| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent c89f68d commit 6b16b14
12 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -649,7 +649,24 @@ function WebMapSourceToL7Source(source, sourceLayer, options) { | |||
| 649 | 649 | return rules[type] && rules[type](source, sourceLayer, options); | |
| 650 | 650 | } | |
| 651 | 651 | ||
| 652 | - function getL7Filter(filter) { | ||
| 652 | + function getFilterFields(filter) { | ||
| 653 | + const result = []; | ||
| 654 | + for (const exp of filter) { | ||
| 655 | + if (exp instanceof Array && exp[1] && typeof exp[1] === 'string') { | ||
| 656 | + result.push(exp[1]); | ||
| 657 | + continue; | ||
| 658 | + } | ||
| 659 | + if (exp instanceof Array) { | ||
| 660 | + const subResult = getFilterFields(exp); | ||
| 661 | + if (subResult && subResult.length > 0) { | ||
| 662 | + result.push(...subResult); | ||
| 663 | + } | ||
| 664 | + } | ||
| 665 | + } | ||
| 666 | + return result; | ||
| 667 | + } | ||
| 668 | + | ||
| 669 | + export function getL7Filter(filter) { | ||
| 653 | 670 | if (!filter) { | |
| 654 | 671 | return; | |
| 655 | 672 | } | |
@@ -661,7 +678,7 @@ function getL7Filter(filter) { | |||
| 661 | 678 | } | |
| 662 | 679 | return true; | |
| 663 | 680 | }); | |
| 664 | - const field = newExpressions.map((exp) => exp[1]); | ||
| 681 | + const field = Array.from(new Set(getFilterFields(newExpressions))); | ||
| 665 | 682 | const fFilter = featureFilter([condition, ...newExpressions]); | |
| 666 | 683 | const filterFunc = fFilter.filter.bind(fFilter); | |
| 667 | 684 | return { | |
@@ -687,14 +704,19 @@ function getL7Filter(filter) { | |||
| 687 | 704 | * @param layer | |
| 688 | 705 | */ | |
| 689 | 706 | function getL7LayerCommonInfo(layer) { | |
| 690 | - const { id, minzoom, maxzoom, layout, filter } = layer; | ||
| 707 | + const { type, id, minzoom, maxzoom, layout, paint, filter, source } = layer; | ||
| 691 | 708 | return { | |
| 692 | 709 | id, | |
| 693 | 710 | options: { | |
| 711 | + type, | ||
| 694 | 712 | name: layer.id, | |
| 695 | 713 | sourceLayer: layer['source-layer'], | |
| 696 | - minzoom, | ||
| 697 | - maxzoom, | ||
| 714 | + source, | ||
| 715 | + layout, | ||
| 716 | + paint, | ||
| 717 | + filter, | ||
| 718 | + minZoom: minzoom, | ||
| 719 | + maxZoom: maxzoom, | ||
| 698 | 720 | visible: layout.visibility === 'none' ? false : true | |
| 699 | 721 | }, | |
| 700 | 722 | filter: getL7Filter(filter) | |
@@ -1908,15 +1930,15 @@ function getL7Layer(l) { | |||
| 1908 | 1930 | [MSLayerType.polygon]: 'PolygonLayer', | |
| 1909 | 1931 | [MSLayerType.heatmap]: 'HeatmapLayer' | |
| 1910 | 1932 | }; | |
| 1933 | + const source = l.source || {}; | ||
| 1911 | 1934 | const layer = new L7Layer({ | |
| 1912 | 1935 | type: typeRule[l.type], | |
| 1913 | - options: { ...l.options, layerID: (l.options || {}).name } | ||
| 1936 | + options: { ...l.options, layerID: (l.options || {}).name, featureId: (source.parser || {}).type === 'mvt' ? 'smpid' : undefined } // 解决L7结构化数据监听click事件会返回多个features问题 | ||
| 1914 | 1937 | }); | |
| 1915 | 1938 | // getL7Layer返回原生antv l7 layer的实例 | |
| 1916 | 1939 | const l7Layer = layer.getL7Layer(); | |
| 1917 | 1940 | // 调用原生antv l7 layer的方法,构建图层 | |
| 1918 | 1941 | const sourceOptions = {}; | |
| 1919 | - const source = l.source || {}; | ||
| 1920 | 1942 | const shape = l.shape || {}; | |
| 1921 | 1943 | if (source.parser) { | |
| 1922 | 1944 | sourceOptions.parser = l.source.parser; | |
@@ -1982,7 +2004,9 @@ export async function addL7Layers({ map, webMapInfo, l7Layers, spriteDatas, opti | |||
| 1982 | 2004 | ChartController.setSceneChartLayer(l.id, actionLayer); | |
| 1983 | 2005 | } else { | |
| 1984 | 2006 | const layer = getL7Layer(l); | |
| 1985 | - map.addLayer(layer, beforeLayer && beforeLayer.id); | ||
| 2007 | + if (!map.getLayer(layer.id)) { | ||
| 2008 | + map.addLayer(layer, beforeLayer && beforeLayer.id); | ||
| 2009 | + } | ||
| 1986 | 2010 | } | |
| 1987 | 2011 | } | |
| 1988 | 2012 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -194,6 +194,31 @@ export class WebMap extends mapboxgl.Evented { | |||
| 194 | 194 | return this._legendList; | |
| 195 | 195 | } | |
| 196 | 196 | ||
| 197 | + async copyLayer(id, layerInfo = {}) { | ||
| 198 | + const matchLayer = this._mapInfo.layers.find(layer => layer.id === id); | ||
| 199 | + if (!matchLayer || this.map.getLayer(layerInfo.id)) { | ||
| 200 | + return; | ||
| 201 | + } | ||
| 202 | + const copyLayerId = layerInfo.id || `${matchLayer.id}_copy`; | ||
| 203 | + const copyLayer = { ...matchLayer, ...layerInfo, id: copyLayerId }; | ||
| 204 | + if (isL7Layer(copyLayer)) { | ||
| 205 | + const layers = [copyLayer]; | ||
| 206 | + await addL7Layers({ | ||
| 207 | + map: this.map, | ||
| 208 | + webMapInfo: { ...this._mapInfo, layers, sources: this._mapInfo.sources }, | ||
| 209 | + l7Layers: layers, | ||
| 210 | + spriteDatas: this._spriteDatas, | ||
| 211 | + options: this.options | ||
| 212 | + }); | ||
| 213 | + return; | ||
| 214 | + } | ||
| 215 | + if (typeof copyLayer.source === 'object') { | ||
| 216 | + this.map.addSource(copyLayer.id, copyLayer.source); | ||
| 217 | + copyLayer.source = copyLayer.id; | ||
| 218 | + } | ||
| 219 | + this.map.addLayer(copyLayer); | ||
| 220 | + } | ||
| 221 | + | ||
| 197 | 222 | /** | |
| 198 | 223 | * @private | |
| 199 | 224 | * @function WebMap.prototype._createMap | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,60 @@ | |||
| 1 | + export class CustomOverlayLayer { | ||
| 2 | + constructor(options) { | ||
| 3 | + this.type = 'custom'; | ||
| 4 | + this.overlay = true; | ||
| 5 | + this.sourceId = options.sourceId; | ||
| 6 | + // interaction 控制是否支持事件 | ||
| 7 | + this.interaction = options.interaction || false; | ||
| 8 | + // query 是否支持查询 | ||
| 9 | + this.query = options.query || false; | ||
| 10 | + this.events = options.events || []; | ||
| 11 | + } | ||
| 12 | + | ||
| 13 | + // 获取 layer 的信息,如 type, id, sourceLayer, layout 等 | ||
| 14 | + getLayer() {} | ||
| 15 | + | ||
| 16 | + // 更换 layer 的顺序 | ||
| 17 | + moveLayer() {} | ||
| 18 | + | ||
| 19 | + // 获取 layer source的信息,如 id,type 等 | ||
| 20 | + getSource() {} | ||
| 21 | + | ||
| 22 | + // 返回指定样式图层中绘制属性的值 | ||
| 23 | + getPaintProperty() {} | ||
| 24 | + | ||
| 25 | + // 返回指定样式图层中布局属性的值 | ||
| 26 | + getLayoutProperty() {} | ||
| 27 | + | ||
| 28 | + // 修改指定样式图层中布局属性的值 | ||
| 29 | + setLayoutProperty() {} | ||
| 30 | + | ||
| 31 | + // 返回应用于指定样式图层的过滤器 | ||
| 32 | + getFilter() {} | ||
| 33 | + | ||
| 34 | + // 设定指定样式图层的过滤器 | ||
| 35 | + setFilter() {} | ||
| 36 | + | ||
| 37 | + // map 添加 layer 时的钩子函数 | ||
| 38 | + onAdd() {} | ||
| 39 | + | ||
| 40 | + // map 移除 layer 时的钩子函数 | ||
| 41 | + onRemove() {} | ||
| 42 | + | ||
| 43 | + // map 渲染 layer 时的钩子函数 | ||
| 44 | + render() {} | ||
| 45 | + | ||
| 46 | + // 注册 layer 事件,触发多次 | ||
| 47 | + on() {} | ||
| 48 | + | ||
| 49 | + // 注册 layer 事件,触发一次 | ||
| 50 | + once() {} | ||
| 51 | + | ||
| 52 | + // 移除 layer 事件 | ||
| 53 | + off() {} | ||
| 54 | + | ||
| 55 | + // 查询足查询参数的可见要素的 GeoJSON 要素对象数组 | ||
| 56 | + queryRenderedFeatures() {} | ||
| 57 | + | ||
| 58 | + // 查询满足查询参数的指定矢量切片或 GeoJSON 源中的要素 | ||
| 59 | + querySourceFeatures() {} | ||
| 60 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments