Skip to content

Commit

Permalink
Upgrade to openlayer 10.
Browse files Browse the repository at this point in the history
  • Loading branch information
francois2metz committed Aug 1, 2024
1 parent c477587 commit 767da39
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 16 deletions.
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
<meta charset="utf-8" />
<title>Map with indoor=</title>
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
<script src="https://cdn.jsdelivr.net/npm/ol@v9.1.0/dist/ol.js"></script>
<script src="https://cdn.jsdelivr.net/npm/ol@v10.0.0/dist/ol.js"></script>
<script src="./dist/openlayers-indoorequal.umd.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/ol@9.1.0/ol.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/ol@10.0.0/ol.css">
<link href="./openlayers-indoorequal.css" rel="stylesheet" />
<style>
body { margin: 0; padding: 0; }
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"transformIgnorePatterns": []
},
"peerDependencies": {
"ol": "< 11.0.0"
"ol": "^10.0.0"
},
"dependencies": {
"debounce": "^2.0.0"
Expand Down
5 changes: 3 additions & 2 deletions src/indoorequal.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export default class IndoorEqual extends BaseObject {
this.source = await loadSourceFromTileJSON(`${this.url}${urlParams}`);

this.indoorLayer.setSource(this.source);
this.heatmapLayer.setSource(createHeatmapSource(this.source));
this.heatmapLayer.setSource(createHeatmapSource(this.indoorLayer));
this._listenForLevels();
}

Expand All @@ -73,11 +73,12 @@ export default class IndoorEqual extends BaseObject {
}

_listenForLevels() {
const layer = this.indoorLayer;
const source = this.source;

const refreshLevels = debounce(() => {
const extent = this.map.getView().calculateExtent(this.map.getSize());
const features = source.getFeaturesInExtent(extent);
const features = layer.getFeaturesInExtent(extent);
this.set('levels', findAllLevels(features));
}, 1000);

Expand Down
8 changes: 4 additions & 4 deletions src/layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,17 @@ export function getLayer(options) {
});
}

export function createHeatmapSource(source) {
const tilegrid = source.getTileGrid();
export function createHeatmapSource(indoorLayer) {
const tilegrid = indoorLayer.getSource().getTileGrid();
const vectorSource = new VectorSource({
loader(extent, resolution, projection, success, failure) {
const refresh = () => {
const features = source.getFeaturesInExtent(extent);
const features = indoorLayer.getFeaturesInExtent(extent);
vectorSource.clear(true);
vectorSource.addFeatures(features);
success(features);
}
source.on('tileloadend', refresh);
indoorLayer.getSource().on('tileloadend', refresh);
refresh();
},
loadingstrategy: tile(tilegrid)
Expand Down
12 changes: 6 additions & 6 deletions test/indoorequal.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,19 @@ describe('IndoorEqual', () => {
};
const source = {
on: (_eventName, callback) => callback(),
}
const getLayerReturn = {
on: (_eventName, callback) => callback(),
setStyle: jest.fn(),
setSource: jest.fn(),
setVisible: jest.fn(),
getFeaturesInExtent: () => {
return [
new Feature({ layer: 'area', level: 0 }),
new Feature({ layer: 'area', level: 1 }),
new Feature({ layer: 'area', level: -2 }),
];
}
}
const getLayerReturn = {
on: (_eventName, callback) => callback(),
setStyle: jest.fn(),
setSource: jest.fn(),
setVisible: jest.fn(),
};
getLayer.mockReturnValueOnce(getLayerReturn);
getHeatmapLayer.mockReturnValueOnce(getLayerReturn);
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5744,7 +5744,7 @@ __metadata:
ol: "npm:^10.0.0"
rollup: "npm:^4.14.0"
peerDependencies:
ol: < 11.0.0
ol: ^10.0.0
languageName: unknown
linkType: soft

Expand Down

0 comments on commit 767da39

Please sign in to comment.