diff --git a/src/api/gis/service.js b/src/api/gis/service.js index 0805de0..f343d46 100644 --- a/src/api/gis/service.js +++ b/src/api/gis/service.js @@ -10,19 +10,24 @@ import axios from 'axios' export function loadWMS(map, url, option) { if (url) { const id = url.split('layer=')[1] - console.log(id, '新增的图层id') - map.addSource(option.source, { - id: option.id, - type: 'raster', - tiles: [url], - tileSize: 512 - }) - map.addLayer({ - id: id, - type: option.type, - source: option.source, - paint: option.paint - }) + const source = map.getSource(option.source) + const layer = map.getLayer(option.id) + if (source == undefined && layer == undefined) { + map.addSource(option.source, { + + type: 'raster', + tiles: [url], + tileSize: 512 + }) + map.addLayer({ + id: id, + type: option.type, + source: option.source, + paint: option.paint + }) + } else { + alert('该图层已存在!请勿重复添加。') + } } else { alert('请输入WMS服务地址!') } @@ -34,11 +39,10 @@ export function loadWMS(map, url, option) { * @param url */ export function removeLayer(map, url, option) { - console.log(url, '地址') const id = url.split('layer=')[1] - console.log(id, '移除的id') + map.removeLayer(id) - map.removeSource(id) + map.removeSource(option.source) } /** @@ -57,53 +61,59 @@ export function removeWFSLayer(map, option) { * @param option Object */ export function loadWFSLayer(map, url, option) { - if (url) { - axios.get(url).then((res) => { - const features = res.data.features - // console.log(features, "元素层"); - // let layerType = null; - // let geometryType = features[0].geometry.type; - const addLayerOption = { - id: option.id, - type: option.type, - source: { - type: 'geojson', - data: { - type: 'FeatureCollection', - features: features - } - }, - layout: { - visibility: 'visible' - }, - paint: option.paint - } - // if (geometryType == "MultiLineString") { - // addLayerOption.type = "line"; - // } else if (geometryType == "Line") { - // addLayerOption.type = "line"; - // } else if (geometryType == "Point") { - // addLayerOption.type = "circle"; - // } else if (geometryType == " MultiPoint") { - // addLayerOption.type = "circle"; - // } else if (geometryType == "Polygon") { - // addLayerOption.type = "fill"; - // addLayerOption.paint = { - // "fill-color": "rgba(200,100,240,0.4)", - // "fill-outline-color": "rgba(200,100,240,1)", - // }; - // } else if (geometryType == "MultiPolygon") { - // addLayerOption.type = "fill"; - // addLayerOption.paint = { - // "fill-color": "rgba(200,100,240,0.4)", - // "fill-outline-color": "rgba(200,100,240,1)", - // }; - // } + const source = map.getSource(option.id) + const layer = map.getLayer(option.id) + if (source == undefined && layer == undefined) { + if (url) { + axios.get(url).then((res) => { + const features = res.data.features + // console.log(features, "元素层"); + // let layerType = null; + // let geometryType = features[0].geometry.type; + const addLayerOption = { + id: option.id, + type: option.type, + source: { + type: 'geojson', + data: { + type: 'FeatureCollection', + features: features + } + }, + layout: { + visibility: 'visible' + }, + paint: option.paint + } + // if (geometryType == "MultiLineString") { + // addLayerOption.type = "line"; + // } else if (geometryType == "Line") { + // addLayerOption.type = "line"; + // } else if (geometryType == "Point") { + // addLayerOption.type = "circle"; + // } else if (geometryType == " MultiPoint") { + // addLayerOption.type = "circle"; + // } else if (geometryType == "Polygon") { + // addLayerOption.type = "fill"; + // addLayerOption.paint = { + // "fill-color": "rgba(200,100,240,0.4)", + // "fill-outline-color": "rgba(200,100,240,1)", + // }; + // } else if (geometryType == "MultiPolygon") { + // addLayerOption.type = "fill"; + // addLayerOption.paint = { + // "fill-color": "rgba(200,100,240,0.4)", + // "fill-outline-color": "rgba(200,100,240,1)", + // }; + // } - map.addLayer(addLayerOption) - }) + map.addLayer(addLayerOption) + }) + } else { + alert('请输入WFS地址!') + } } else { - alert('请输入WFS地址!') + alert('该图层已存在!请勿重复添加') } } @@ -114,22 +124,28 @@ export function loadWFSLayer(map, url, option) { * @param option Object */ export function loadWMTS(map, url, option) { - if (url) { - const id = url.split('layer=')[1] - map.addSource(option.source, { - type: 'raster', - tiles: [url], + const source = map.getSource(option.source) + const layer = map.getLayer(option.id) + if (source == undefined && layer == undefined) { + if (url) { + const id = url.split('layer=')[1] + map.addSource(option.source, { + type: 'raster', + tiles: [url], - tileSize: 256 - }) - map.addLayer({ - id: id, - type: option.type, - source: option.source, - paint: option.paint - }) + tileSize: 256 + }) + map.addLayer({ + id: id, + type: option.type, + source: option.source, + paint: option.paint + }) + } else { + alert('请输入WMTS服务地址!') + } } else { - alert('请输入WMTS服务地址!') + alert('该图层已存在!请勿重复添加。') } } diff --git a/src/assets/img/location.png b/src/assets/img/location.png new file mode 100644 index 0000000..771d163 Binary files /dev/null and b/src/assets/img/location.png differ diff --git a/src/assets/img/search.png b/src/assets/img/search.png new file mode 100644 index 0000000..c65845f Binary files /dev/null and b/src/assets/img/search.png differ diff --git a/src/components/PositionMatching/index.vue b/src/components/PositionMatching/index.vue new file mode 100644 index 0000000..b8b0b64 --- /dev/null +++ b/src/components/PositionMatching/index.vue @@ -0,0 +1,55 @@ + + + + + + + + + + + + diff --git a/src/examples/service.vue b/src/examples/service.vue index 5e0293d..6a7098f 100644 --- a/src/examples/service.vue +++ b/src/examples/service.vue @@ -1,156 +1,149 @@ - + \ No newline at end of file + diff --git a/src/views/dashboard/index.vue b/src/views/dashboard/index.vue index 0fe450b..59a0ad0 100644 --- a/src/views/dashboard/index.vue +++ b/src/views/dashboard/index.vue @@ -1,5 +1,8 @@ + WFS服务 移除wFS服务图层 @@ -12,12 +15,15 @@ 坐标转换 + + +