-
-
Notifications
You must be signed in to change notification settings - Fork 783
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[example] Animate symbol to follow mouse (#4945)
* [example] Animate symbol to follow mouse * cleanup * add @see to mousemove * add control
- Loading branch information
Showing
3 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<title>Animate symbol to follow the mouse</title> | ||
<meta property="og:description" content="Animate symbol to follow the mouse." /> | ||
<meta charset='utf-8'> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<link rel='stylesheet' href='../../dist/maplibre-gl.css' /> | ||
<script src='../../dist/maplibre-gl-dev.js'></script> | ||
<style> | ||
body { | ||
margin: 0; | ||
padding: 0; | ||
} | ||
|
||
html, | ||
body, | ||
#map { | ||
height: 100%; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<div id="map"></div> | ||
<script> | ||
const map = new maplibregl.Map({ | ||
container: 'map', | ||
projection: {type: 'globe'}, | ||
style: | ||
'https://api.maptiler.com/maps/streets/style.json?key=get_your_own_OpIi9ZULNHzrESv6T2vL', | ||
center: [0, 0], | ||
zoom: 2 | ||
}); | ||
|
||
map.on('mousemove', (e) => { | ||
const lngLat = e.lngLat.wrap(); | ||
const pointSource = map.getSource('point'); | ||
|
||
if (pointSource && lngLat.lng && lngLat.lat) { | ||
pointSource.setData({ | ||
'type': 'Point', | ||
'coordinates': [lngLat.lng, lngLat.lat] | ||
}); | ||
} | ||
}); | ||
map.addControl(new maplibregl.GlobeControl()); | ||
|
||
map.on('load', () => { | ||
|
||
map.addSource('point', { | ||
'type': 'geojson', | ||
'data': { | ||
'type': 'Point', | ||
'coordinates': [0, 0] | ||
} | ||
}); | ||
|
||
map.addLayer({ | ||
'id': 'point', | ||
'source': 'point', | ||
'type': 'symbol', | ||
'layout': { | ||
'icon-image': 'airport_15', | ||
'icon-allow-overlap': true, | ||
'icon-ignore-placement': true | ||
}, | ||
}); | ||
}); | ||
</script> | ||
</body> | ||
|
||
</html> |