|
@@ -2,7 +2,7 @@ import OLMap from 'ol/Map'
|
|
|
import View from 'ol/View'
|
|
|
import * as proj from 'ol/proj'
|
|
|
import * as interaction from 'ol/interaction'
|
|
|
-import {Draw,Modify} from 'ol/interaction'
|
|
|
+import {Draw, Modify} from 'ol/interaction'
|
|
|
import 'ol/ol.css'
|
|
|
import './css/KMap.css'
|
|
|
import * as Enum from './Enum'
|
|
@@ -11,14 +11,14 @@ import VectorLayer from './VectorLayer'
|
|
|
import * as Extent from 'ol/extent'
|
|
|
import Overlay from 'ol/Overlay'
|
|
|
|
|
|
+import {GeoJSON, WKT} from 'ol/format'
|
|
|
import WMTSLayer from './WMTSLayer'
|
|
|
import XYZLayer from './XYZLayer'
|
|
|
import config from "@/api/config.js";
|
|
|
-import {Feature} from "ol";
|
|
|
-import {GeoJSON, WKT} from 'ol/format'
|
|
|
-import { Style, Text,Icon } from 'ol/style';
|
|
|
import { Circle, Fill, Stroke } from 'ol/style.js';
|
|
|
-import {LineString, MultiPolygon, Point} from 'ol/geom';
|
|
|
+import { LineString, Point } from 'ol/geom';
|
|
|
+import { Style, Text } from 'ol/style';
|
|
|
+import {Feature} from "ol";
|
|
|
import {getArea} from "ol/sphere"
|
|
|
/**
|
|
|
* @description KMap.Map 地图类
|
|
@@ -68,8 +68,8 @@ class Map {
|
|
|
* @description Map初始化方法
|
|
|
* @constructor
|
|
|
*/
|
|
|
- constructor(id,zoomLevel,lng,lat,projection, minZoom,maxZoom,isShowPoint){
|
|
|
- this.defaultCursor = 'default'
|
|
|
+ constructor(id,zoomLevel,lng,lat,projection, minZoom, maxZoom, mapType, dragPan = true, mouseWheelZoom = true,isBaseMap = false, showCva = true){
|
|
|
+ this.mapType = mapType || "img";
|
|
|
if(Map.Instance){
|
|
|
Map.Instance = false;
|
|
|
}
|
|
@@ -91,47 +91,55 @@ class Map {
|
|
|
zoom: zoomLevel,
|
|
|
minZoom: minZoom || Common.ShowLevel[0],
|
|
|
maxZoom: maxZoom || Common.ShowLevel[1],
|
|
|
- projection:projection
|
|
|
+ projection:projection,
|
|
|
+ enableRotation: false
|
|
|
})
|
|
|
this.view = view
|
|
|
this.map = new OLMap({
|
|
|
- interactions: interaction.defaults().extend([
|
|
|
+ interactions: interaction.defaults({
|
|
|
+ dragPan,
|
|
|
+ mouseWheelZoom
|
|
|
+ }).extend([
|
|
|
new interaction.DragRotateAndZoom()]),
|
|
|
target: id,
|
|
|
layers: [],//vm.baseLayer
|
|
|
view: view,
|
|
|
control: []
|
|
|
})
|
|
|
- this.initBaseLayer(projection,isShowPoint)
|
|
|
+ if(!isBaseMap){
|
|
|
+ this.initBaseLayer(projection, showCva)
|
|
|
+ }
|
|
|
//初始化业务图层
|
|
|
this.initBusinessLayer()
|
|
|
//初始化地图信息弹窗
|
|
|
this.initInfoWindow()
|
|
|
//初始化地图基础事件
|
|
|
this.initMapBaseEvent()
|
|
|
-
|
|
|
}
|
|
|
/**
|
|
|
* 初始化地图底图图层
|
|
|
* @return {array}
|
|
|
* @memberof Map
|
|
|
*/
|
|
|
- async initBaseLayer(projection,isShowPoint){
|
|
|
- // const img_wmts = await VE_API.system.getCfg({"k":"img_wmts_mkt","resultType":"json"});
|
|
|
- // const cva_wmts = await VE_API.system.getCfg({"k":"cva_wmts_mkt","resultType":"json"});
|
|
|
- // this.tdtImgLayer = new WMTSLayer(img_wmts.data, projection,this);
|
|
|
- // this.cva_torLayer = new WMTSLayer(cva_wmts.data,projection,this);
|
|
|
- let xyz2 = config.base_img_url3 + 'map/lby/{z}/{x}/{y}.png';
|
|
|
- // this.addXYZLayer(xyz2,{minZoom:12,maxZoom:23},7);
|
|
|
- let xyz3 = "https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}";
|
|
|
- this.addXYZLayer(xyz3,{minZoom:12,maxZoom:23},1);
|
|
|
- let xyzPoint = config.base_img_url3 + 'map/ggp_point/{z}/{x}/{y}.png';
|
|
|
- if(isShowPoint){
|
|
|
- this.addXYZLayer(xyzPoint,{minZoom:12,maxZoom:23},99);
|
|
|
+ async initBaseLayer(projection, showCva){
|
|
|
+ if(this.mapType == "img"){
|
|
|
+ const img_wmts = await VE_API.system.getCfg({"k":"img_wmts_mkt","resultType":"json"});
|
|
|
+ this.tdtImgLayer = new WMTSLayer(img_wmts.data, projection,this);
|
|
|
+ if (showCva) {
|
|
|
+ const cva_wmts = await VE_API.system.getCfg({"k":"cva_wmts_mkt","resultType":"json"});
|
|
|
+ this.cva_torLayer = new WMTSLayer(cva_wmts.data,projection,this);
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ const img_wmts = await VE_API.system.getCfg({"k":"vec_c_wmts","resultType":"json"});
|
|
|
+ this.tdtImgLayer = new WMTSLayer(img_wmts.data, projection,this);
|
|
|
+ if (showCva) {
|
|
|
+ const cva_wmts = await VE_API.system.getCfg({"k":"cva_c_wmts","resultType":"json"});
|
|
|
+ this.cva_torLayer = new WMTSLayer(cva_wmts.data,projection,this);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
addXYZLayer(url,options,zIndex){
|
|
|
- let xyz = new XYZLayer(url,options,zIndex || 3);
|
|
|
+ let xyz = new XYZLayer(url,options, zIndex || 3);
|
|
|
return xyz;
|
|
|
}
|
|
|
/**
|
|
@@ -146,9 +154,8 @@ class Map {
|
|
|
//创建默认线标记图层
|
|
|
vm.polyLineLayer = new VectorLayer("defaultPolylineLayer",101)
|
|
|
//创建默认面图层
|
|
|
- vm.polygonLayer = new VectorLayer("defaultPolygonLayer",1000,{
|
|
|
- style: vm.polygonStyle,
|
|
|
- maxZoom:23
|
|
|
+ vm.polygonLayer = new VectorLayer("defaultPolygonLayer",1000, {
|
|
|
+ style: vm.polygonStyle
|
|
|
})
|
|
|
//创建文本标记图层
|
|
|
vm.labelLayer = new VectorLayer("defaultLabelLayer",99)
|
|
@@ -178,34 +185,19 @@ class Map {
|
|
|
})
|
|
|
this.draw.setActive(false)
|
|
|
this.map.addInteraction(this.draw);
|
|
|
- this.draw.on("drawstart",callback)
|
|
|
this.draw.on("drawend",callback)
|
|
|
}
|
|
|
startDraw(){
|
|
|
this.draw.setActive(true)
|
|
|
}
|
|
|
- endDraw(){
|
|
|
- this.draw.setActive(false)
|
|
|
- }
|
|
|
|
|
|
- modifyDraw(callback, condition) {
|
|
|
+ modifyDraw(callback) {
|
|
|
this.modify = new Modify({
|
|
|
source: this.polygonLayer.source,
|
|
|
pixelTolerance: 10, //设置吸附像素值
|
|
|
-
|
|
|
})
|
|
|
- this.modify.setActive(false)
|
|
|
this.map.addInteraction(this.modify);
|
|
|
this.modify.on("modifyend",callback)
|
|
|
- this.modify.on("modifystart",callback)
|
|
|
- }
|
|
|
-
|
|
|
- startModify(){
|
|
|
- this.modify.setActive(true)
|
|
|
- }
|
|
|
-
|
|
|
- endModify(){
|
|
|
- this.modify.setActive(false)
|
|
|
}
|
|
|
|
|
|
drawStyleFunc(feature) {
|
|
@@ -218,13 +210,13 @@ class Map {
|
|
|
new Style({
|
|
|
geometry: new Point(coord[i]),
|
|
|
image: new Circle({
|
|
|
- radius: 6,
|
|
|
+ radius: 4,
|
|
|
fill: new Fill({
|
|
|
- color: '#06F7A1'
|
|
|
+ color: '#54cb82'
|
|
|
}),
|
|
|
stroke: new Stroke({
|
|
|
- color: '#fff',
|
|
|
- width: 1
|
|
|
+ color: '#54cb82',
|
|
|
+ width: 3
|
|
|
})
|
|
|
})
|
|
|
})
|
|
@@ -249,7 +241,7 @@ class Map {
|
|
|
new Style({
|
|
|
geometry: new LineString([coord[i], coord[i + 1]]),
|
|
|
stroke: new Stroke({
|
|
|
- color: '#06F7A1',
|
|
|
+ color: '#54cb82',
|
|
|
width: 2
|
|
|
})
|
|
|
})
|
|
@@ -259,81 +251,63 @@ class Map {
|
|
|
return styles;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
polygonStyle(feature) {
|
|
|
const styles = [];
|
|
|
- let fillStyle = {}
|
|
|
- let coord = feature.getGeometry().getCoordinates();
|
|
|
- if(coord[0].length === 1){
|
|
|
- coord = coord[0];
|
|
|
- }
|
|
|
- if(feature.get("icon")==="point-act"){
|
|
|
- for (let i = 0; i < coord[0].length - 1; i++) {
|
|
|
- if (i%2) {
|
|
|
- styles.push(
|
|
|
- new Style({
|
|
|
- geometry: new Point(coord[0][i]),
|
|
|
- image: new Circle({
|
|
|
- radius: 6,
|
|
|
- fill: new Fill({
|
|
|
- color: '#06F7A1'
|
|
|
- }),
|
|
|
- stroke: new Stroke({
|
|
|
- color: '#fff',
|
|
|
- width: 1
|
|
|
- }),
|
|
|
- }),
|
|
|
- }),
|
|
|
- );
|
|
|
- } else {
|
|
|
- styles.push(
|
|
|
- new Style({
|
|
|
- geometry: new Point(coord[0][i]),
|
|
|
- image: new Circle({
|
|
|
- radius: 6,
|
|
|
- fill: new Fill({
|
|
|
- color: '#fff'
|
|
|
- })
|
|
|
- }),
|
|
|
+ const coord = feature.getGeometry().getCoordinates()[0];
|
|
|
+ for (let i = 0; i < coord[0].length - 1; i++) {
|
|
|
+ if (i%2) {
|
|
|
+ styles.push(
|
|
|
+ new Style({
|
|
|
+ geometry: new Point(coord[0][i]),
|
|
|
+ image: new Circle({
|
|
|
+ radius: 4,
|
|
|
+ fill: new Fill({
|
|
|
+ color: '#54cb82'
|
|
|
}),
|
|
|
- );
|
|
|
- }
|
|
|
+ stroke: new Stroke({
|
|
|
+ color: '#54cb82',
|
|
|
+ width: 3
|
|
|
+ })
|
|
|
+ })
|
|
|
+ })
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+ styles.push(
|
|
|
+ new Style({
|
|
|
+ geometry: new Point(coord[0][i]),
|
|
|
+ image: new Circle({
|
|
|
+ radius: 6,
|
|
|
+ fill: new Fill({
|
|
|
+ color: '#fff'
|
|
|
+ })
|
|
|
+ })
|
|
|
+ })
|
|
|
+ );
|
|
|
}
|
|
|
- fillStyle = new Style({
|
|
|
- fill: new Fill({
|
|
|
- color: [45, 72, 55, 0.3]
|
|
|
- }),
|
|
|
- stroke: new Stroke({
|
|
|
- color: '#34C16D',
|
|
|
- width: 2
|
|
|
- })
|
|
|
- })
|
|
|
- }else{
|
|
|
- fillStyle = new Style({
|
|
|
- fill: new Fill({
|
|
|
- color: [45, 72, 55, 0.3]
|
|
|
- }),
|
|
|
- stroke: new Stroke({
|
|
|
- color: '#34C16D',
|
|
|
- width: 2
|
|
|
- })
|
|
|
- })
|
|
|
}
|
|
|
+ let fillStyle = new Style({
|
|
|
+ fill: new Fill({
|
|
|
+ color: [1, 41, 52, 0.6]
|
|
|
+ }),
|
|
|
+ stroke: new Stroke({
|
|
|
+ color: '#54cb82',
|
|
|
+ width: 2
|
|
|
+ })
|
|
|
+ })
|
|
|
let geom = feature.getGeometry().clone()
|
|
|
- // geom.transform(proj.get("EPSG:4326"), proj.get("EPSG:38572"))
|
|
|
- geom.transform(proj.get("EPSG:4326"), proj.get("EPSG:3857"))
|
|
|
+ geom.transform(proj.get("EPSG:4326"), proj.get("EPSG:38572"))
|
|
|
let area = getArea(geom)
|
|
|
area = (area + area / 2) / 1000;
|
|
|
let areaValStyle = new Style({
|
|
|
text: new Text({
|
|
|
font: "16px sans-serif",
|
|
|
text: area.toFixed(2) + "亩",
|
|
|
- offsetX: 0,
|
|
|
- offsetY: 0,
|
|
|
+ // offsetX: 28,
|
|
|
+ // offsetY: -100,
|
|
|
fill: new Fill({ color: "#fff" }), // 字体颜色
|
|
|
}),
|
|
|
})
|
|
|
- styles.push(fillStyle);
|
|
|
+ styles.push(fillStyle, areaValStyle);
|
|
|
return styles;
|
|
|
}
|
|
|
|
|
@@ -342,11 +316,6 @@ class Map {
|
|
|
let features = vm.polygonLayer.source.getFeatures()
|
|
|
return features
|
|
|
}
|
|
|
- getFeatureById(id) {
|
|
|
- const vm = this
|
|
|
- let feature = vm.polygonLayer.source.getFeatureById(id)
|
|
|
- return feature
|
|
|
- }
|
|
|
|
|
|
// 传入geojson,回显到polygon
|
|
|
setLayerPolygon(geometry) {
|
|
@@ -354,31 +323,12 @@ class Map {
|
|
|
vm.polygonLayer.source.addFeatures(new GeoJSON().readFeatures(geometry))
|
|
|
}
|
|
|
|
|
|
- setLayerPolygonCoordinates(coordinates, layout ,data, isView, padding) {
|
|
|
+ setLayerWkt(wkt) {
|
|
|
const vm = this
|
|
|
- let f = new Feature({geometry:new MultiPolygon([[coordinates]],layout) ,...data})
|
|
|
- if(f.get("id")){
|
|
|
- f.setId(f.get("id"))
|
|
|
- }
|
|
|
+ let f = new Feature({geometry:new WKT().readGeometry(wkt)})
|
|
|
const extent = f.getGeometry().getExtent()
|
|
|
vm.polygonLayer.source.addFeature(f)
|
|
|
- if(isView){
|
|
|
- vm.map.getView().fit(extent, { padding: padding || [20, 20, 20, 20] });
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- setLayerWkt(wkt,data,isView, padding) {
|
|
|
- const vm = this
|
|
|
- let f = new Feature({geometry:new WKT().readGeometry(wkt),...data})
|
|
|
- if(f.get("id")){
|
|
|
- f.setId(f.get("id"))
|
|
|
- }
|
|
|
- const extent = f.getGeometry().getExtent()
|
|
|
- vm.polygonLayer.source.addFeature(f)
|
|
|
- if(isView){
|
|
|
- vm.map.getView().fit(extent, { padding: padding || [20, 20, 20, 20] });
|
|
|
- }
|
|
|
- return f
|
|
|
+ vm.map.getView().fit(extent, { padding: [20, 20, 20, 20] });
|
|
|
}
|
|
|
|
|
|
addLayer(layer){
|
|
@@ -472,12 +422,12 @@ class Map {
|
|
|
vm.clearMouseMoveInfoWindow()
|
|
|
}
|
|
|
//设置鼠标悬停到覆盖物上的样式
|
|
|
- let mapContainer = vm.getTarget()
|
|
|
+ var mapContainer = vm.getTarget()
|
|
|
if(mousemoveFeature) {
|
|
|
mapContainer.style.cursor = "pointer"
|
|
|
}
|
|
|
else {
|
|
|
- mapContainer.style.cursor = this.defaultCursor
|
|
|
+ mapContainer.style.cursor = "default"
|
|
|
}
|
|
|
})
|
|
|
}
|
|
@@ -917,8 +867,8 @@ class Map {
|
|
|
let bounds = new Extent.boundingExtent(lnglatArray)
|
|
|
this.view.fit(bounds) //地图视角切换到矩阵范围
|
|
|
}
|
|
|
- fit(geometryOrExtent,options){
|
|
|
- this.view.fit(geometryOrExtent,options)
|
|
|
+ fit(geometryOrExtent,padding){
|
|
|
+ this.view.fit(geometryOrExtent,{ duration:500,padding})
|
|
|
}
|
|
|
/**
|
|
|
* @description 平面地图像素坐标转经纬度坐标
|
|
@@ -1057,11 +1007,10 @@ class Map {
|
|
|
|
|
|
/**
|
|
|
* @description 设置地图指针样式
|
|
|
- * @param {String} cursorStyle 鼠标样式("default"默认指针,"pointer"小手,"move"移动指针, "text"文本指针,"wait"等待状态,"help"帮助,"crosshair"十字指针),必填
|
|
|
+ * @param {String} cursorStyle 鼠标样式("default"默认指针,"pointer"小手,"move"移动指针, "text"文本指针,"wait"等待状态,"help"帮助),必填
|
|
|
* @memberof Map
|
|
|
*/
|
|
|
setDefaultCursor(cursorStyle) {
|
|
|
- this.defaultCursor = cursorStyle
|
|
|
let mapContainer = this.map.getTargetElement()
|
|
|
if(cursorStyle != undefined) {
|
|
|
mapContainer.style.cursor = cursorStyle
|
|
@@ -1079,13 +1028,14 @@ class Map {
|
|
|
setFeatureCursor(cursorStyle) {
|
|
|
cursorStyle = (cursorStyle == undefined)? "default" : cursorStyle
|
|
|
let mapContainer = this.map.getTargetElement()
|
|
|
+ let defaultCursor = mapContainer.style.cursor
|
|
|
this.map.on("pointermove",function(e){
|
|
|
let features = this.map.forEachFeatureAtPixel(e.pixel,function(feature) { return feature })
|
|
|
if(features) {
|
|
|
mapContainer.style.cursor = cursorStyle
|
|
|
}
|
|
|
else {
|
|
|
- mapContainer.style.cursor = this.defaultCursor
|
|
|
+ mapContainer.style.cursor = defaultCursor
|
|
|
}
|
|
|
})
|
|
|
}
|