Skip to content

Commit 2b2e163

Browse files
committed
Update ol to 8.2
1 parent b8ead84 commit 2b2e163

File tree

6 files changed

+243
-159
lines changed

6 files changed

+243
-159
lines changed

README.md

Lines changed: 53 additions & 53 deletions
Large diffs are not rendered by default.

package-lock.json

Lines changed: 90 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/apply.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@ function setupGeoJSONSource(glSource, styleUrl, options) {
819819
)
820820
);
821821
source.set('mapbox-source', glSource);
822-
return source;
822+
return /** @type {VectorSource} */ (source);
823823
}
824824

825825
function setupGeoJSONLayer(glSource, styleUrl, options) {

src/stylefunction.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -798,8 +798,9 @@ export function stylefunction(
798798
'Point',
799799
renderFeatureCoordinates,
800800
[],
801+
2,
801802
{},
802-
null
803+
undefined
803804
);
804805
}
805806
styleGeom = renderFeature;

test/apply.test.js

Lines changed: 82 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -211,42 +211,90 @@ describe('ol-mapbox-style', function () {
211211
.catch(done);
212212
});
213213

214-
it('handles geojson wfs sources with bbox loadingstrategy and custom projection', function (done) {
215-
fetch('./fixtures/geojson-wfs.json')
216-
.then(function (response) {
217-
return response.json();
214+
describe('geojson', function () {
215+
let originalFetch;
216+
const requests = [];
217+
beforeEach(function () {
218+
originalFetch = fetch;
219+
window.fetch = (request) => {
220+
requests.push(request);
221+
return originalFetch(request);
222+
};
223+
});
224+
afterEach(function () {
225+
window.fetch = originalFetch;
226+
requests.length = 0;
227+
});
228+
it('handles geojson wfs sources with bbox loadingstrategy and custom projection', function (done) {
229+
fetch('./fixtures/geojson-wfs.json')
230+
.then(function (response) {
231+
return response.json();
232+
})
233+
.then(function (style) {
234+
style.sources.water_areas.data =
235+
style.sources.water_areas.data.replace('3857', '4326');
236+
apply(target, style, {projection: 'EPSG:4326'})
237+
.then(function (map) {
238+
const layer = map
239+
.getAllLayers()
240+
.find((x) => x.get('mapbox-source') === 'water_areas');
241+
const source = layer.getSource();
242+
source.once('change', () => {
243+
try {
244+
const url = new URL(requests[requests.length - 1].url);
245+
const bbox = url.searchParams.get('bbox');
246+
const extent = map.getView().calculateExtent();
247+
should(bbox).be.equal(extent.join(','));
248+
done();
249+
} catch (e) {
250+
done(e);
251+
}
252+
});
253+
source.loadFeatures(
254+
map.getView().calculateExtent(),
255+
1,
256+
map.getView().getProjection()
257+
);
258+
})
259+
.catch(done);
260+
});
261+
});
262+
263+
it('handles geojson wfs sources with bbox loadingstrategy & transformRequest', function (done) {
264+
apply(target, './fixtures/geojson-wfs.json', {
265+
transformRequest: (urlStr, type) => {
266+
if (type === 'GeoJSON') {
267+
const url = new URL(urlStr + '&transformRequest=true');
268+
return new Request(url);
269+
}
270+
},
218271
})
219-
.then(function (style) {
220-
style.sources.water_areas.data =
221-
style.sources.water_areas.data.replace('3857', '4326');
222-
apply(target, style, {projection: 'EPSG:4326'})
223-
.then(function (map) {
224-
const layer = map
225-
.getAllLayers()
226-
.find((x) => x.get('mapbox-source') === 'water_areas');
227-
const source = layer.getSource();
228-
const originalFetch = fetch;
229-
const requests = [];
230-
fetch = (request) => {
231-
requests.push(request);
232-
return originalFetch(request);
233-
};
234-
source.loadFeatures(
235-
map.getView().calculateExtent(),
236-
1,
237-
map.getView().getProjection()
238-
);
239-
source.once('change', () => {
240-
window.fetch = originalFetch;
241-
const url = new URL(requests[0].url);
242-
const bbox = url.searchParams.get('bbox');
243-
const extent = map.getView().calculateExtent();
244-
should(bbox).be.equal(extent.join(','));
272+
.then(function (map) {
273+
const layer = map
274+
.getAllLayers()
275+
.find((x) => x.get('mapbox-source') === 'water_areas');
276+
const source = layer.getSource();
277+
source.loadFeatures(
278+
map.getView().calculateExtent(),
279+
1,
280+
get('EPSG:3857')
281+
);
282+
source.once('change', () => {
283+
try {
284+
const url = new URL(requests[requests.length - 1].url);
285+
should(url.searchParams.get('transformRequest')).be.equal(
286+
'true'
287+
);
288+
should(source).be.instanceof(VectorSource);
289+
should(layer.getStyle()).be.a.Function();
245290
done();
246-
});
247-
})
248-
.catch(done);
249-
});
291+
} catch (e) {
292+
done(e);
293+
}
294+
});
295+
})
296+
.catch(done);
297+
});
250298
});
251299

252300
it('sets the correct GeoJON data projection for custom projections', function (done) {
@@ -317,43 +365,6 @@ describe('ol-mapbox-style', function () {
317365
});
318366
});
319367

320-
it('handles geojson wfs sources with bbox loadingstrategy & transformRequest', function (done) {
321-
apply(target, './fixtures/geojson-wfs.json', {
322-
transformRequest: (urlStr, type) => {
323-
if (type === 'GeoJSON') {
324-
const url = new URL(urlStr + '&transformRequest=true');
325-
return new Request(url);
326-
}
327-
},
328-
})
329-
.then(function (map) {
330-
const layer = map
331-
.getAllLayers()
332-
.find((x) => x.get('mapbox-source') === 'water_areas');
333-
const source = layer.getSource();
334-
const originalFetch = fetch;
335-
const requests = [];
336-
fetch = (request) => {
337-
requests.push(request);
338-
return originalFetch(request);
339-
};
340-
source.loadFeatures(
341-
map.getView().calculateExtent(),
342-
1,
343-
get('EPSG:3857')
344-
);
345-
source.once('change', () => {
346-
window.fetch = originalFetch;
347-
const url = new URL(requests[0].url);
348-
should(url.searchParams.get('transformRequest')).be.equal('true');
349-
should(source).be.instanceof(VectorSource);
350-
should(layer.getStyle()).be.a.Function();
351-
done();
352-
});
353-
})
354-
.catch(done);
355-
});
356-
357368
it('handles geojson sources with inline GeoJSON', function (done) {
358369
const map = new Map({target: target});
359370
map.getLayers().once('add', function (e) {

0 commit comments

Comments
 (0)