Created
October 28, 2015 15:14
-
-
Save oriolbx/69f9c6c9c0361cb917b5 to your computer and use it in GitHub Desktop.
add CartoDB search box with 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> | |
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> | |
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/> | |
<link rel="stylesheet" href="http://libs.cartocdn.com/cartodb.js/v3/3.15/themes/css/cartodb.css" /> | |
<!-- include cartodb.js library --> | |
<script src="http://libs.cartocdn.com/cartodb.js/v3/3.15/cartodb.js"></script> | |
<style> | |
html, body, #map { | |
height: 100%; | |
padding: 0; | |
margin: 0; | |
} | |
</style> | |
</head> | |
<body> | |
<div id="map"></div> | |
<script type="text/javascript"> | |
var layer; | |
var vector = []; | |
var legend; | |
function main() { | |
var map = L.map('map', { | |
zoomControl: false, | |
center: [41.390205, 2.154007], | |
zoom: 12 | |
}); | |
// add basemap | |
L.tileLayer('http://{s}.basemaps.cartocdn.com/light_nolabels/{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); | |
// add CartoDB layer | |
cartodb.createLayer(map, { | |
user_name: 'oboix', | |
type: 'cartodb', | |
sublayers: [{ | |
sql: "select * FROM barris_barcelona_test;", | |
cartocss: "#barris_barcelona_test{ polygon-fill: #29ABA4;polygon-opacity: 1;line-color: #FFF;line-width: 0.5;line-opacity: 1; }", | |
}] | |
}).addTo(map) | |
.done(function(){ | |
// add search box | |
var searchBox = cdb.vis.Overlay.create('search', map.viz, {}); | |
searchBox.show(); | |
$('#map').append(searchBox.render().el); | |
}); | |
} | |
window.onload = main; | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment