diff --git a/src/api/gis/service.js b/src/api/gis/service.js new file mode 100644 index 0000000..345cf50 --- /dev/null +++ b/src/api/gis/service.js @@ -0,0 +1,169 @@ +import axios from "axios"; + +/** + * @description:加载WMS服务 + * @param map + * @param url String + * @param option Object + * + */ +export function loadWMS(map,url,option){ + if(url) { + let 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 + }) + + }else{ + alert('请输入WMS服务地址!') + } + +} + +/** + * @description:根据id删除指定图层 + * @param map + * @param url + */ +export function removeLayer(map,url,option){ + console.log(url,'地址') + let id=url.split('layer=')[1] + console.log(id,'移除的id') + map.removeLayer(id) + map.removeSource(id) +} + +/** + * @description:移除WFS服务图层 + * @param {*} map + * @param {*} url + * @param {*} option + */ +export function removeWFSLayer(map,option){ + map.removeLayer(option.id) + map.removeSource(option.id) +} +/** + * @description:加载WFS服务 + * @param url String + * @param option Object + */ + export function loadWFSLayer(map,url,option){ + if(url){ + axios.get(url).then((res) => { + + let features = res.data.features; + // console.log(features, "元素层"); + // let layerType = null; + // let geometryType = features[0].geometry.type; + let 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); + + }); + }else{ + alert('请输入WFS地址!') + } + +} + +/** + * @description:加载WMTS服务 + * @param map + * @param url String + * @param option Object + */ + export function loadWMTS(map,url,option){ + if(url){ + + let 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 + }) + }else{ + alert('请输入WMTS服务地址!') + } + +} + +/** + * @description:加载TMS服务 + * @param map + * @param url String + * @param option Object + */ + export function loadTMSLayer(map,url,option){ + if(url){ + let 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 + }) + }else{ + alert('请输入TMS服务地址!') + } + +} + diff --git a/src/views/dashboard/index.vue b/src/views/dashboard/index.vue index c21d447..2ca03c7 100644 --- a/src/views/dashboard/index.vue +++ b/src/views/dashboard/index.vue @@ -4,72 +4,173 @@
+ + + +
- +
+