Skip to content

Commit 17e3f59

Browse files
committed
[feature] 扩展mapboxgl的 setStyle 接口 支持 layer带symbol属性。
review by zhaoq
1 parent fa93021 commit 17e3f59

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

src/mapboxgl/core/MapExtend.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,24 @@ export var MapExtend = (function () {
126126
);
127127
};
128128

129-
maplibregl.Map.prototype.setSymbol = function (layerId, symbol) {
129+
mapboxgl.Map.prototype.setSymbol = function (layerId, symbol) {
130130
this.symbolLayerManager('mapbox', this).setSymbol(layerId, symbol);
131131
};
132132

133+
if(!(mapboxgl.Map.prototype).setStyleBak) {
134+
(mapboxgl.Map.prototype).setStyleBak = mapboxgl.Map.prototype.setStyle;
135+
mapboxgl.Map.prototype.setStyle = function (style, options) {
136+
this.setStyleBak(style, options);
137+
this.style.once('style.load', () => {
138+
const symbolLayers = style.layers.filter(l => l.symbol);
139+
symbolLayers.forEach((l) => {
140+
this.setSymbol(l.id, l.symbol);
141+
});
142+
});
143+
return this;
144+
}
145+
};
146+
133147
function addLayer(layer, map) {
134148
layer.onAdd && layer.onAdd(map);
135149
}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import MapboxSymbolLayerManager from "./MapboxSymbolLayerManager";
22

3-
export const SymbolLayerManager = () => {
3+
const SymbolLayerManager = () => {
44
const result = {};
55
return (type) => {
66
if(!result[type]) {
@@ -10,4 +10,5 @@ export const SymbolLayerManager = () => {
1010
}
1111
return result[type];
1212
}
13-
}
13+
}
14+
export default SymbolLayerManager;

src/mapboxgl/core/symbol/SymbolTransformUtil.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export function getSymbolPaintLayout(symbolInfo) {
2424
paint: {
2525
'icon-color': symbolInfo.color || IMAGE_POINT_DEFAULT_VALUE.color,
2626
'icon-opacity': symbolInfo.opacity || IMAGE_POINT_DEFAULT_VALUE.opacity,
27-
'icon-translate': symbolInfo.translate || IMAGE_POINT_DEFAULT_VALUE.translate,
27+
'icon-translate': symbolInfo.translate || IMAGE_POINT_DEFAULT_VALUE.translate
2828
},
2929
layout: {
3030
'icon-size': symbolInfo.size || IMAGE_POINT_DEFAULT_VALUE.size,
@@ -51,7 +51,7 @@ export function getCirclePaintLayout(symbolInfo) {
5151
'circle-stroke-color': symbolInfo.stroke || SIMPLE_POINT_DEFAULT_VALUE.stroke,
5252
'circle-stroke-width': symbolInfo.strokeWidth || SIMPLE_POINT_DEFAULT_VALUE.strokeWidth,
5353
'circle-stroke-opacity': symbolInfo.strokeOpacity || SIMPLE_POINT_DEFAULT_VALUE.strokeOpacity,
54-
'circle-translate': symbolInfo.translate || SIMPLE_POINT_DEFAULT_VALUE.translate,
54+
'circle-translate': symbolInfo.translate || SIMPLE_POINT_DEFAULT_VALUE.translate
5555
// 符号库暂未支持的属性
5656
// 'circle-translate-anchor': symbolInfo.translateAnchor
5757
},

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy