Improve icon-sprite-webgl example to include hit detection
This commit is contained in:
@@ -18,3 +18,4 @@ cloak:
|
||||
value: Your Mapbox access token from https://mapbox.com/ here
|
||||
---
|
||||
<div id="map" class="map"></div>
|
||||
<div>Current sighting: <span id="info"></span></div>
|
||||
|
||||
@@ -103,7 +103,7 @@ function loadData() {
|
||||
|
||||
loadData();
|
||||
|
||||
new Map({
|
||||
const map = new Map({
|
||||
layers: [
|
||||
new TileLayer({
|
||||
source: new TileJSON({
|
||||
@@ -121,3 +121,18 @@ new Map({
|
||||
zoom: 2
|
||||
})
|
||||
});
|
||||
|
||||
const info = document.getElementById('info');
|
||||
map.on('pointermove', function(evt) {
|
||||
if (map.getView().getInteracting()) {
|
||||
return;
|
||||
}
|
||||
const pixel = evt.pixel;
|
||||
info.innerText = '';
|
||||
map.forEachFeatureAtPixel(pixel, function(feature) {
|
||||
const datetime = feature.get('datetime');
|
||||
const duration = feature.get('duration');
|
||||
const shape = feature.get('shape');
|
||||
info.innerText = 'On ' + datetime + ', lasted ' + duration + ' seconds and had a "' + shape + '" shape.';
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user