Skip to content

Commit 0d4abb2

Browse files
committed
[update] 修复直接使用npm项目,不配置babel 打包报错问题
review by luox
1 parent 94b3c7d commit 0d4abb2

File tree

7 files changed

+44
-40
lines changed

7 files changed

+44
-40
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"release-leaflet-es6": "cross-env moduleVersion=es6 npm run deploy-leaflet && node ./node_modules/uglify-es/bin/uglifyjs ./dist/leaflet/iclient-leaflet-es6.js --ecma 6 --comments /iclient-/i -c -m -o ./dist/leaflet/iclient-leaflet-es6.min.js && cleancss -o ./dist/leaflet/iclient-leaflet.min.css ./dist/leaflet/iclient-leaflet.css",
2626
"release-openlayers-es6": "cross-env moduleVersion=es6 npm run deploy-openlayers && node ./node_modules/uglify-es/bin/uglifyjs ./dist/openlayers/iclient-openlayers-es6.js --ecma 6 --comments /iclient-/i -c -m -o ./dist/openlayers/iclient-openlayers-es6.min.js && cleancss -o ./dist/openlayers/iclient-openlayers.min.css ./dist/openlayers/iclient-openlayers.css",
2727
"release-ol-es6": "cross-env moduleVersion=es6 npm run deploy-ol && node ./node_modules/uglify-es/bin/uglifyjs ./dist/ol/iclient-ol-es6.js --ecma 6 --comments /iclient-/i -c -m -o ./dist/ol/iclient-ol-es6.min.js && cleancss -o ./dist/ol/iclient-ol.min.css ./dist/ol/iclient-ol.css",
28-
"release-mapboxgl-es6": "cross-env moduleVersion=es6 npm run deploy-mapboxgl && node ./node_modules/terser/bin/terser ./dist/mapboxgl/iclient-mapboxgl-es6.js --ecma 6 --comments /iclient-/i -c -m -o ./dist/mapboxgl/iclient-mapboxgl-es6.min.js && cleancss -o ./dist/mapboxgl/iclient-mapboxgl.min.css ./dist/mapboxgl/iclient-mapboxgl.css",
28+
"release-mapboxgl-es6": "cross-env moduleVersion=es6 npm run deploy-mapboxgl && node ./node_modules/uglify-es/bin/uglifyjs ./dist/mapboxgl/iclient-mapboxgl-es6.js --ecma 6 --comments /iclient-/i -c -m -o ./dist/mapboxgl/iclient-mapboxgl-es6.min.js && cleancss -o ./dist/mapboxgl/iclient-mapboxgl.min.css ./dist/mapboxgl/iclient-mapboxgl.css",
2929
"release-classic-es6": "cross-env moduleVersion=es6 npm run deploy-classic && node ./node_modules/uglify-es/bin/uglifyjs ./dist/classic/iclient-classic-es6.js --ecma 6 --comments /iclient-/i -c -m -o ./dist/classic/iclient-classic-es6.min.js",
3030
"release-maplibregl-es5": "cross-env moduleVersion=es5 npm run deploy-maplibregl && uglifyjs ./dist/maplibregl/iclient-maplibregl.js --ecma 5 --comments /iclient-/i -c -m -o ./dist/maplibregl/iclient-maplibregl.min.js",
3131
"release-maplibregl-es6": "cross-env moduleVersion=es6 npm run deploy-maplibregl && node ./node_modules/uglify-es/bin/uglifyjs ./dist/maplibregl/iclient-maplibregl-es6.js --ecma 6 --comments /iclient-/i -c -m -o ./dist/maplibregl/iclient-maplibregl-es6.min.js",

src/mapboxgl/overlay/symbol/MapExtendSymbol.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ function MapExtendSymbol(){
9191
(mapboxgl.Map.prototype).setStyleBak = mapboxgl.Map.prototype.setStyle;
9292
mapboxgl.Map.prototype.setStyle = function (style, options) {
9393
this.setStyleBak(style, options);
94-
this.style?.once('style.load', () => {
94+
this.style && this.style.once('style.load', () => {
9595
const symbolLayers = style.layers.filter(l => l.symbol);
9696
symbolLayers.forEach((l) => {
9797
this.setSymbol(l.id, l.symbol);
@@ -240,7 +240,9 @@ function MapExtendSymbol(){
240240
if (!value) {
241241
return null;
242242
}
243-
const hasImage = value?.paint?.['fill-pattern'] || value?.paint?.['line-pattern'] || value?.layout?.['icon-image'];
243+
const paint = value.paint || {};
244+
const layout = value.layout || {};
245+
const hasImage = paint['fill-pattern'] || paint['line-pattern'] || layout['icon-image'];
244246
const image = hasImage && await new Promise((resolve) => {
245247
const image = new Image();
246248
image.src = `${url}.png`;

src/mapboxgl/overlay/symbol/SingleSymbolRender.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ class SingleSymbolRender {
2020
if(layer.layout && layer.layout.visibility === 'none') {
2121
Object.assign(layer.layout, {visibility: 'visible'});
2222
}
23-
layer.paint && Object.assign(symbol.paint ?? {}, layer.paint);
24-
layer.layout && Object.assign(symbol.layout ?? {}, layer.layout);
23+
layer.paint && Object.assign(symbol.paint || {}, layer.paint);
24+
layer.layout && Object.assign(symbol.layout || {}, layer.layout);
2525
this.map.addLayerBySymbolBak({ ...layer, ...symbol }, before);
2626
}
2727
}

src/mapboxgl/overlay/symbol/SymbolHandler.js

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,13 @@ import { getImageKey, isMapboxExpression, isMultiSymbol, validateSymbol } from "
1313
* @private
1414
*/
1515
class SymbolHandler {
16-
#layerSymbols; // 图层与symbol的映射关系
1716

1817
constructor(map) {
1918
this.map = map;
2019
this.symbolManager = new SymbolManager();
2120
this.singleSymbolRender = new SingleSymbolRender(map);
2221
this.compositeSymbolRender = new CompositeSymbolRender(map);
23-
this.#layerSymbols = {};
22+
this._layerSymbols = {};// 图层与symbol的映射关系
2423
}
2524

2625
_update(map) {
@@ -66,11 +65,12 @@ class SymbolHandler {
6665
});
6766
}
6867
this.map.removeLayer(layerId);
69-
const beforeId = layers[layerIndex + 1]?.id;
70-
const before = beforeId && (this.map.style.getLayer(beforeId)?.id ?? this.getFirstLayerId(beforeId));
68+
const beforeId = layers[layerIndex + 1] && layers[layerIndex + 1].id;
69+
const layer = beforeId && this.map.style.getLayer(beforeId);
70+
const before = (layer && layer.id) || (beforeId && this.getFirstLayerId(beforeId));
7171
const orginLayer = layers[layerIndex];
7272
this.addLayer({ ...orginLayer, paint: {}, layout: {
73-
visibility: orginLayer.layout?.visibility ?? 'visible'
73+
visibility: (orginLayer.layout && orginLayer.layout.visibility) || 'visible'
7474
}, symbol }, before);
7575
}
7676

@@ -145,7 +145,8 @@ class SymbolHandler {
145145
match: this.getMatchLayers,
146146
case: this.getCaseLayers
147147
}
148-
const layers = rules[layer.symbol[0]]?.(layer);
148+
const getLayersFn = rules[layer.symbol[0]];
149+
const layers = getLayersFn && getLayersFn(layer);
149150
if (!layers) {
150151
return this.map.fire('error', {
151152
error: new Error(`This expressions not supported`)
@@ -174,7 +175,7 @@ class SymbolHandler {
174175
*/
175176
addSymbolImageToMap(symbol, image) {
176177
const { type, name } = getImageKey(symbol);
177-
const id = symbol[type]?.[name];
178+
const id = symbol[type] && symbol[type][name];
178179
if (id && !this.map.hasImage(id)) {
179180
// 如果需要使用到image 的需要addImage
180181
this.map.addImage(id, image);
@@ -209,7 +210,7 @@ class SymbolHandler {
209210
* @param {string | array} symbol
210211
*/
211212
setSymbolTolayer(layerId, symbol) {
212-
this.#layerSymbols[layerId] = symbol;
213+
this._layerSymbols[layerId] = symbol;
213214
}
214215

215216
/**
@@ -218,15 +219,15 @@ class SymbolHandler {
218219
* @return {string | array} symbol
219220
*/
220221
getSymbol(layerId) {
221-
return this.#layerSymbols[layerId];
222+
return this._layerSymbols[layerId];
222223
}
223224

224225
/**
225226
* 判断是否有symbol
226227
* @return {boolean}
227228
*/
228229
hasSymbol() {
229-
return Object.keys(this.#layerSymbols).length > 0;
230+
return Object.keys(this._layerSymbols).length > 0;
230231
}
231232

232233
/**
@@ -251,7 +252,7 @@ class SymbolHandler {
251252
* @returns {array}
252253
*/
253254
getLayerIds(layerId) {
254-
return this.compositeSymbolRender.getLayerIds(layerId);
255+
return this.compositeSymbolRender.getLayerIds(layerId) || [];
255256
}
256257

257258
/**
@@ -284,7 +285,7 @@ class SymbolHandler {
284285
return symbol ? { ...layer, symbol } : layer;
285286
} else {
286287
const layerIds = this.getLayerIds(layerId);
287-
if (layerIds?.[0]) {
288+
if (layerIds[0]) {
288289
const reallayer = this.map.getLayerBySymbolBak(layerIds[0]);
289290
return reallayer && { ...reallayer, symbol, id: layerId }
290291
}
@@ -297,7 +298,7 @@ class SymbolHandler {
297298
*/
298299
removeLayer(layerId) {
299300
const layerIds = this.getLayerIds(layerId);
300-
if (layerIds?.length > 0) {
301+
if (layerIds.length > 0) {
301302
layerIds.forEach(id => this.map.style.removeLayer(id));
302303
this.removeLayerId(layerId);
303304
} else {
@@ -334,7 +335,7 @@ class SymbolHandler {
334335
*/
335336
getFirstLayerId(layerId) {
336337
const layerIds = this.getLayerIds(layerId);
337-
return layerIds?.[0];
338+
return layerIds[0];
338339
}
339340

340341
/**
@@ -344,8 +345,9 @@ class SymbolHandler {
344345
*/
345346
moveLayer(layerId, beforeId) {
346347
const layerIds = this.getLayerIds(layerId);
347-
const realBeforeId = beforeId && (this.map.style.getLayer(beforeId)?.id ?? this.getFirstLayerId(beforeId));
348-
if (layerIds?.length > 0) {
348+
const layer = beforeId && this.map.style.getLayer(beforeId);
349+
const realBeforeId = (layer && layer.id) || (beforeId && this.getFirstLayerId(beforeId));
350+
if (layerIds.length > 0) {
349351
layerIds.forEach(id => this.map.style.moveLayer(id, realBeforeId));
350352
} else {
351353
this.map.style.moveLayer(layerId, realBeforeId);
@@ -369,7 +371,7 @@ class SymbolHandler {
369371
return;
370372
}
371373
const layerIds = this.getLayerIds(layerId);
372-
if (layerIds?.length > 0) {
374+
if (layerIds.length > 0) {
373375
layerIds.forEach(id => this.map.style.setFilter(id, filter, options));
374376
} else {
375377
this.map.style.setFilter(layerId, filter, options);
@@ -396,7 +398,7 @@ class SymbolHandler {
396398
*/
397399
setLayerZoomRange(layerId, minzoom, maxzoom) {
398400
const layerIds = this.getLayerIds(layerId);
399-
if (layerIds?.length > 0) {
401+
if (layerIds.length > 0) {
400402
layerIds.forEach(id => this.map.style.setLayerZoomRange(id, minzoom, maxzoom));
401403
} else {
402404
this.map.style.setLayerZoomRange(layerId, minzoom, maxzoom);
@@ -412,7 +414,7 @@ class SymbolHandler {
412414
*/
413415
setPaintProperty(layerId, name, value, options) {
414416
const layerIds = this.getLayerIds(layerId);
415-
if (layerIds?.length > 0) {
417+
if (layerIds.length > 0) {
416418
layerIds.forEach(id => this.map.style.setPaintProperty(id, name, value, options));
417419
} else {
418420
this.map.style.setPaintProperty(layerId, name, value, options);
@@ -439,7 +441,7 @@ class SymbolHandler {
439441
*/
440442
setLayoutProperty(layerId, name, value, options) {
441443
const layerIds = this.getLayerIds(layerId);
442-
if (layerIds?.length > 0) {
444+
if (layerIds.length > 0) {
443445
layerIds.forEach(id => this.map.style.setLayoutProperty(id, name, value, options));
444446
} else {
445447
this.map.style.setLayoutProperty(layerId, name, value, options);

src/mapboxgl/overlay/symbol/SymbolManager.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22
* This program are made available under the terms of the Apache License, Version 2.0
33
* which accompanies this distribution and is available at http://www.apache.org/licenses/LICENSE-2.0.html.*/
44
class SymbolManager {
5-
symbols;// addSymbol接口添加的symbol信息
6-
images; // 在loadImage的时候存下image
75

86
constructor() {
9-
this.symbols = {};
10-
this.images = {};
7+
this.symbols = {};//addSymbol接口添加的symbol信息
8+
this.images = {};//在loadImage的时候存下image
119
}
1210

1311
addSymbol(id, symbol) {

src/mapboxgl/overlay/symbol/SymbolUtil.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const GET_TYPE_RULE = [{
2121
}];
2222

2323
export function isMultiSymbol(symbol) {
24-
return symbol?.length > 0;
24+
return symbol && symbol.length > 0;
2525
}
2626

2727
/**
@@ -67,7 +67,7 @@ export function getSymbolType(symbol) {
6767
break;
6868
}
6969
}
70-
return type ?? LayerType.symbol;
70+
return type || LayerType.symbol;
7171
}
7272

7373
const MAPBOX_EXPRESSION_FIRST_VALUE = [
@@ -155,7 +155,7 @@ const MAPBOX_EXPRESSION_FIRST_VALUE = [
155155
* @private
156156
*/
157157
export function isMapboxExpression(value) {
158-
if (value?.length > 0) {
158+
if (value && value.length > 0) {
159159
const [v] = value;
160160
return typeof v === 'string' && MAPBOX_EXPRESSION_FIRST_VALUE.includes(v);
161161
}
@@ -171,6 +171,6 @@ export function validateStyleKey(value) {
171171
export function validateSymbol(symbol) {
172172
const symbolInfo = isMultiSymbol(symbol) ? symbol : [symbol];
173173
return symbolInfo.every((s) => {
174-
return validateStyleKey(s.paint ?? {}) && validateStyleKey(s.layout ?? {});
174+
return validateStyleKey(s.paint || {}) && validateStyleKey(s.layout || {});
175175
});
176176
}

src/mapboxgl/overlay/symbol/WebSymbol.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,14 @@ import MapExtendSymbol from './MapExtendSymbol';
173173
*/
174174
export class WebSymbol {
175175

176-
/**
177-
* @member WebSymbol.prototype.defaultBasePath
178-
* @description 符号资源路径。
179-
* @private
180-
*/
181-
defaultBasePath = './resources/symbols';
176+
constructor() {
177+
/**
178+
* @member WebSymbol.prototype.defaultBasePath
179+
* @description 符号资源路径。
180+
* @private
181+
*/
182+
this.defaultBasePath = './resources/symbols';
183+
}
182184

183185
/**
184186
* @function WebSymbol.prototype.init
@@ -187,7 +189,7 @@ export class WebSymbol {
187189
* @param {string} [config.basePath] - 指定符号资源路径
188190
*/
189191
init(config) {
190-
mapboxgl.Map.prototype.basePath = config?.basePath ?? this.defaultBasePath;
192+
mapboxgl.Map.prototype.basePath = config && config.basePath || this.defaultBasePath;
191193
MapExtendSymbol();
192194
}
193195
}

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