html 自定义信息窗口示例
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了html 自定义信息窗口示例相关的知识,希望对你有一定的参考价值。
<!DOCTYPE html>
<html>
<head>
<title>Custom infowindow 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;
}
</style>
<link rel="stylesheet" href="http://libs.cartodb.com/cartodb.js/v3/3.11/themes/css/cartodb.css" />
</head>
<body>
<div id="map"></div>
<script type="infowindow/html" id="infowindow_template">
</script>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script src="http://libs.cartodb.com/cartodb.js/v3/3.11/cartodb.js"></script>
<script>
var INFOWINDOW_TEMPLATE = [
'<div class="cartodb-popup v2">',
' <a href="#close" class="cartodb-popup-close-button close">x</a>',
' <div class="cartodb-popup-content-wrapper">',
' <div class="cartodb-popup-content">',
' <div id="chart_div">',
' <script>',
' draw_chart([{{content.data.pop_min}}, {{content.data.pop_max}}], "{{content.data.name}}");',
' </scr' + 'ipt>',
' </div>',
' </div>',
' </div>',
' <div class="cartodb-popup-tip-container"></div>',
'</div>'].join('');
// load visualization library from google
google.load('visualization', '1.0', {'packages':['corechart']});
function draw_chart(data, name) {
var data = google.visualization.arrayToDataTable([
['', 'population'],
['max', data[0]],
['min', data[1]]
]);
var options = {
title: name + ' population',
legend: { position: "none" },
width: 300,
};
var chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
function main() {
// create map
var map = L.map('map', {
zoomControl: false,
center: [0, 0],
zoom: 3
});
// add a nice baselayer from Cartodb
L.tileLayer('http://{s}.api.cartocdn.com/base-light/{z}/{x}/{y}.png', {
attribution: 'CartoDB'
}).addTo(map);
cartodb.createLayer(map, 'http://documentation.cartodb.com/api/v2/viz/7eb2096a-51d9-11e3-89a7-5404a6a683d5/viz.json')
.addTo(map)
.on('done', function(layer) {
// get sublayer 0 and set the infowindow template
var sublayer = layer.getSubLayer(0);
sublayer.infowindow.set({
template: INFOWINDOW_TEMPLATE,
width: 328,
maxHeight: 400
});
}).on('error', function() {
console.log("some error occurred");
});
}
window.onload = main;
</script>
</body>
</html>
以上是关于html 自定义信息窗口示例的主要内容,如果未能解决你的问题,请参考以下文章
带有两个可点击按钮或 ImageView 的 Google 地图 v2 自定义信息窗口