Created
September 22, 2015 12:18
-
-
Save iriberri/0c65b681afb46d4cbc31 to your computer and use it in GitHub Desktop.
Obtaining a fixed embed URL for specific coordinates
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> | |
<title>Get coordinates of geometry | 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; | |
} | |
body > div.cartodb-header{ | |
display: none; | |
position: absolute; | |
top:0px; | |
width: 100%; | |
background-color: rgba(0,0,0,.5); | |
font-family: 'Helvetica Neue',Helvetica,sans-serif; | |
line-height: normal; | |
z-index: 99999; | |
} | |
</style> | |
</style> | |
<link rel="stylesheet" href="http://libs.cartocdn.com/cartodb.js/v3/3.14/themes/css/cartodb.css" /> | |
</head> | |
<body> | |
<div id="map"></div> | |
<!-- include cartodb.js library --> | |
<script src="http://libs.cartocdn.com/cartodb.js/v3/3.14/cartodb.js"></script> | |
<script> | |
function main() { | |
var map = new L.Map('map', { | |
zoomControl: false, | |
center: [43, 0], | |
zoom: 3 | |
}); | |
L.tileLayer('http://tile.stamen.com/toner/{z}/{x}/{y}.png', { | |
attribution: 'Stamen', | |
}).addTo(map); | |
embed_url = 'http://documentation.cartodb.com/viz/236085de-ea08-11e2-958c-5404a6a683d5/embed_map' | |
cartodb.createLayer(map, 'http://documentation.cartodb.com/api/v2/viz/236085de-ea08-11e2-958c-5404a6a683d5/viz.json') | |
.addTo(map) | |
.on('done', function(layer) { | |
// change the query for the first layer | |
var subLayerOptions = { | |
sql: "SELECT * FROM example_cartodbjs_1 where pop_other::float > 1000000", | |
cartocss: "#example_cartodbjs_1{marker-fill: #109DCD; marker-width: 5; marker-line-color: white; marker-line-width: 0;}" | |
} | |
var sublayer = layer.getSubLayer(0); | |
sublayer.set(subLayerOptions); | |
sublayer.on('featureClick', function(e, latlng, pos, data) { | |
alert("Hey! You clicked " + latlng +". Your URL is: " + embed_url+"?center_lat="+latlng[0]+"¢er_lon="+latlng[1]+"&zoom=10"); | |
}); | |
}).on('error', function() { | |
//log the error | |
}); | |
} | |
window.onload = main; | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment