Skip to content

Instantly share code, notes, and snippets.

@oscarlorentzon
Last active July 26, 2021 18:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save oscarlorentzon/0a11029a5627028c445a38016c76fb3a to your computer and use it in GitHub Desktop.
Save oscarlorentzon/0a11029a5627028c445a38016c76fb3a to your computer and use it in GitHub Desktop.
MapillaryJS + Leaflet
<!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>
@CarlosBrys
Copy link

This is an excellent resource.
Please could you update it to the new Mapillary API version 4?
There are more up-to-date resources to add:

 <script src = 'https: //unpkg.com/mapillary-js@4.0.0/dist/mapillary.min.js'> </script>
 <script src = 'https: //unpkg.com/leaflet@1.7.1/dist/leaflet.js'> </script>

@oscarlorentzon
Copy link
Author

These MapillaryJS Gist resources are deprecated and not maintained anymore. Please see the examples section of the MapillaryJS v4.x documentation instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment