代码:
import {
layers
} from "./layersJson"
import axios from "axios";
import store from '../../store'
export const clickMap = {}
clickMap.queryFun = {}
clickMap.queryFunOne = function (e, map, layer, value, type) {
console.log('这是e', e);
let url = layer.getSource().getFeatureInfoUrl(
e.coordinate,
map.getView().getResolution(),
"EPSG:3857", {
INFO_FORMAT: "application/json",
FEATURE_COUNT: 1,
QUERY_LAYERS: value
},
)
axios.get(url).then(res => {
if (res.data.numberReturned) {
console.log('这是liyao 查询到的事件 res', res);
console.log('这是刷新了store', res.data.features);
console.log('这是type', type);
if (type == "通道图层") {
store.dispatch("tagging/setCableDetails", res.data.features);
} else if (type == "井图层") {
console.log('这是123456', res.data);
store.dispatch("tagging/setEqmtOrWell", res.data.features);
store.dispatch("tagging/setWellDetails", res.data.features[0]);
} else if (type == "设备图层") {
store.dispatch("tagging/setEqmtOrWell", res.data.features);
}
}
})
}
clickMap.openClickAndQueryWithType = function (map, type) {
console.log('这是this', this);
let arr = map.getLayers().array_
let layer = {}
arr.forEach(item => {
if (item.get("label") == type) {
layer = item
}
})
let value = ""
layers.forEach(items => {
if (items.label == type) {
value = items.value
}
})
//找到图层对应的那个layer
console.log('这是layer', layer);
clickMap.queryFun = function(e){
clickMap.queryFunOne(e, map, layer, value, type)
}
map.on("click", clickMap.queryFun)
}
clickMap.openMutiClickAndQueryWithType = function (map, arr) {
// console.log('这是queryFun', queryFun);
clickMap.clickMapClose(map)
arr.forEach(item => {
clickMap.openClickAndQueryWithType(map, item)
})
}
clickMap.clickMapClose = function (map) {
console.log('这是map', map);
if (map.listeners_.click.length) {
console.log('这是123',);
map.listeners_.click.forEach(item=>{
console.log('=====这是清除了一次=====',);
map.un("click", item)
})
}
}
导入:
import {clickMap}from "@/mapComponent/editFeatures/clickMapSearch"
使用: 其他同理可得
clickMap.openMutiClickAndQueryWithType(this.mapObj.map, ["设备图层"])
其中layers
效果:点击对应图层内某图斑查出的结果