Last active
March 19, 2018 05:55
-
-
Save Jn1532/5844d9f8a47c8b0d6cf083efe3e614e7 to your computer and use it in GitHub Desktop.
Mapbox ethnicity map example
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
license: gpl-3.0 | |
height: 500 | |
scrolling: no | |
border: no |
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' /> | |
<script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.26.0/mapbox-gl.js'></script> | |
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.26.0/mapbox-gl.css' rel='stylesheet' /> | |
<style id="jsbin-css"> | |
body { margin:0; padding:0; } | |
#map { position:absolute; top:0; bottom:0; width:100%; } | |
</style> | |
</head> | |
<body> | |
<div id='map'></div> | |
<script id="jsbin-javascript"> | |
mapboxgl.accessToken = 'pk.eyJ1Ijoiam4xNTMyIiwiYSI6ImNpbnBoczBzejEwMXZ1Mm0zbWowdGxtOHgifQ.OioFRlO4Ou3Og3sMBxmfbA'; | |
var map = new mapboxgl.Map({ | |
container: 'map', | |
style: 'mapbox://styles/mapbox/light-v9', | |
zoom: 12, | |
center: [-122.447303, 37.753574] | |
}); | |
map.on('load', function () { | |
map.addSource('population', { | |
type: 'vector', | |
url: 'mapbox://examples.8fgz4egr' | |
}); | |
map.addLayer({ | |
'id': 'population', | |
'type': 'circle', | |
'source': 'population', | |
'source-layer': 'sf2010', | |
'paint': { | |
// make circles larger as the user zooms from z12 to z22 | |
'circle-radius': { | |
'base': 1.75, | |
'stops': [[12, 2], [22, 180]] | |
}, | |
// color circles by ethnicity, using data-driven styles | |
'circle-color': { | |
property: 'ethnicity', | |
type: 'categorical', | |
stops: [ | |
['White', '#fbb03b'], | |
['Black', '#223b53'], | |
['Hispanic', '#e55e5e'], | |
['Asian', '#3bb2d0'], | |
['Other', '#ccc']] | |
} | |
/* | |
'fill-color':{ property: 'ethnicity' , | |
stops: [ | |
['White', '#fbb03b'], | |
['Black', '#223b53'], | |
['Hispanic', '#e55e5e'], | |
['Asian', '#3bb2d0'], | |
['Other', '#ccc'] | |
] | |
} | |
*/ | |
} | |
}); | |
//////////////////////////////////////////////////////////////// | |
map.on('mousemove', function(e) { | |
var features = map.queryRenderedFeatures(e.point, { | |
// layers: [ 'layer-1' ,'layer-2','layer-3','layer-4','layer-0'] | |
}); | |
console.clear(); | |
// var feature = features[0]; | |
var obj = features[0].properties | |
for(var name in obj) { | |
if (obj !== "undefined") | |
{ | |
// console.log(name); | |
var value = obj[name]; | |
console.log(name + " " + value); | |
} | |
} | |
}) ; | |
//////////////////////////////////////////////////////////////// | |
}); | |
</script> | |
<script id="jsbin-source-html" type="text/html"><!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset='utf-8' /> | |
<title></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.26.0/mapbox-gl.js'><\/script> | |
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.26.0/mapbox-gl.css' rel='stylesheet' /> | |
</head> | |
<body> | |
<div id='map'></div> | |
</body> | |
</html> | |
</script> | |
<script id="jsbin-source-css" type="text/css"> body { margin:0; padding:0; } | |
#map { position:absolute; top:0; bottom:0; width:100%; }</script> | |
<script id="jsbin-source-javascript" type="text/javascript">mapboxgl.accessToken = 'pk.eyJ1Ijoiam4xNTMyIiwiYSI6ImNpbnBoczBzejEwMXZ1Mm0zbWowdGxtOHgifQ.OioFRlO4Ou3Og3sMBxmfbA'; | |
var map = new mapboxgl.Map({ | |
container: 'map', | |
style: 'mapbox://styles/mapbox/light-v9', | |
zoom: 12, | |
center: [-122.447303, 37.753574] | |
}); | |
map.on('load', function () { | |
map.addSource('population', { | |
type: 'vector', | |
url: 'mapbox://examples.8fgz4egr' | |
}); | |
map.addLayer({ | |
'id': 'population', | |
'type': 'circle', | |
'source': 'population', | |
'source-layer': 'sf2010', | |
'paint': { | |
// make circles larger as the user zooms from z12 to z22 | |
'circle-radius': { | |
'base': 1.75, | |
'stops': [[12, 2], [22, 180]] | |
}, | |
// color circles by ethnicity, using data-driven styles | |
'circle-color': { | |
property: 'ethnicity', | |
type: 'categorical', | |
stops: [ | |
['White', '#fbb03b'], | |
['Black', '#223b53'], | |
['Hispanic', '#e55e5e'], | |
['Asian', '#3bb2d0'], | |
['Other', '#ccc']] | |
} | |
/* | |
'fill-color':{ property: 'ethnicity' , | |
stops: [ | |
['White', '#fbb03b'], | |
['Black', '#223b53'], | |
['Hispanic', '#e55e5e'], | |
['Asian', '#3bb2d0'], | |
['Other', '#ccc'] | |
] | |
} | |
*/ | |
} | |
}); | |
//////////////////////////////////////////////////////////////// | |
map.on('mousemove', function(e) { | |
var features = map.queryRenderedFeatures(e.point, { | |
// layers: [ 'layer-1' ,'layer-2','layer-3','layer-4','layer-0'] | |
}); | |
console.clear(); | |
// var feature = features[0]; | |
var obj = features[0].properties | |
for(var name in obj) { | |
if (obj !== "undefined") | |
{ | |
// console.log(name); | |
var value = obj[name]; | |
console.log(name + " " + value); | |
} | |
} | |
}) ; | |
//////////////////////////////////////////////////////////////// | |
});</script></body> | |
</html> |
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
body { margin:0; padding:0; } | |
#map { position:absolute; top:0; bottom:0; width:100%; } |
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
mapboxgl.accessToken = 'pk.eyJ1Ijoiam4xNTMyIiwiYSI6ImNpbnBoczBzejEwMXZ1Mm0zbWowdGxtOHgifQ.OioFRlO4Ou3Og3sMBxmfbA'; | |
var map = new mapboxgl.Map({ | |
container: 'map', | |
style: 'mapbox://styles/mapbox/light-v9', | |
zoom: 12, | |
center: [-122.447303, 37.753574] | |
}); | |
map.on('load', function () { | |
map.addSource('population', { | |
type: 'vector', | |
url: 'mapbox://examples.8fgz4egr' | |
}); | |
map.addLayer({ | |
'id': 'population', | |
'type': 'circle', | |
'source': 'population', | |
'source-layer': 'sf2010', | |
'paint': { | |
// make circles larger as the user zooms from z12 to z22 | |
'circle-radius': { | |
'base': 1.75, | |
'stops': [[12, 2], [22, 180]] | |
}, | |
// color circles by ethnicity, using data-driven styles | |
'circle-color': { | |
property: 'ethnicity', | |
type: 'categorical', | |
stops: [ | |
['White', '#fbb03b'], | |
['Black', '#223b53'], | |
['Hispanic', '#e55e5e'], | |
['Asian', '#3bb2d0'], | |
['Other', '#ccc']] | |
} | |
/* | |
'fill-color':{ property: 'ethnicity' , | |
stops: [ | |
['White', '#fbb03b'], | |
['Black', '#223b53'], | |
['Hispanic', '#e55e5e'], | |
['Asian', '#3bb2d0'], | |
['Other', '#ccc'] | |
] | |
} | |
*/ | |
} | |
}); | |
//////////////////////////////////////////////////////////////// | |
map.on('mousemove', function(e) { | |
var features = map.queryRenderedFeatures(e.point, { | |
// layers: [ 'layer-1' ,'layer-2','layer-3','layer-4','layer-0'] | |
}); | |
console.clear(); | |
// var feature = features[0]; | |
var obj = features[0].properties | |
for(var name in obj) { | |
if (obj !== "undefined") | |
{ | |
// console.log(name); | |
var value = obj[name]; | |
console.log(name + " " + value); | |
} | |
} | |
}) ; | |
////////////////////////////////////////////////////////////////// source http://jsbin.com/coduhoh | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment