@ohuoy/easymap 1.1.12 → 1.1.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +53 -31
  2. package/package.json +2 -1
package/index.js CHANGED
@@ -127,7 +127,7 @@ export class EasyMap {
127
127
  })
128
128
  }
129
129
 
130
-
130
+ mapStyleTimer = null
131
131
  setMapStyle(style){
132
132
  let map = this.map;
133
133
  const layerIds = map.style.order
@@ -143,38 +143,60 @@ export class EasyMap {
143
143
  layers.push(layer)
144
144
  map.removeLayer(id)
145
145
  });
146
- const handleStyleLoad = () => {
147
- // Object.keys(sources).forEach(key => {
148
- // if (!map.getSource(key)) {
149
- // map.addSource(key, sources[key]);
150
- // }
151
- // }
152
- // );
153
-
154
- sources.forEach(source=>{
155
- if (!map.getSource(source.id)) {
156
- map.addSource(source.id,source._options);
157
- }
158
- })
159
- layers.forEach(layer=>{
160
- if (!map.getLayer(layer.id)) {
161
- map.addLayer(layer);
162
- }
163
- })
164
- if(layerIds.indexOf("tiandi") >= 0){
165
- map.theme.value ="light"
166
- }
167
- else if(layerIds.indexOf("yingxiang") >= 0){
168
- map.theme.value ="dark"
169
- }else{
170
- map.theme.value = map.style.stylesheet.theme
171
- }
146
+ // const handleStyleLoad = () => {
147
+ // console.log(222)
148
+ // sources.forEach(source=>{
149
+ // if (!map.getSource(source.id)) {
150
+ // map.addSource(source.id,source._options);
151
+ // }
152
+ // })
153
+ // layers.forEach(layer=>{
154
+ // if (!map.getLayer(layer.id)) {
155
+ // map.addLayer(layer);
156
+ // }
157
+ // })
158
+
159
+ // if(layerIds.indexOf("tiandi") >= 0){
160
+ // map.theme.value ="light"
161
+ // }
162
+ // else if(layerIds.indexOf("yingxiang") >= 0){
163
+ // map.theme.value ="dark"
164
+ // }else{
165
+ // map.theme.value = map.style.stylesheet.theme
166
+ // }
172
167
 
173
- map.off('style.load', handleStyleLoad);
174
- };
168
+ // map.off('style.load', handleStyleLoad);
169
+ // };
175
170
 
176
- map.on('style.load', handleStyleLoad);
177
- map.setStyle(style);
171
+ // this.map.on('style.load', handleStyleLoad);
172
+ this.map.on('styledata', ()=>{
173
+ if(this.mapStyleTimer){
174
+ clearTimeout(this.mapStyleTimer)
175
+ }
176
+ this.mapStyleTimer = setTimeout(() => {
177
+ sources.forEach(source=>{
178
+ if (!map.getSource(source.id)) {
179
+ map.addSource(source.id,source._options);
180
+ }
181
+ })
182
+ layers.forEach(layer=>{
183
+ if (!map.getLayer(layer.id)) {
184
+ map.addLayer(layer);
185
+ }
186
+ })
187
+
188
+ if(layerIds.indexOf("tiandi") >= 0){
189
+ map.theme.value ="light"
190
+ }
191
+ else if(layerIds.indexOf("yingxiang") >= 0){
192
+ map.theme.value ="dark"
193
+ }else{
194
+ map.theme.value = map.style.stylesheet.theme
195
+ }
196
+ this.mapStyleTimer = null
197
+ }, 1000);
198
+ });
199
+ this.map.setStyle(style);
178
200
  }
179
201
 
180
202
  async setStyle(url){
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ohuoy/easymap",
3
- "version": "1.1.12",
3
+ "version": "1.1.13",
4
4
  "description": "self map easy use",
5
5
  "main": "main.js",
6
6
  "scripts": {
@@ -45,3 +45,4 @@
45
45
  "webpack-cli": "^5.1.4"
46
46
  }
47
47
  }
48
+