import * as maptalks from 'maptalks';
|
import store from '../store';
|
import img_zhandian_m_url from '../assets/map/icon_zhandian_m.png';
|
import img_zhandian_mm_url from '../assets/map/icon_zhandian_mm.png';
|
import img_cheliang_m_url from '../assets/map/icon_cheliang_m.png';
|
import img_cheliang_mm_url from '../assets/map/icon_cheliang_mm.png';
|
import img_bg_s_url from '../assets/map/bg_s.png';
|
import img_bg_m_url from '../assets/map/bg_m.png';
|
import { message } from 'ant-design-vue';
|
export default class customTool extends maptalks.MapTool {
|
onEnable() {
|
let layer = window.map.getLayer("CustomTool_layer");
|
if(!layer){
|
this._markerLayer = new maptalks.VectorLayer('CustomTool_layer').addTo(this.getMap());
|
}
|
|
}
|
|
onDisable() {
|
if (this._markerLayer) {
|
this._markerLayer.remove();
|
}
|
}
|
|
getEvents() {
|
return {
|
'click': this._onClick,
|
'contextmenu': this._onRightClick
|
};
|
}
|
|
_onClick(param) {
|
let layer = window.map.getLayer("CustomTool_layer");
|
if(store.state.mapMenu === "站点") {
|
window.map.on('click', function (e) {
|
layer.forEach(function (g) {
|
g.updateSymbol([{'markerFile': img_zhandian_m_url},{'markerFile': img_bg_s_url}]);
|
});
|
window.map.identify({
|
'coordinate' : e.coordinate,
|
'layers' : [layer]
|
},
|
function (geos) {
|
if (geos.length === 0) {
|
return;
|
} else {
|
store.commit("SET_SelAttr", {visa:true,type: "zhandian",value:geos[0].properties.name})
|
geos[0].updateSymbol([{'markerFile': img_zhandian_mm_url},{'markerFile': img_bg_m_url}]);
|
// loadtempLayer(geos[0].properties)
|
// window.map.animateTo({
|
// zoom : 14,
|
// center : geos[0]._coordinates.add(0.015, 0.000)
|
// }, {
|
// duration : 500,
|
// easing : 'out'
|
// })
|
}
|
}
|
);
|
});
|
} else if (store.state.mapMenu === "车辆") {
|
window.map.on('click', function (e) {
|
layer.forEach(function (g) {
|
g.updateSymbol([{'markerFile': img_cheliang_m_url},{'markerFile': img_bg_s_url}]);
|
});
|
window.map.identify({
|
'coordinate' : e.coordinate,
|
'layers' : [layer]
|
},
|
function (geos) {
|
if (geos.length === 0) {
|
return;
|
} else {
|
store.commit("SET_SelAttr", {visa:true,type: "cheliang",value:geos[0].properties.name})
|
geos[0].updateSymbol([{'markerFile': img_cheliang_mm_url},{'markerFile': img_bg_m_url}]);
|
// loadtempLayer(geos[0].properties)
|
// window.map.animateTo({
|
// zoom : 14,
|
// center : geos[0]._coordinates.add(0.015, 0.000)
|
// }, {
|
// duration : 500,
|
// easing : 'out'
|
// })
|
}
|
}
|
);
|
});
|
}
|
|
}
|
|
_onRightClick(param) {
|
map.identify({
|
coordinate: param.coordinate,
|
layers: [this._markerLayer]
|
}, geos => {
|
this._markerLayer.removeGeometry(geos)
|
let array = this._markerLayer._geoList
|
let pathDataArr =array.map(item=>item.properties.id)
|
if(store.state.mapMenu === "车辆"){
|
if(array.length > 50){
|
message.warning('选择车辆不能大于50!')
|
} else {
|
store.commit("SET_SelAttr", {visa:true,type: "cheliangcircle",value:pathDataArr.toString()})
|
}
|
} else if (store.state.mapMenu === "站点") {
|
if(array.length > 50){
|
message.warning('选择站点不能大于50!')
|
} else {
|
store.commit("SET_SelAttr", {visa:true,type: "zhandiancircle",value:pathDataArr.toString()})
|
}
|
}
|
});
|
}
|
setMarkersLayer(markers){
|
this._markerLayer.addGeometry(markers);
|
}
|
}
|