diff --git a/src/api/gis/load-aggregation-graph.js b/src/api/gis/load-aggregation-graph.js new file mode 100644 index 0000000..1916097 --- /dev/null +++ b/src/api/gis/load-aggregation-graph.js @@ -0,0 +1,141 @@ +import axios from 'axios' +import { removeLayer } from './service' + +export default { + sourceId: '', + layerId: '', + clusterCountId: '', + unclusteredId: '', + /** + * 加载聚合图层 + * @param map + * @param url String 传递的后端服务地址 + * @param sourceOption Object 只需传clusterMaxZoom和clusterRadius + * @param layerOption Object 只需传filter和paint + * @param clusterLayerOption Object 只需传filter layout paint + * @param unclusterLayerOption Object 只需传filter paint + */ + loadAggregationGraph (map, url, sourceOption, layerOption, clusterLayerOption, unclusterLayerOption) { + axios.get(url).then((res) => { + if (res) { + // console.log(res, '返回的数据') + const data = res.data + + const sourceId = res.data.crs.properties.name + this.sourceId = sourceId + const layerId = sourceId + 'layer' + this.layerId = layerId + const clusterCountId = sourceId + 'clusterCount' + this.clusterCountId = clusterCountId + const unclusteredId = sourceId + 'unclustered' + this.unclusteredId = unclusteredId + map.addSource(sourceId, { + type: 'geojson', + data: data, + cluster: true, + clusterMaxZoom: sourceOption.clusterMaxZoom ? sourceOption.clusterMaxZoom : 14, // 最大缩放到群集点 + clusterRadius: sourceOption.clusterRadius ? sourceOption.clusterRadius : 50// 每一组点的半径 + }) + // 外围有数字的图层,加晕染 + map.addLayer({ + id: layerId, + type: 'circle', + source: sourceId, + // filter: ['has', 'poi_id'], + filter: layerOption.filter, + paint: layerOption.paint ? layerOption.paint : { + // 蓝色,当点数小于100时为20px圆 + // 点计数在100到750之间时为黄色,21px圆 + // 点计数大于或等于750时为22像素的粉红色圆圈 + 'circle-color': [ + 'step', + ['get', 'poi_id'], + 'rgba(81,187,214,0.8)', + 100, + 'rgba(241,240,117,0.8)', + 750, + 'rgba(242,140,177,0.8)' + ], + 'circle-radius': [ + 'step', + ['get', 'poi_id'], + 20, // 蓝色,当点数小于100时为20px圆 + 100, // 对应上面circle-color数字,意思为100以内 + 21, // 点计数在100到750之间为黄色,意思为750以内 + 750, // 对应上面circle-color数字,意思为750以内 + 22// 点计数大于或等于750时为22像素的粉红色圆圈 + ], + // 这个是外边框的颜色 circle-stroke-color这个对应了上面circle-color + 'circle-stroke-color': [ + 'step', + ['get', 'poi_id'], + 'rgba(81,187,214,0.2)', + 100, + 'rgba(241,240,117,0.2)', + 750, + 'rgba(242,140,177,0.2)' + ], + // 这个是外边框渲染的范围 + 'circle-stroke-width': [ + 'step', + ['get', 'poi_id'], + 5, // 蓝色晕染长度,当点数小于100时为5px晕染 + 100, // 对应上面circle-color数字,意思为100以内 + 6, // 点计数在100到750之间时为黄色,6px晕染 + 750, // 对应上面circle-color数字,意思为750以内 + 7// 点计数大于或等于750时为7px像素的粉红色晕染 + ] + } + }) + // 聚合图圆圈中的数字 + map.addLayer({ + id: clusterCountId, + type: 'symbol', + source: sourceId, + // filter: ['has', 'poi_id'], + filter: clusterLayerOption.filter, + layout: clusterLayerOption.layout, + // layout:{ + // 'text-field': '{poi_id}', // 文本内容来源字段 + // 'text-font': ['Microsoft YaHei'], + // 'text-size': 12 + // } + paint: clusterLayerOption.paint ? clusterLayerOption.paint : { + 'text-color': 'hsl(0, 0%, 100%)', + 'text-halo-color': '#54c081', + 'text-halo-width': 100 + } + }) + // 聚合图中没有数字的显示小圆点 + map.addLayer({ + id: unclusteredId, + type: 'circle', + source: sourceId, + // filter: ['!', ['has', 'poi_id']], + filter: unclusterLayerOption.filter, + paint: unclusterLayerOption.paint ? unclusterLayerOption.paint : { + 'circle-color': '#11b4da', + 'circle-radius': 4, + 'circle-stroke-width': 1, + 'circle-stroke-color': '#fff' + } + // paint: { + // 'circle-color': '#11b4da', + // 'circle-radius': 4, + // 'circle-stroke-width': 1, + // 'circle-stroke-color': '#fff' + // } + }) + } + }) + }, + /** + * 移除聚合图层 + */ + removeLayer (map) { + map.removeLayer(this.layerId) + map.removeLayer(this.clusterCountId) + map.removeLayer(this.unclusteredId) + map.removeSource(this.sourceId) + } +} diff --git a/src/api/gis/service.js b/src/api/gis/service.js index f343d46..89c3bd9 100644 --- a/src/api/gis/service.js +++ b/src/api/gis/service.js @@ -7,12 +7,12 @@ import axios from 'axios' * @param option Object * */ -export function loadWMS(map, url, option) { +export function loadWMS (map, url, option) { if (url) { const id = url.split('layer=')[1] const source = map.getSource(option.source) const layer = map.getLayer(option.id) - if (source == undefined && layer == undefined) { + if (source === undefined && layer === undefined) { map.addSource(option.source, { type: 'raster', @@ -38,7 +38,7 @@ export function loadWMS(map, url, option) { * @param map * @param url */ -export function removeLayer(map, url, option) { +export function removeLayer (map, url, option) { const id = url.split('layer=')[1] map.removeLayer(id) @@ -51,7 +51,7 @@ export function removeLayer(map, url, option) { * @param {*} url * @param {*} option */ -export function removeWFSLayer(map, option) { +export function removeWFSLayer (map, option) { map.removeLayer(option.id) map.removeSource(option.id) } @@ -60,10 +60,10 @@ export function removeWFSLayer(map, option) { * @param url String * @param option Object */ -export function loadWFSLayer(map, url, option) { +export function loadWFSLayer (map, url, option) { const source = map.getSource(option.id) const layer = map.getLayer(option.id) - if (source == undefined && layer == undefined) { + if (source === undefined && layer === undefined) { if (url) { axios.get(url).then((res) => { const features = res.data.features @@ -123,10 +123,10 @@ export function loadWFSLayer(map, url, option) { * @param url String * @param option Object */ -export function loadWMTS(map, url, option) { +export function loadWMTS (map, url, option) { const source = map.getSource(option.source) const layer = map.getLayer(option.id) - if (source == undefined && layer == undefined) { + if (source === undefined && layer === undefined) { if (url) { const id = url.split('layer=')[1] map.addSource(option.source, { @@ -155,22 +155,28 @@ export function loadWMTS(map, url, option) { * @param url String * @param option Object */ -export function loadTMSLayer(map, url, option) { - if (url) { - const id = url.split('layer=')[1] - map.addSource(option.source, { - type: 'raster', - tiles: [url], +export function loadTMSLayer (map, url, option) { + 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('请输入TMS服务地址!') + } } else { - alert('请输入TMS服务地址!') + alert('该图层已存在!请勿重复添加') } } diff --git a/src/assets/img/search.png b/src/assets/img/search.png index c65845f..d3ed09f 100644 Binary files a/src/assets/img/search.png and b/src/assets/img/search.png differ diff --git a/src/views/dashboard/index.vue b/src/views/dashboard/index.vue index 59a0ad0..11b96ea 100644 --- a/src/views/dashboard/index.vue +++ b/src/views/dashboard/index.vue @@ -1,19 +1,28 @@