Skip to content

Instantly share code, notes, and snippets.

Created Mar 5, 2014
What would you like to do?
layer from scratch + infowindow in gmaps
<!DOCTYPE html>
<title>Gmaps example | 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="" />
html, body, #map {
height: 100%;
padding: 0;
margin: 0;
<link rel="stylesheet" href="" />
<!--[if lte IE 8]>
<link rel="stylesheet" href="" />
<div id="map"></div>
<!-- include google maps library *before* load cartodb.js -->
<script src=""></script>
<!-- include cartodb.js library -->
<script src=""></script>
<script type="infowindow/html" id="infowindow_template">
<span> custom </span>
<div class="cartodb-popup">
<a href="#close" class="cartodb-popup-close-button close">x</a>
<div class="cartodb-popup-content-wrapper">
<div class="cartodb-popup-content">
<!-- contains the field info -->
<div class="cartodb-popup-tip-container"></div>
function main() {
var map;
var my_city = new google.maps.LatLng(43.7292108173, 12.6530746836);
var mapOptions = {
zoom: 15,
center: my_city,
map = new google.maps.Map(document.getElementById('map'), mapOptions);
cartodb.createLayer(map, {
user_name: 'sissy0584',
type: 'cartodb',
sublayers: [{
sql: "SELECT * FROM output_new",
cartocss: '#output_new { marker-opacity: 0.9; marker-fill: red; marker-width: 12;}',
interactivity: 'ppe_ma'
.on('done', function(layer) {
// get sublayer 0 and set the infowindow template
var sublayer = layer.getSubLayer(0);
// when you create a visualization from scratch you need to
// use cdb.vis.Vis.addInfowindow to set the params
// if you use viz.json the infowindow params are inside it
cdb.vis.Vis.addInfowindow(map, sublayer, ['cartodb_id','ppe_ma'], {
// we provide a nice default template, if you want yours uncomment this
//infowindowTemplate: $('#infowindow_template').html()
}).on('error', function() {
console.log("some error occurred");
}//end main
window.onload = main;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment