Skip to content

Commit

Permalink
Add example of binded source
Browse files Browse the repository at this point in the history
  • Loading branch information
ger-benjamin committed Feb 3, 2023
1 parent c846104 commit 33a5df3
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
1 change: 1 addition & 0 deletions examples/demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
</head>
<body>
<div class="map" id="map"></div>
<p>Demo bind source calls: <button onclick="refreshSource()">Refresh source</button></p>
<script src="./demo.js"></script>
</body>
</html>
28 changes: 17 additions & 11 deletions examples/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,21 @@ import {TileDebug} from 'ol/source';

import MapLibreLayer from '../src/MapLibreLayer';

const mapLibreLayer = new MapLibreLayer({
maplibreOptions: {
style:
'https://vectortiles.geo.admin.ch/styles/ch.swisstopo.leichte-basiskarte_world.vt/style.json',
},
source: new Source({
attributions: [
'<a href="https://www.geo.admin.ch/en/geo-services/geo-services/portrayal-services-web-mapping/vector_tiles_service.html" target="_blank">© swisstopo</a>',
],
}),
});

window.map = new Map({
layers: [
new MapLibreLayer({
maplibreOptions: {
style:
'https://vectortiles.geo.admin.ch/styles/ch.swisstopo.leichte-basiskarte_world.vt/style.json',
},
source: new Source({
attributions: [
'<a href="https://www.geo.admin.ch/en/geo-services/geo-services/portrayal-services-web-mapping/vector_tiles_service.html" target="_blank">© swisstopo</a>',
],
}),
}),
mapLibreLayer,
new TileLayer({
source: new TileDebug(),
}),
Expand All @@ -32,3 +34,7 @@ window.map = new Map({
zoom: 8,
}),
});

window.refreshSource = () => {
mapLibreLayer.getSource().refresh();
};
2 changes: 1 addition & 1 deletion examples/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ body,
margin: 0;
padding: 0;
width: 100%;
height: 100%;
height: 90%;
}
2 changes: 1 addition & 1 deletion src/MapLibreSource.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Source from "ol/source/Source";
import Source from 'ol/source/Source';

export default class MapLibreSource extends Source {
constructor(options) {
Expand Down

0 comments on commit 33a5df3

Please sign in to comment.