MCPcopy Create free account
hub / github.com/SuperMap/iClient-JavaScript / _setUniqueId

Method _setUniqueId

src/common/mapping/MapStyle.js:99–142  ·  view source on GitHub ↗
(style)

Source from the content-addressed store, hash-verified

97 }
98
99 _setUniqueId(style) {
100 const layersToMap = JSON.parse(JSON.stringify(style.layers));
101 const nextSources = {};
102 const sourcesIdChangedMap = {};
103 const layerIdToChange = [];
104 const timestamp = `_${+new Date()}`;
105 for (const sourceId in style.sources) {
106 let nextSourceId = sourceId;
107 if (this.map.getSource(sourceId)) {
108 nextSourceId = sourceId + timestamp;
109 }
110 sourcesIdChangedMap[nextSourceId] = sourceId;
111 nextSources[nextSourceId] = style.sources[sourceId];
112 for (const layer of layersToMap) {
113 if (layer.source === sourceId) {
114 layer.source = nextSourceId;
115 }
116 }
117 }
118 for (const layer of layersToMap) {
119 const originId = layer.id;
120 let reused;
121 const existLayer = this.map.getLayer(layer.id);
122 if (existLayer) {
123 // 此时用 getSource(xx).tiles 为空
124 if (
125 this.options.checkSameLayer &&
126 isSameRasterLayer(nextSources[layer.source], this.map.getStyle().sources[existLayer.source])
127 ) {
128 reused = true;
129 layer.source = sourcesIdChangedMap[layer.source];
130 } else {
131 const layerId = layer.id + timestamp;
132 layer.id = layerId;
133 }
134 }
135 layerIdToChange.push({ originId: originId, renderId: layer.id, reused });
136 }
137 return {
138 sources: nextSources,
139 layers: layersToMap,
140 layerIdMapList: layerIdToChange
141 };
142 }
143
144 _generateAppreciableLayers() {
145 return this.mapOptions.style.layers.reduce((layers, layer) => {

Callers 1

_addLayersToMapMethod · 0.95

Calls 6

isSameRasterLayerFunction · 0.90
pushMethod · 0.80
parseMethod · 0.45
getSourceMethod · 0.45
getLayerMethod · 0.45
getStyleMethod · 0.45

Tested by

no test coverage detected