-
-
Save bolollo/28f1447492232da0b7af to your computer and use it in GitHub Desktop.
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>Trying to hide the layers| 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; | |
} | |
</style> | |
<link rel="stylesheet" href="http://libs.cartocdn.com/cartodb.js/v3/themes/css/cartodb.css" /> | |
</head> | |
<body> | |
<div id="map"></div> | |
<!-- include cartodb.js library --> | |
<script src="http://libs.cartocdn.com/cartodb.js/v3/cartodb.js"></script> | |
<script> | |
function main() { | |
cartodb.createVis('map', 'http://xurxosanz.cartodb.com/api/v2/viz/e0cc9a92-1b24-11e4-b59c-0e10bcd91c2b/viz.json', { | |
shareable: false, | |
title: false, | |
description: false, | |
search: true, | |
tiles_loader: true, | |
center_lat: 0, | |
center_lon: 0, | |
zoom: 2, | |
layer_selector:true, | |
cartodb_logo: true, | |
legends: false | |
}) | |
.done(function(vis, layers) { | |
//get the data layers | |
var overlays = layers[1].getSubLayers(); | |
overlays.forEach(function(overlay) { | |
overlay.hide(); | |
}); | |
//get the layer selector control | |
var control = vis.getOverlay("layer_selector"); | |
//redraw layer selector to update the states | |
control.render(); | |
layers[1].on('featureOver', function(e, pos, latlng, data) { | |
cartodb.log.log(e, pos, latlng, data); | |
}); | |
// you can get the native map to work with it | |
// depending if you use google maps or leaflet | |
map = vis.getNativeMap(); | |
// now, perform any operations you need | |
// map.setZoom(3) | |
// map.setCenter(new google.maps.Latlng(...)) | |
}) | |
.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