Skip to content

Commit 91cf154

Browse files
committed
[update] 优化代码
review by zhaoq
1 parent 6eaafc3 commit 91cf154

File tree

10 files changed

+1802
-1365
lines changed

10 files changed

+1802
-1365
lines changed

build/jsdocs/mapboxgl/categories.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

dist/mapboxgl/iclient-mapboxgl-es6.js

Lines changed: 243 additions & 103 deletions
Large diffs are not rendered by default.

dist/mapboxgl/iclient-mapboxgl-es6.min.js

Lines changed: 434 additions & 434 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/mapboxgl/iclient-mapboxgl.js

Lines changed: 220 additions & 141 deletions
Large diffs are not rendered by default.

dist/mapboxgl/iclient-mapboxgl.min.js

Lines changed: 425 additions & 425 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/mapboxgl-v2/libs/mapboxgl/iclient-mapboxgl.js

Lines changed: 220 additions & 141 deletions
Large diffs are not rendered by default.

src/mapboxgl/core/MapExtend.js

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import mapboxgl from 'mapbox-gl';
55
import CompositeLayer from '../symbol/CompositeLayer';
66
import SymbolLayer from '../symbol/SymbolLayer';
77
import Symbol from '../symbol/Symbol';
8+
import { validateSymbol } from '../symbol/SymbolUtil';
89

910
/**
1011
* @function MapExtend
@@ -22,7 +23,7 @@ export var MapExtend = (function () {
2223
mapboxgl.Map.prototype.addLayerBak = mapboxgl.Map.prototype.addLayer;
2324
mapboxgl.Map.prototype.addLayer = function (layer, before) {
2425
if(layer.symbol) {
25-
this.symbolLayerManager(this).addLayer(layer, layer.symbol, before);
26+
this.symbolLayerManager(this).addLayer(layer, before);
2627
return this;
2728
}
2829

@@ -149,38 +150,32 @@ export var MapExtend = (function () {
149150

150151

151152
mapboxgl.Map.prototype.loadSymbol = async function (symbol, callback) {
152-
let error;
153-
let symbolInfo = symbol;
154153
if(typeof symbol === 'string') {
155-
symbolInfo = this.symbolManager.getSymbol(symbol);
154+
let symbolInfo = this.symbolManager.getSymbol(symbol);
156155
if (!symbolInfo) {
157156
if(!mapboxgl.supermap.WebSymbol.symbolUrl) {
158-
error = {
159-
message: 'symbolUrl of WebSymbol is null. '
160-
};
161-
callback(error);
157+
callback({
158+
message: 'SymbolUrl of WebSymbol is null. '
159+
});
162160
return;
163161
}
164162
const symbolResult = await mapboxgl.supermap.WebSymbol.getSymbol?.(symbol);
165163
if(!symbolResult) {
166-
error = {
167-
message: 'This symbol is not exists.'
168-
};
169-
} else {
170-
const {value, image} = symbolResult;
171-
symbolInfo = value;
172-
const {type, name} = this.symbolLayerManager(this).getImageKey(value);
173-
const id = value[type]?.[name];
174-
if(id) {
175-
// 如果需要使用到image 的需要addImage
176-
this.addImage(id, image);
177-
// 为了解决sdf问题,需要把load后的image信息存下
178-
this.symbolManager.addImageInfo(id, image);
179-
}
164+
callback({
165+
message: 'This symbol is not exists.'
166+
});
167+
return;
180168
}
169+
const {value, image} = symbolResult;
170+
symbolInfo = value;
171+
this.symbolLayerManager(this).addSymbolImageToMap(value, image);
181172
}
173+
callback(null, symbolInfo);
174+
} else {
175+
callback({
176+
message: 'Symbol id must be a string.'
177+
});
182178
}
183-
callback(error, symbolInfo);
184179
};
185180

186181
mapboxgl.Map.prototype.addSymbol = function (id, symbol) {
@@ -189,7 +184,13 @@ export var MapExtend = (function () {
189184
error: new Error('An symbol with this name already exists.')
190185
});
191186
}
192-
this.symbolManager.addSymbol(id, symbol);
187+
if(validateSymbol(symbol)) {
188+
this.symbolManager.addSymbol(id, symbol);
189+
} else {
190+
this.fire('error', {
191+
error: new Error('Symbol is not supported expressions。')
192+
});
193+
}
193194
};
194195

195196
mapboxgl.Map.prototype.hasSymbol = function(id) {

src/mapboxgl/symbol/CompositeLayer.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
/**
22
* 组合图层管理器
3-
* @returns {Object}
3+
* @returns {Object}
4+
* @private
45
*/
56
const CompositeLayersManager = () => {
67
const layers = {};
78
return {
89
/**
910
* 添加图层
10-
* @param id
11-
* @param childId
11+
* @param {string} id
12+
* @param {string} childId
13+
* @private
1214
*/
1315
addLayer(id, childId) {
1416
if (!layers[id]) {
@@ -19,9 +21,9 @@
1921

2022
/**
2123
* 删除图层
22-
* @param {*} id
23-
* @param {*} childId
24-
* @returns {undefined}
24+
* @param {string} id
25+
* @param {string} childId
26+
* @private
2527
*/
2628
removeLayer(id, childId) {
2729
if (childId) {
@@ -36,17 +38,19 @@
3638

3739
/**
3840
* 获取图层
39-
* @param id
41+
* @param {string} id
4042
* @returns {Array}
43+
* @private
4144
*/
4245
getLayers(id) {
4346
return layers[id];
4447
},
4548

4649
/**
4750
* 获取组合图层ID
48-
* @param {*} childId
51+
* @param {string} childId
4952
* @returns {string}
53+
* @private
5054
*/
5155
getCompositeLayerId(childId) {
5256
for (const id in layers) {

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