Created
July 23, 2014 16:22
-
-
Save andrewxhill/35b82ba8d6356a07c1c2 to your computer and use it in GitHub Desktop.
one minute demo of metro extracts
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> | |
<title>Layer selector example | CartoDB.js</title> | |
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> | |
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/> | |
<link rel="shortcut icon" href="http://cartodb.com/assets/favicon.ico" /> | |
<style> | |
html, body, #map { | |
height: 100%; | |
padding: 0; | |
margin: 0; | |
background: black; | |
} | |
</style> | |
<link rel="stylesheet" href="http://libs.cartocdn.com/cartodb.js/v3/themes/css/cartodb.css" /> | |
<!--[if lte IE 8]> | |
<link rel="stylesheet" href="http://libs.cartocdn.com/cartodb.js/v3/themes/css/cartodb.ie.css" /> | |
<![endif]--> | |
</head> | |
<body> | |
<div id="map"></div> | |
<!-- include cartodb.js library --> | |
<script src="http://libs.cartocdn.com/cartodb.js/v3/cartodb.js"></script> | |
<script> | |
var map; | |
function featureClick(e, pos, latlng, data){ | |
// var sql = new cartodb.SQL({ user: 'documentation' }); | |
console.log(data) | |
if(map.getZoom() < 7){ | |
map.setView([data.lat,data.lng],7) | |
} else { | |
var url = "http://osm.cartodb.com/api/v2/sql?format=shp&q=select the_geom,hstore_to_json(tags) as tags from osm_all WHERE the_geom %26%26 ST_SetSRID('"+data.bbox+"'::geometry, 4326)"; | |
window.location = url; | |
} | |
} | |
function main() { | |
// get the currently selected style | |
selectedStyle = $('li.selected').attr('id'); | |
cartodb.createVis('map','http://osm2.cartodb.com/api/v2/viz/cf26d670-009b-11e4-830e-0e73339ffa50/viz.json') | |
.done(function(vis, layers) { | |
// createSelector(layers); | |
map = vis.getNativeMap(); | |
layer = layers[1].getSubLayer(0); | |
layer.set({sql: 'SELECT cartodb_id, the_geom, area_sqkm, the_geom_webmercator, ST_ASText(the_geom) bbox, ST_X(ST_Centroid(the_geom)) lng, ST_Y(ST_Centroid(the_geom)) lat FROM ne_10m_urban_areas_bbox ORDER BY area_sqkm DESC',interactivity: 'cartodb_id, bbox, lat, lng'}) | |
layer.setInteraction(true); | |
layer.on('featureClick', featureClick); | |
}) | |
.error(function(err) { | |
console.log(err); | |
}); | |
} | |
window.onload = main; | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment