Skip to content

Commit 46faafd

Browse files
committed
【feature】修改添加图片方式为雪碧图; review by qiw
1 parent 949fb1e commit 46faafd

File tree

1 file changed

+12
-31
lines changed

1 file changed

+12
-31
lines changed

src/mapboxgl/mapping/webmap/v3/WebMap.js

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export class WebMap extends mapboxgl.Evented {
4040
* @description 创建地图。
4141
*/
4242
_createMap() {
43-
let { name, crs, center = new mapboxgl.LngLat(0, 0), zoom = 0, bearing = 0, pitch = 0, minzoom, maxzoom } = this._mapInfo;
43+
let { name, crs, center = new mapboxgl.LngLat(0, 0), zoom = 0, bearing = 0, pitch = 0, minzoom, maxzoom, sprite } = this._mapInfo;
4444
if (this._mapInfo.center && crs === 'EPSG:3857') {
4545
center = Util.unproject(center);
4646
}
@@ -52,6 +52,7 @@ export class WebMap extends mapboxgl.Evented {
5252
center,
5353
zoom,
5454
style: {
55+
sprite,
5556
name,
5657
version: 8,
5758
sources: {},
@@ -86,11 +87,8 @@ export class WebMap extends mapboxgl.Evented {
8687
description: relatedInfo.description
8788
};
8889
this._mapResourceInfo = JSON.parse(relatedInfo.projectInfo);
89-
this._createMapRelatedInfo().then(res => {
90-
if (res) {
91-
this._addLayersToMap();
92-
}
93-
});
90+
this._createMapRelatedInfo();
91+
this._addLayersToMap();
9492
});
9593
}
9694

@@ -104,31 +102,14 @@ export class WebMap extends mapboxgl.Evented {
104102
for (let key in glyphs) {
105103
this.map.style.addGlyphs(key, glyphs[key]);
106104
}
107-
for (let key in sprite) {
108-
this.map.style.addSprite(key, sprite[key]);
109-
}
110-
// 添加地图图片资源
111-
const { images } = this._mapResourceInfo;
112-
const loadImagePromises = images.map(({ url, id }) => {
113-
return new Promise((resolve, reject) => {
114-
this.map.loadImage(url, (error, image) => {
115-
if (error) {
116-
reject(error);
117-
return;
118-
}
119-
!this.map.hasImage(id) && this.map.addImage(id, image, { sdf: true });
120-
resolve(url);
121-
});
122-
});
123-
});
124-
return Promise.all(loadImagePromises)
125-
.then((imagesAddToMap) => {
126-
this.fire('getlayerresourcesucceeded', { images: imagesAddToMap });
127-
return imagesAddToMap;
128-
})
129-
.catch((error) => {
130-
this.fire('getlayerresourcefailed', { error });
131-
});
105+
// if (typeof sprite === 'object') {
106+
// for (let key in sprite) {
107+
// this.map.style.addSprite(key, sprite[key]);
108+
// }
109+
// } else {
110+
// this.map.style.sprite = sprite;
111+
// this.map.setStyle(this.map.style);
112+
// }
132113
}
133114

134115
/**

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