Last active
July 26, 2021 18:09
-
-
Save oscarlorentzon/0a11029a5627028c445a38016c76fb3a to your computer and use it in GitHub Desktop.
MapillaryJS + Leaflet
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
<!DOCTYPE HTML> | |
<html> | |
<head> | |
<meta charset='utf-8' /> | |
<title></title> | |
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' /> | |
<link href='https://unpkg.com/mapillary-js@3.1.0/dist/mapillary.min.css' rel='stylesheet' /> | |
<link href='https://unpkg.com/leaflet@1.0.1/dist/leaflet.css' rel='stylesheet' /> | |
<script src='https://unpkg.com/mapillary-js@3.1.0/dist/mapillary.min.js'></script> | |
<script src='https://unpkg.com/leaflet@1.0.1/dist/leaflet.js'></script> | |
<style> | |
body { margin:0; padding:0; height: 100%; } | |
#mly { position: absolute; height: 100%; width: 66%; } | |
#map { position: absolute; width: 34%; top: 0; right: 0; bottom: 0; } | |
</style> | |
</head> | |
<body> | |
<div id='mly'></div> | |
<div id='map'></div> | |
<script> | |
var map = L.map('map').setView([56.04351888068181, 12.695600612967427], 15); | |
var osmUrl='https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'; | |
var osmAttrib='Map data © <a href="https://openstreetmap.org">OpenStreetMap</a> contributors'; | |
var osm = new L.TileLayer(osmUrl, { maxZoom: 18, attribution: osmAttrib}); | |
map.addLayer(osm); | |
var mly = new Mapillary.Viewer({ | |
apiClient: 'QjI1NnU0aG5FZFZISE56U3R5aWN4Zzo3NTM1MjI5MmRjODZlMzc0', | |
container: 'mly', | |
imageKey: 'zarcRdNFZwg3FkXNcsFeGw', | |
}); | |
var marker; | |
mly.on(Mapillary.Viewer.nodechanged, function (node) { | |
var latLon = [node.latLon.lat, node.latLon.lon]; | |
if (!marker) { | |
marker = L.marker(latLon); | |
marker.addTo(map); | |
} else { | |
marker.setLatLng(latLon); | |
} | |
map.setView(latLon); | |
}); | |
window.addEventListener('resize', function() { mly.resize(); }); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
These MapillaryJS Gist resources are deprecated and not maintained anymore. Please see the examples section of the MapillaryJS v4.x documentation instead.