Skip to content

Commit

Permalink
Restore initial index.html and main.js
Browse files Browse the repository at this point in the history
  • Loading branch information
ahocevar committed Dec 5, 2024
1 parent 98208e0 commit 314d29a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 79 deletions.
14 changes: 1 addition & 13 deletions src/en/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,8 @@
<head>
<meta charset="utf-8">
<title>OpenLayers</title>
<style>
@import "node_modules/ol/ol.css";
</style>
<style>
html, body, #map-container {
margin: 0;
height: 300px;
width: 500px;
font-family: sans-serif;
}
</style>
</head>
<body>
<div id="map-container"></div>
<script src="./main.js" type="module"></script>
</body>
</html>
</html>
67 changes: 1 addition & 66 deletions src/en/main.js
Original file line number Diff line number Diff line change
@@ -1,66 +1 @@
import {Map, View} from 'ol';
import {MapboxVectorLayer} from 'ol-mapbox-style';
import {fromLonLat} from 'ol/proj';
//! [import-layer]
import VectorLayer from 'ol/layer/Vector';
import VectorSource from 'ol/source/Vector';
//! [import-layer]
//! [import-interaction]
import Feature from 'ol/Feature';
import Point from 'ol/geom/Point';
//! [import-interaction]

const map = new Map({
target: 'map-container',
view: new View({
center: fromLonLat([0, 0]),
zoom: 2,
}),
});

const layer = new MapboxVectorLayer({
styleUrl: 'https://tiles.openfreemap.org/styles/bright',
// or, instead of the above, try
// styleUrl: 'mapbox://styles/mapbox/bright-v9',
// accessToken: 'Your token from https://mapbox.com/'
});
map.addLayer(layer);

//! [layer]
const source = new VectorSource();
const info = new VectorLayer({
source: source,
style: {
'stroke-color': 'red',
'stroke-width': 4,
//! [coalesce]
'text-value': ['coalesce', ['get', 'layers'], ''],
//! [coalesce]
'text-padding': [2, 2, 2, 2],
'text-offset-y': -15,
'text-font': '16px sans-serif',
'text-background-fill-color': 'gray',
},
});
map.addLayer(info);
//! [layer]
//! [interaction]
map.on('pointermove', function (event) {
source.clear();
//! [get-features]
const features = map.getFeaturesAtPixel(event.pixel, {
layerFilter: (layer) => layer !== info,
});
//! [get-features]
source.addFeatures(features);
//! [layers-label]
const layers = features.map((feature) => feature.get('layer'));
source.addFeature(
new Feature({
geometry: new Point(event.coordinate),
layers: Array.from(new Set(layers)).join(', '),
})
);
//! [layers-label]
});
//! [interaction]
alert('Hello Workshop');

0 comments on commit 314d29a

Please sign in to comment.