Skip to content

Instantly share code, notes, and snippets.

@bsudekum
Created February 4, 2014 23:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bsudekum/8814541 to your computer and use it in GitHub Desktop.
Save bsudekum/8814541 to your computer and use it in GitHub Desktop.
Esri + mapbox + clustering
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title></title>
<meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no' />
<script src='//api.tiles.mapbox.com/mapbox.js/v1.6.1/mapbox.js'></script>
<link href='//api.tiles.mapbox.com/mapbox.js/v1.6.1/mapbox.css' rel='stylesheet' />
<script src='//code.jquery.com/jquery-2.0.3.min.js'></script>
<script src='//api.tiles.mapbox.com/mapbox.js/plugins/leaflet-hash/v0.2.1/leaflet-hash.js'></script>
<script src='//api.tiles.mapbox.com/mapbox.js/plugins/leaflet-markercluster/v0.4.0/leaflet.markercluster.js'></script>
<link href='//api.tiles.mapbox.com/mapbox.js/plugins/leaflet-markercluster/v0.4.0/MarkerCluster.css' rel='stylesheet' />
<link href='//api.tiles.mapbox.com/mapbox.js/plugins/leaflet-markercluster/v0.4.0/MarkerCluster.Default.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 type="text/javascript">
var map = L.mapbox.map('map', 'examples.map-9ijuk24y')
.setView([45.5238,-122.6764],16);
var hash = new L.hash(map);
var markers = new L.MarkerClusterGroup();
// Call up esri
$.ajax({
type: 'GET',
datatype: 'json',
url: 'http://services.arcgis.com/rOo16HdIMeOBI4Mb/arcgis/rest/services/stops/FeatureServer/0/query?geometryType=esriGeometryEnvelope&geometry=%7B%22xmin%22%3A-122.68273830413818%2C%22ymin%22%3A45.519819502877084%2C%22xmax%22%3A-122.67175197601318%2C%22ymax%22%3A45.527516684421265%2C%22spatialReference%22%3A%7B%22wkid%22%3A4326%7D%7D&outFields=*&outSR=4326&inSR=4326&f=json',
success: function(e) {
var data = JSON.parse(e);
for (var i = 0; i < data.features.length; i++) {
console.log(data.features[i])
var marker = L.marker([data.features[i].geometry.y, data.features[i].geometry.x], {
icon: L.mapbox.marker.icon({
'marker-symbol': 'bus',
'marker-color': 'DD4814'
})
}).bindPopup(data.features[i].attributes.stop_desc)
//Add to cluster layer
markers.addLayer(marker);
}
},
error: function(e) {
console.log(e)
}
})
map.addLayer(markers);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment