Skip to content

Commit

Permalink
Update ol to 8.2
Browse files Browse the repository at this point in the history
  • Loading branch information
ahocevar committed Dec 12, 2023
1 parent b8ead84 commit 2b2e163
Show file tree
Hide file tree
Showing 6 changed files with 243 additions and 159 deletions.
106 changes: 53 additions & 53 deletions README.md

Large diffs are not rendered by default.

114 changes: 90 additions & 24 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/apply.js
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ function setupGeoJSONSource(glSource, styleUrl, options) {
)
);
source.set('mapbox-source', glSource);
return source;
return /** @type {VectorSource} */ (source);
}

function setupGeoJSONLayer(glSource, styleUrl, options) {
Expand Down
3 changes: 2 additions & 1 deletion src/stylefunction.js
Original file line number Diff line number Diff line change
Expand Up @@ -798,8 +798,9 @@ export function stylefunction(
'Point',
renderFeatureCoordinates,
[],
2,
{},
null
undefined
);
}
styleGeom = renderFeature;
Expand Down
153 changes: 82 additions & 71 deletions test/apply.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,42 +211,90 @@ describe('ol-mapbox-style', function () {
.catch(done);
});

it('handles geojson wfs sources with bbox loadingstrategy and custom projection', function (done) {
fetch('./fixtures/geojson-wfs.json')
.then(function (response) {
return response.json();
describe('geojson', function () {
let originalFetch;
const requests = [];
beforeEach(function () {
originalFetch = fetch;
window.fetch = (request) => {
requests.push(request);
return originalFetch(request);
};
});
afterEach(function () {
window.fetch = originalFetch;
requests.length = 0;
});
it('handles geojson wfs sources with bbox loadingstrategy and custom projection', function (done) {
fetch('./fixtures/geojson-wfs.json')
.then(function (response) {
return response.json();
})
.then(function (style) {
style.sources.water_areas.data =
style.sources.water_areas.data.replace('3857', '4326');
apply(target, style, {projection: 'EPSG:4326'})
.then(function (map) {
const layer = map
.getAllLayers()
.find((x) => x.get('mapbox-source') === 'water_areas');
const source = layer.getSource();
source.once('change', () => {
try {
const url = new URL(requests[requests.length - 1].url);
const bbox = url.searchParams.get('bbox');
const extent = map.getView().calculateExtent();
should(bbox).be.equal(extent.join(','));
done();
} catch (e) {
done(e);
}
});
source.loadFeatures(
map.getView().calculateExtent(),
1,
map.getView().getProjection()
);
})
.catch(done);
});
});

it('handles geojson wfs sources with bbox loadingstrategy & transformRequest', function (done) {
apply(target, './fixtures/geojson-wfs.json', {
transformRequest: (urlStr, type) => {
if (type === 'GeoJSON') {
const url = new URL(urlStr + '&transformRequest=true');
return new Request(url);
}
},
})
.then(function (style) {
style.sources.water_areas.data =
style.sources.water_areas.data.replace('3857', '4326');
apply(target, style, {projection: 'EPSG:4326'})
.then(function (map) {
const layer = map
.getAllLayers()
.find((x) => x.get('mapbox-source') === 'water_areas');
const source = layer.getSource();
const originalFetch = fetch;
const requests = [];
fetch = (request) => {
requests.push(request);
return originalFetch(request);
};
source.loadFeatures(
map.getView().calculateExtent(),
1,
map.getView().getProjection()
);
source.once('change', () => {
window.fetch = originalFetch;
const url = new URL(requests[0].url);
const bbox = url.searchParams.get('bbox');
const extent = map.getView().calculateExtent();
should(bbox).be.equal(extent.join(','));
.then(function (map) {
const layer = map
.getAllLayers()
.find((x) => x.get('mapbox-source') === 'water_areas');
const source = layer.getSource();
source.loadFeatures(
map.getView().calculateExtent(),
1,
get('EPSG:3857')
);
source.once('change', () => {
try {
const url = new URL(requests[requests.length - 1].url);
should(url.searchParams.get('transformRequest')).be.equal(
'true'
);
should(source).be.instanceof(VectorSource);
should(layer.getStyle()).be.a.Function();
done();
});
})
.catch(done);
});
} catch (e) {
done(e);
}
});
})
.catch(done);
});
});

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

it('handles geojson wfs sources with bbox loadingstrategy & transformRequest', function (done) {
apply(target, './fixtures/geojson-wfs.json', {
transformRequest: (urlStr, type) => {
if (type === 'GeoJSON') {
const url = new URL(urlStr + '&transformRequest=true');
return new Request(url);
}
},
})
.then(function (map) {
const layer = map
.getAllLayers()
.find((x) => x.get('mapbox-source') === 'water_areas');
const source = layer.getSource();
const originalFetch = fetch;
const requests = [];
fetch = (request) => {
requests.push(request);
return originalFetch(request);
};
source.loadFeatures(
map.getView().calculateExtent(),
1,
get('EPSG:3857')
);
source.once('change', () => {
window.fetch = originalFetch;
const url = new URL(requests[0].url);
should(url.searchParams.get('transformRequest')).be.equal('true');
should(source).be.instanceof(VectorSource);
should(layer.getStyle()).be.a.Function();
done();
});
})
.catch(done);
});

it('handles geojson sources with inline GeoJSON', function (done) {
const map = new Map({target: target});
map.getLayers().once('add', function (e) {
Expand Down
Loading

0 comments on commit 2b2e163

Please sign in to comment.