Skip to content

Commit 1c637b4

Browse files
songyumengluoxiao-supermap
authored andcommitted
Update GraphicSpec.js
1 parent 34b1d68 commit 1c637b4

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

test/openlayers/overlay/GraphicSpec.js

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import Stroke from 'ol/style/Stroke';
2424
import Point from 'ol/geom/Point';
2525
import ImageLayer from 'ol/layer/Image';
2626
import RegularShape from 'ol/style/RegularShape';
27+
import { unByKey } from 'ol/Observable';
2728

2829

2930
var url = "http://supermapiserver:8090/iserver/services/map-china400/rest/maps/China_4326";
@@ -272,23 +273,25 @@ describe('openlayers_GraphicLayer', () => {
272273
})
273274
});
274275
map.addLayer(graphicLayer);
275-
276-
setTimeout(() => {
277-
const graphicSource = graphicLayer.getSource();
278-
graphicSource.addGraphics(graphics);
279-
expect(graphicSource.graphics.length).toEqual(10);
280-
graphicLayer.getSource()._forEachFeatureAtCoordinate([-35.16, 38.05], 1, (result) => {
281-
expect(result).not.toBeNull();
282-
});
283-
284-
let pixel = map.getPixelFromCoordinate([-35.16, 38.05]);
285-
map.forEachFeatureAtPixel(pixel,
286-
(graphic, layer) => {
287-
expect(graphic).toBe(graphics[0]);
288-
expect(layer).toBe(graphicLayer);
289-
});
290-
done();
291-
}, 0);
276+
const key = graphicLayer.on('postrender', function() {
277+
if (graphicLayer.getSource().renderer) {
278+
unByKey(key);
279+
const graphicSource = graphicLayer.getSource();
280+
graphicSource.addGraphics(graphics);
281+
expect(graphicSource.graphics.length).toEqual(10);
282+
graphicLayer.getSource()._forEachFeatureAtCoordinate([-35.16, 38.05], 1, (result) => {
283+
expect(result).not.toBeNull();
284+
});
285+
286+
let pixel = map.getPixelFromCoordinate([-35.16, 38.05]);
287+
map.forEachFeatureAtPixel(pixel,
288+
(graphic, layer) => {
289+
expect(graphic).toBe(graphics[0]);
290+
expect(layer).toBe(graphicLayer);
291+
});
292+
done();
293+
}
294+
});
292295
});
293296

294297
it("getGraphicBy add getGraphicById", (done) => {
@@ -632,4 +635,4 @@ describe('openlayers_GraphicLayer', () => {
632635
done();
633636
}, 0);
634637
});
635-
});
638+
});

0 commit comments

Comments
 (0)