Created
August 13, 2014 16:21
-
-
Save ajpierce/364cfafaae706b3c0ec0 to your computer and use it in GitHub Desktop.
Mapbox-GL Random Points
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.2.2/mapbox-gl.js'></script> | |
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.2.2/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> | |
// Not my public key, I found it on Google. Thank you, stranger! | |
mapboxgl.accessToken = 'pk.eyJ1IjoibWFwYm94IiwiYSI6IlhHVkZmaW8ifQ.hAMX5hSW-QnTeRCMAy9A8Q'; | |
mapboxgl.util.getJSON('https://www.mapbox.com/mapbox-gl-styles/styles/outdoors-v4.json', function (err, style) { | |
if (err) throw err; | |
style.layers.push({ | |
"id": "markers", | |
"source": "markers", | |
"type": "symbol", | |
"render": { | |
"icon-image": "{marker-symbol}-12", | |
"text-field": "{title}", | |
"text-font": "Open Sans Semibold, Arial Unicode MS Bold", | |
"text-offset": [0, 0.6], | |
"text-vertical-align": "top" | |
}, | |
"style": { | |
"text-size": 12 | |
} | |
}); | |
var map = new mapboxgl.Map({ | |
container: 'map', | |
style: style, | |
center: [37.8, -96], | |
zoom: 3 | |
}); | |
var features = [ | |
{ | |
"type": "Feature", | |
"geometry": { | |
"type": "Point", | |
"coordinates": [-77.03238901390978, 38.913188059745586] | |
}, | |
"properties": { | |
"title": "Mapbox DC", | |
"marker-symbol": "monument" | |
} | |
}, | |
{ | |
"type": "Feature", | |
"geometry": { | |
"type": "Point", | |
"coordinates": [-122.414, 37.776] | |
}, | |
"properties": { | |
"title": "Mapbox SF", | |
"marker-symbol": "harbor" | |
} | |
} | |
]; | |
var latBounds = [-122, -77]; | |
var lngBounds = [30, 50]; | |
for( var i=0; i<1000; i++ ){ | |
var lat = Math.random() * (latBounds[1]- latBounds[0] + 1) + latBounds[0]; | |
var lng = Math.random() * (lngBounds[1]- lngBounds[0] + 1) + lngBounds[0]; | |
features.push({ | |
"type": "Feature", | |
"geometry": { | |
"type": "Point", | |
"coordinates": [lat, lng] | |
}, | |
"properties": { | |
"title": "point_" +i, | |
"marker-symbol": "harbor" | |
} | |
}); | |
} | |
var geoJSON = { | |
"type": "FeatureCollection", | |
"features": features | |
}; | |
var markers = new mapboxgl.GeoJSONSource({ data: geoJSON }); | |
map.addSource('markers', markers); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment