Last active
February 6, 2016 12:21
-
-
Save ernesmb/3eec0c96b52c3d0a2a80 to your computer and use it in GitHub Desktop.
ZoomInfo control w/ createLayer()
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>Custom ZoomLevel Control w/ createLayer() | 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; | |
} | |
.control-zinfo { | |
width: 26px; | |
height: 26px; | |
background-position: 50% 50%; | |
display: block; | |
background-color: #FFFFFF; | |
border-radius: 4px; | |
box-shadow: 0 1px 4px rgba(0,0,0,0.5); | |
display: table-cell; | |
vertical-align: middle; | |
text-align:center; | |
} | |
| |
</style> | |
<link rel="stylesheet" href="https://cartodb-libs.global.ssl.fastly.net/cartodb.js/v3/3.15/themes/css/cartodb.css" /> | |
</head> | |
<body> | |
<div id="map"></div> | |
<!-- include cartodb.js library --> | |
<script src="https://cartodb-libs.global.ssl.fastly.net/cartodb.js/v3/3.15/cartodb.js"></script> | |
<script> | |
function main() { | |
var map = new L.Map('map', { | |
zoomControl: true, | |
center: [36, -2], | |
zoom: 3, | |
}); | |
var basemap = L.tileLayer('http://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png', { | |
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, © <a href="http://cartodb.com/attributions">CartoDB</a>' | |
}).addTo(map); | |
cartodb.createLayer(map, { | |
user_name: 'ernestomb', | |
type: 'cartodb', | |
sublayers: [{ | |
sql: "SELECT * FROM ne_10m_populated_places_simple_7_copy", | |
cartocss: "#ne_10m_populated_places_simple_7{ marker-fill-opacity: 0.9; marker-line-color: #FFF; marker-line-width: 0; marker-line-opacity: 1; marker-placement: point; marker-multi-policy: largest; marker-type: ellipse; marker-fill: #FFCC00; marker-allow-overlap: true; marker-clip: false; marker-comp-op: multiply;}" | |
}] | |
},{https:true}).addTo(map) | |
.on('done', function(layer) { | |
}); | |
L.Control.zoomInfo = L.Control.extend({ | |
options: {position: 'topleft'}, | |
onAdd: function (map) { | |
var z0 = map.getZoom(); | |
zinfo = L.DomUtil.create('div','control-zinfo '); | |
zinfoUI = L.DomUtil.create('div', 'control-zinfo control-zinfo-interior', zinfo); | |
zinfoUI.innerHTML=z0; | |
console.log(z0); | |
map.on('zoomend', function(e){ | |
zinfoUI.innerHTML = this.getZoom(); | |
console.log(this.getZoom()); | |
}) | |
return zinfo; | |
} | |
}); | |
map.addControl(new L.Control.zoomInfo()); | |
} | |
window.onload = main; | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment