Created
March 19, 2014 11:24
-
-
Save matallo/9639726 to your computer and use it in GitHub Desktop.
This file contains hidden or 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>Easy 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="http://cartodb.com/assets/favicon.ico" /> | |
<style> | |
html, body, #map { | |
height: 100%; | |
padding: 0; | |
margin: 0; | |
} | |
.list { | |
position: absolute; | |
background: white; | |
top: 180px; | |
left: 20px; | |
padding: 20px; | |
z-index: 10; | |
} | |
.marker_img { | |
height: 158px; | |
} | |
</style> | |
<link rel="stylesheet" href="http://libs.cartocdn.com/cartodb.js/v3/themes/css/cartodb.css" /> | |
<!--[if lte IE 8]> | |
<link rel="stylesheet" href="http://libs.cartocdn.com/cartodb.js/v3/themes/css/cartodb.ie.css" /> | |
<![endif]--> | |
</head> | |
<body> | |
<div id="map"></div> | |
<div class="list"> | |
<a href="#" class="link">open infowindow</a> | |
</div> | |
<!-- include cartodb.js library --> | |
<script src="http://libs.cartocdn.com/cartodb.js/v3/cartodb.uncompressed.js"></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"> | |
<div class='marker_img'> | |
<img id="screenshot" src="#" style="width:300px;margint-left:10px; padding: 3px; border: solid 1px #EFEFEF;" /> | |
</div> | |
<!-- content.data contains the field info --> | |
<h4>{{content.data.name}}</h4> | |
<script> | |
//Load dynamic image (url depends on {{content.data}}) | |
var imageId = Math.floor(Math.random() * 10); | |
$("#screenshot").attr("src","http://lorempixel.com/400/200/sports/"+imageId); | |
</script> | |
</div> | |
</div> | |
<div class="cartodb-popup-tip-container"></div> | |
</div> | |
</script> | |
<script> | |
function openInfowindow(layer, latlng, cartodb_id) { | |
layer.trigger('featureClick', null, latlng, null, { cartodb_id: cartodb_id }, 0); | |
} | |
function main() { | |
cartodb.createVis('map', 'http://documentation.cartodb.com/api/v2/viz/7eb2096a-51d9-11e3-89a7-5404a6a683d5/viz.json', { | |
shareable: false, | |
title: false, | |
description: false, | |
search: false, | |
tiles_loader: true, | |
center_lat: 35.317, | |
center_lon: -3.5, | |
zoom: 7, | |
legends: false | |
}) | |
.done(function(vis, layers) { | |
// layer 0 is the base layer, layer 1 is cartodb layer | |
var layer = layers[1]; | |
var sublayer = layer.getSubLayer(0); | |
sublayer.infowindow.set('template', $('#infowindow_template').html()); | |
$('.link').click(function() { | |
openInfowindow(layer, [40.4000262645, -3.683351686], 5324) | |
return false; | |
}); | |
}) | |
.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