Skip to content

Instantly share code, notes, and snippets.

@nygeog
Last active September 24, 2016 14:55
Show Gist options
  • Save nygeog/4c3e594b2a03cfe065d4de42919287bf to your computer and use it in GitHub Desktop.
Save nygeog/4c3e594b2a03cfe065d4de42919287bf to your computer and use it in GitHub Desktop.
Carto JS html template
<!DOCTYPE html>
<html>
<head>
<title>Map Title</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="https://cartodb.com/assets/favicon.ico" />
<style>
html, body, #map {
height: 100%;
padding: 0;
margin: 0;
}
</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() {
cartodb.createVis('map', 'https://<username>carto.com/api/v2/viz/<viz-id>/viz.json', {
title: true,
description: true,
search: true,
tiles_loader: true,
center_lat: -22.9785,
center_lon: -43.3373,
zoom: 17,
scrollwheel: false,
search: false,
shareable: false,
layer_selector: true,
})
.done(function(vis, layers) {
// layer 0 is the base layer, layer 1 is cartodb layer
// setInteraction is disabled by default
layers[1].setInteraction(true);
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
var map = vis.getNativeMap();
// now, perform any operations you need
// map.setZoom(3);
// map.panTo([50.5, 30.5]);
})
.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