Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2da82c8

Browse files
[fix]l7mock
1 parent 80536ae commit 2da82c8

File tree

1 file changed

+36
-24
lines changed

1 file changed

+36
-24
lines changed

‎test/tool/mock_l7.js

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
class Event {
2+
constructor() {
3+
this.stacks = {};
4+
}
5+
6+
on(type, cb) {
7+
this.stacks[type] = this.stacks[type] || [];
8+
this.stacks[type].push(cb);
9+
}
10+
emit(type) {
11+
this.stacks[type]?.forEach((cb) => {
12+
cb();
13+
});
14+
}
15+
}
16+
const event = new Event();
117
class Scene {
218
constructor() {
319
this.layerService = {
@@ -6,12 +22,16 @@ class Scene {
622
startAnimate: () => true
723
};
824
this.callbacks = {};
25+
event.stacks = {};
926
}
1027
removeAllLayer() {}
1128
getLayer() {
1229
return true;
1330
}
1431
addLayer() {
32+
setTimeout(() => {
33+
event.emit('add');
34+
}, 100);
1535
return true;
1636
}
1737
removeLayer() {
@@ -49,10 +69,9 @@ class Layer {
4969
this.layerModel = {
5070
spriteAnimate: false
5171
};
52-
this.stacks = {};
5372
this.rawConfig = options;
5473
this.layerSource = {
55-
originData: {type: 'FeatureCollection', features: []},
74+
originData: {type: 'FeatureCollection', features: []},
5675
data: {
5776
dataArray: []
5877
}
@@ -69,7 +88,7 @@ class Layer {
6988
}
7089
const newFeature = {
7190
properties: {},
72-
geometry: { type: '', coordinates: [] },
91+
geometry: { type: '', coordinates: [] }
7392
};
7493
const coordinates = item.coordinates;
7594
delete item.coordinates;
@@ -81,12 +100,12 @@ class Layer {
81100
});
82101
return res;
83102
}
84-
}
103+
};
85104
}
86105
source(data, options = {}) {
87-
const parser = options.parser || { type: "geojson" };
106+
const parser = options.parser || { type: 'geojson' };
88107
let dataArray = [];
89-
if (parser.type === "geojson") {
108+
if (parser.type === 'geojson') {
90109
dataArray = data;
91110
}
92111
if (parser.type === 'json') {
@@ -105,18 +124,18 @@ class Layer {
105124
this.layerSource = {
106125
...options,
107126
parser,
108-
originData: data.features ? data : {type: 'FeatureCollection', features: data},
127+
originData: data.features ? data : {type: 'FeatureCollection', features: data},
109128
data: {
110-
dataArray: parser.type === "geojson" ? data : []
129+
dataArray: parser.type === 'geojson' ? data : []
111130
}
112131
};
113-
if (parser.type === "mvt") {
132+
if (parser.type === 'mvt') {
114133
this.layerSource.tileset = {
115-
cacheTiles: this.rawConfig.name.includes("empty")
134+
cacheTiles: this.rawConfig.name.includes('empty')
116135
? new Map()
117136
: new Map([
118137
[
119-
"0",
138+
'0',
120139
{
121140
data: {
122141
vectorLayerCache: {
@@ -155,7 +174,7 @@ class Layer {
155174
}
156175
shape(type) {
157176
this.shape = type;
158-
if (this.shape === "sprite") {
177+
if (this.shape === 'sprite') {
159178
this.layerModel = {
160179
spriteAnimate: true
161180
};
@@ -174,27 +193,20 @@ class Layer {
174193
return this;
175194
}
176195
getSource() {
177-
const sourceInfo = {
178-
on: (type, cb) => {
179-
this.stacks[type] = [cb];
180-
},
181-
emit: type => {
182-
this.stacks[type].forEach(cb => {
183-
cb();
184-
});
185-
}
186-
};
196+
const sourceInfo = event;
187197
sourceInfo._data = this.layerSource.originData;
188198
sourceInfo.getData = () => this.layerSource.originData;
189199
sourceInfo.setData = this.setData;
190200
return sourceInfo;
191201
}
192202
setData(data) {
193203
this.layerSource.originData = data;
194-
this.getSource().emit("update");
204+
this.getSource().emit('update');
195205
}
196206

197-
on() {}
207+
on(type, cb) {
208+
event.on(type, cb);
209+
}
198210

199211
once() {}
200212

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /