|
@@ -23,6 +23,8 @@ import { |
|
|
} from 'ol/style'; |
|
|
} from 'ol/style'; |
|
|
import { extend, createEmpty } from 'ol/extent'; |
|
|
import { extend, createEmpty } from 'ol/extent'; |
|
|
import VectorLayer from 'ol/layer/Vector'; |
|
|
import VectorLayer from 'ol/layer/Vector'; |
|
|
|
|
|
import Image from 'ol/layer/Image'; |
|
|
|
|
|
import ImageWMS from 'ol/source/ImageWMS.js'; |
|
|
import VectorSource from 'ol/source/Vector'; |
|
|
import VectorSource from 'ol/source/Vector'; |
|
|
import TileWMS from 'ol/source/TileWMS'; |
|
|
import TileWMS from 'ol/source/TileWMS'; |
|
|
import GeoJSON from 'ol/format/GeoJSON'; |
|
|
import GeoJSON from 'ol/format/GeoJSON'; |
|
@@ -48,6 +50,7 @@ class GisUtils { |
|
|
|
|
|
|
|
|
constructor(domId) { |
|
|
constructor(domId) { |
|
|
this.getMap(domId) |
|
|
this.getMap(domId) |
|
|
|
|
|
this.initView() |
|
|
return this |
|
|
return this |
|
|
} |
|
|
} |
|
|
/** |
|
|
/** |
|
@@ -56,7 +59,7 @@ class GisUtils { |
|
|
*/ |
|
|
*/ |
|
|
getMap (domId) { |
|
|
getMap (domId) { |
|
|
let view = new View({ |
|
|
let view = new View({ |
|
|
projection: 'EPSG:4326' |
|
|
|
|
|
|
|
|
projection: 'EPSG:3857' |
|
|
}); |
|
|
}); |
|
|
PluggableMap.prototype.getEventPixel = function (event) { |
|
|
PluggableMap.prototype.getEventPixel = function (event) { |
|
|
// eslint-disable-next-line no-underscore-dangle |
|
|
// eslint-disable-next-line no-underscore-dangle |
|
@@ -129,6 +132,20 @@ class GisUtils { |
|
|
return layer; |
|
|
return layer; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
getVectorLayerByFs (features, zIndex = 1012) { |
|
|
|
|
|
const vectorSource = new VectorSource({ |
|
|
|
|
|
features: features, |
|
|
|
|
|
}); |
|
|
|
|
|
// 创建矢量图层 |
|
|
|
|
|
let layer = new VectorLayer({ |
|
|
|
|
|
zIndex, |
|
|
|
|
|
source: vectorSource, |
|
|
|
|
|
name: 'deptLayer' |
|
|
|
|
|
}); |
|
|
|
|
|
this.map.addLayer(layer) |
|
|
|
|
|
return layer |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
addLayer (layer) { |
|
|
addLayer (layer) { |
|
|
this.map.addLayer(layer); |
|
|
this.map.addLayer(layer); |
|
|
} |
|
|
} |
|
@@ -138,8 +155,54 @@ class GisUtils { |
|
|
return polygon; |
|
|
return polygon; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
getFeature (polygon) { |
|
|
|
|
|
return new Feature(polygon); |
|
|
|
|
|
|
|
|
getFeature (info, icon) { |
|
|
|
|
|
let feature = new Feature({ |
|
|
|
|
|
geometry: new Point( |
|
|
|
|
|
fromLonLat([info.lng, info.lat]) |
|
|
|
|
|
), |
|
|
|
|
|
deptId: info.id, |
|
|
|
|
|
deptName: info.label, |
|
|
|
|
|
orgCode: info.orgCode, |
|
|
|
|
|
lat: info.lat, |
|
|
|
|
|
lng: info.lng, |
|
|
|
|
|
deptLevel: info.deptLevel, |
|
|
|
|
|
level: 'deptPoint', |
|
|
|
|
|
}) |
|
|
|
|
|
feature.setStyle(this.createFeatureStyle(feature, icon)); |
|
|
|
|
|
return feature; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 设置坐标点的样式 |
|
|
|
|
|
createFeatureStyle (feature, locationIcon) { |
|
|
|
|
|
return new Style({ |
|
|
|
|
|
image: new Icon({ |
|
|
|
|
|
//设置图标偏移 |
|
|
|
|
|
anchor: [0.5, 1], |
|
|
|
|
|
//标注样式的起点位置 |
|
|
|
|
|
anchorOrigin: "top-right", |
|
|
|
|
|
//X方向单位:分数 |
|
|
|
|
|
anchorXUnits: "fraction", |
|
|
|
|
|
//Y方向单位:像素 |
|
|
|
|
|
anchorYUnits: "pixels", |
|
|
|
|
|
//偏移起点位置的方向 |
|
|
|
|
|
offsetOrigin: "top-right", |
|
|
|
|
|
//透明度 |
|
|
|
|
|
opacity: 0.9, |
|
|
|
|
|
// rotation: (Math.PI / 180) * 20, |
|
|
|
|
|
//图片路径 |
|
|
|
|
|
src: locationIcon, |
|
|
|
|
|
}), |
|
|
|
|
|
text: new Text({ |
|
|
|
|
|
textAlign: "center", //位置 |
|
|
|
|
|
textBaseline: "bottom", //基准线 |
|
|
|
|
|
font: "normal 14px 微软雅黑", //文字样式 |
|
|
|
|
|
text: feature.get("deptName"), //文本内容 |
|
|
|
|
|
fill: new Fill({ |
|
|
|
|
|
//文本填充样式(即文字颜色) |
|
|
|
|
|
color: "#ffff00", |
|
|
|
|
|
}), |
|
|
|
|
|
}) |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
writeFeature (fs) { |
|
|
writeFeature (fs) { |
|
@@ -242,18 +305,22 @@ class GisUtils { |
|
|
* @param {int} minZoom 最小缩放级别 |
|
|
* @param {int} minZoom 最小缩放级别 |
|
|
* @param {int} maxZoom 最大缩放级别 |
|
|
* @param {int} maxZoom 最大缩放级别 |
|
|
*/ |
|
|
*/ |
|
|
getView (extent = [100, 100, 100, 100], zoom = 4, minZoom = 3, maxZoom = 18.4) { |
|
|
|
|
|
|
|
|
initView (extent = [100, 100, 100, 100], zoom = 4, minZoom = 3, maxZoom = 18.4) { |
|
|
let view = new View({ |
|
|
let view = new View({ |
|
|
center: getCenterByExtent(extent), |
|
|
center: getCenterByExtent(extent), |
|
|
zoom, |
|
|
zoom, |
|
|
minZoom, |
|
|
minZoom, |
|
|
maxZoom, |
|
|
maxZoom, |
|
|
projection: 'EPSG:4326' |
|
|
|
|
|
|
|
|
projection: 'EPSG:3857' |
|
|
}); |
|
|
}); |
|
|
this.map.setView(view); |
|
|
this.map.setView(view); |
|
|
return view; |
|
|
return view; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
getView () { |
|
|
|
|
|
return this.map.getView() |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 获取WMS图层 |
|
|
* 获取WMS图层 |
|
|
* @param {*} wmsurl wms路径 |
|
|
* @param {*} wmsurl wms路径 |
|
@@ -278,17 +345,48 @@ class GisUtils { |
|
|
* 获取天地图图层 |
|
|
* 获取天地图图层 |
|
|
* @param {string} url 最小缩放级别 |
|
|
* @param {string} url 最小缩放级别 |
|
|
*/ |
|
|
*/ |
|
|
tianDiTuLayer (url, visible = true) { |
|
|
|
|
|
|
|
|
addTianDiTuLayer (visible = true) { |
|
|
let tianDitTu = new TileLayer({ |
|
|
let tianDitTu = new TileLayer({ |
|
|
visible, |
|
|
visible, |
|
|
source: new XYZ({ |
|
|
source: new XYZ({ |
|
|
url |
|
|
|
|
|
|
|
|
url: 'http://t{0-7}.tianditu.com/img_w/wmts?' + 'SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=img&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles' + '&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}&tk=cc4aba6e967096098249efa069733067' |
|
|
}) |
|
|
}) |
|
|
}); |
|
|
}); |
|
|
this.map.addLayer(tianDitTu); |
|
|
this.map.addLayer(tianDitTu); |
|
|
return tianDitTu; |
|
|
return tianDitTu; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 获取天地图图层 |
|
|
|
|
|
* @param {string} url 最小缩放级别 |
|
|
|
|
|
*/ |
|
|
|
|
|
addAnnotationLayer (visible = true) { |
|
|
|
|
|
let tianDitTu = new TileLayer({ |
|
|
|
|
|
visible, |
|
|
|
|
|
source: new XYZ({ |
|
|
|
|
|
url: 'http://t{0-7}.tianditu.com/DataServer?T=cia_w&x={x}&y={y}&l={z}&tk=cc4aba6e967096098249efa069733067' |
|
|
|
|
|
}) |
|
|
|
|
|
}); |
|
|
|
|
|
this.map.addLayer(tianDitTu); |
|
|
|
|
|
return tianDitTu; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
addImageLayer (mapGeoServerUrl, layerName, deptIds) { |
|
|
|
|
|
let layer = new Image({ |
|
|
|
|
|
source: new ImageWMS({ |
|
|
|
|
|
url: mapGeoServerUrl + '/wms', |
|
|
|
|
|
params: { |
|
|
|
|
|
LAYERS: layerName, |
|
|
|
|
|
cql_filter: "dept_id in (" + deptIds + ")", |
|
|
|
|
|
SRID: 3857, |
|
|
|
|
|
} |
|
|
|
|
|
}), |
|
|
|
|
|
name: 'countyBorderLayer' |
|
|
|
|
|
}); |
|
|
|
|
|
this.map.addLayer(layer) |
|
|
|
|
|
return layer |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 获取wfs服务请求参数 |
|
|
* 获取wfs服务请求参数 |
|
|
* @param {string} typename 请求的图层名 |
|
|
* @param {string} typename 请求的图层名 |
|
@@ -415,51 +513,6 @@ class GisUtils { |
|
|
return style; |
|
|
return style; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
*根据要素集合获得矢量图层 |
|
|
|
|
|
* @param {array} fs 要素集合 |
|
|
|
|
|
*/ |
|
|
|
|
|
getVectorLayerByFs (fs, zIndex = 200, opacity = 1, strokeColor = [0, 180, 241, 1], fillColor = [0, 180, 241, 0.1]) { |
|
|
|
|
|
let style = this.getStyle(strokeColor, fillColor); |
|
|
|
|
|
let textName = ['mj', 'uuid']; |
|
|
|
|
|
const source = new VectorSource({ |
|
|
|
|
|
}); |
|
|
|
|
|
if (fs.length) { |
|
|
|
|
|
source.addFeatures(fs); |
|
|
|
|
|
} |
|
|
|
|
|
const layer = new VectorLayer({ |
|
|
|
|
|
renderMode: 'webgl', |
|
|
|
|
|
style: style, |
|
|
|
|
|
opacity, |
|
|
|
|
|
style: (feature) => { |
|
|
|
|
|
let arr = ''; |
|
|
|
|
|
textName.forEach(item => { |
|
|
|
|
|
arr += feature.getProperties()[item] + '\n'; |
|
|
|
|
|
}); |
|
|
|
|
|
return new Style({ |
|
|
|
|
|
fill: new Fill({ |
|
|
|
|
|
color: fillColor |
|
|
|
|
|
}), |
|
|
|
|
|
text: new Text({ |
|
|
|
|
|
overflow: true, |
|
|
|
|
|
text: arr, |
|
|
|
|
|
font: 'bold 12px serif', |
|
|
|
|
|
fill: new Fill({ |
|
|
|
|
|
color: '#ffffff' |
|
|
|
|
|
}) |
|
|
|
|
|
}), |
|
|
|
|
|
stroke: new Stroke({ |
|
|
|
|
|
color: strokeColor, |
|
|
|
|
|
width: 1 |
|
|
|
|
|
}) |
|
|
|
|
|
}); |
|
|
|
|
|
}, |
|
|
|
|
|
source: source, |
|
|
|
|
|
zIndex: zIndex |
|
|
|
|
|
}); |
|
|
|
|
|
this.map.addLayer(layer); |
|
|
|
|
|
return layer; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
changeTextName (arr, layerName) { |
|
|
changeTextName (arr, layerName) { |
|
|
this.textName[layerName] = arr; |
|
|
this.textName[layerName] = arr; |
|
|