Skip to content

Instantly share code, notes, and snippets.

@oscarlorentzon
Last active January 20, 2021 08:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oscarlorentzon/6f0d316fee85320c552a4ed6838566a2 to your computer and use it in GitHub Desktop.
Save oscarlorentzon/6f0d316fee85320c552a4ed6838566a2 to your computer and use it in GitHub Desktop.
MapillaryJS + Leaflet Tangram
<!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.3/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.3/dist/leaflet.js'></script>
<script src='https://mapzen.com/tangram/0.10/tangram.min.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);
map.options.maxZoom = 16;
var tangram = Tangram.leafletLayer({
scene: 'scene.yaml',
attribution: '<a href="https://mapzen.com/tangram" target="_blank">Tangram</a> | ' +
'&copy; OSM contributors | ' +
'<a href="https://mapzen.com/" target="_blank">Mapzen</a>',
});
tangram.addTo(map);
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>
cameras:
camera1:
type: perspective
lights:
light1:
type: directional
direction: [0, 1, -.5]
diffuse: .3
ambient: 1
sources:
osm:
type: TopoJSON
url: //tile.mapzen.com/mapzen/vector/v1/all/{z}/{x}/{y}.topojson
url_params:
api_key: mapzen-YcDJx8R
max_zoom: 16
layers:
earth:
data: { source: osm }
draw:
polygons:
order: 0
color: '#ddeeee'
landuse:
data: { source: osm }
draw:
polygons:
order: 1
color: '#aaffaa'
water:
data: { source: osm }
draw:
polygons:
order: 2
color: '#88bbee'
roads:
data: { source: osm }
filter:
not: { kind: ["path", "rail"] }
draw:
lines:
order: 4
color: gray
width: 8
cap: round
highway:
filter:
kind: highway
draw:
lines:
order: 5
color: '#cc6666'
width: 12
outline:
color: grey
width: 1.5
minor_road:
filter:
kind: minor_road
draw:
lines:
order: 3
color: lightgrey
width: 5
buildings:
data: { source: osm }
draw:
polygons:
order: 6
color: |
function () {
var h = feature.height || 20;
h = Math.min((h + 50)/ 255, .8); // max brightness: .8
h = Math.max(h, .4); // min brightness: .4
return [h, h, h];
}
3d-buildings:
filter: { $zoom: { min: 15 } }
draw:
polygons:
extrude: function () { return feature.height > 20 || $zoom >= 16; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment