Last active
January 21, 2019 05:39
-
-
Save androidfanatic/fa183617f453926acfc6d1bdad0dd6cd to your computer and use it in GitHub Desktop.
Pune Tree Map
This file contains hidden or 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>Pune Tree Map</title> | |
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' /> | |
<script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.52.0/mapbox-gl.js'></script> | |
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.52.0/mapbox-gl.css' rel='stylesheet' /> | |
<style> | |
body { | |
margin: 0; | |
padding: 0; | |
} | |
#map { | |
position: absolute; | |
top: 0; | |
bottom: 0; | |
width: 100%; | |
} | |
</style> | |
</head> | |
<body> | |
<div id='map'></div> | |
<script> | |
const base = 'http://13.126.70.198'; | |
mapboxgl.accessToken = 'pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4M29iazA2Z2gycXA4N2pmbDZmangifQ.-g_vE53SD2WrJ6tFX7QHmA'; | |
const map = new mapboxgl.Map({ | |
container: 'map', | |
style: 'mapbox://styles/mapbox/dark-v9', | |
zoom: 20, | |
maxZoom: 20, | |
center: [73.8567, 18.5204] | |
}); | |
const popup = new mapboxgl.Popup(); | |
map.on('load', function () { | |
map.addControl(new mapboxgl.FullscreenControl()); | |
map.addLayer({ | |
id: "trees", | |
"source-layer": "trees", | |
source: { | |
type: "vector", | |
tiles: [ | |
`${base}/trees/{z}/{x}/{y}.pbf` | |
], | |
}, | |
minzoom: 0, | |
maxzoom: 17, | |
buffer: 0, | |
type: 'circle', | |
paint: { | |
'circle-radius': 2, | |
'circle-color': '#0f0', | |
} | |
}); | |
map.addLayer({ | |
id: "trees_details", | |
"source-layer": "trees_details", | |
source: { | |
type: "vector", | |
tiles: [ | |
`${base}/trees_details/{z}/{x}/{y}.pbf` | |
], | |
}, | |
minzoom: 17, | |
buffer: 0, | |
type: 'circle', | |
paint: { | |
'circle-radius': ['max', 3, ['get', 'canopy']], | |
'circle-color': '#0f0', | |
} | |
}); | |
map.on('mousemove', (evt) => { | |
const features = map.queryRenderedFeatures(evt.point); | |
if (features && features.length > 0 | |
&& features[0].hasOwnProperty('properties') && features[0].properties.hasOwnProperty('canopy')) { | |
popup.setLngLat(evt.lngLat) | |
.setHTML('<pre>' + JSON.stringify(features[0].properties, null, 4) + '</pre>') | |
.addTo(map); | |
} else { | |
popup.remove(); | |
} | |
}); | |
}); | |
map.addControl(new mapboxgl.NavigationControl()); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment