forked from CartoDB/carto.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgmaps_multilayer.html
94 lines (78 loc) · 3.01 KB
/
gmaps_multilayer.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<!DOCTYPE html>
<html>
<head>
<title>GMaps multilayer 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.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>
<!-- include google maps library *before* load cartodb.js -->
<script src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
<!-- include cartodb.js library -->
<script src="http://libs.cartocdn.com/cartodb.js/v3/cartodb.js"></script>
<script>
function main() {
var map;
// create google maps map
var mapOptions = {
zoom: 3,
center: new google.maps.LatLng(43, 0),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('map'), mapOptions);
// add cartodb layer with one sublayer
cartodb.createLayer(map, {
user_name: 'examples',
type: 'cartodb',
sublayers: [{
sql: 'select * from country_boundaries',
cartocss: '#layer { polygon-fill: #F00; polygon-opacity: 0.3; line-color: #F00; }'
}]
})
.addTo(map)
.done(function(layer) {
var population;
// wait a little bit and add the most populated places
setTimeout(function() {
population = layer.createSubLayer({
sql: 'select * from ne_10m_populated_p_2',
cartocss: '#layer { marker-fill: black; line-color: #333; marker-width: 3 }',
interactivity: 'name'
});
// print on the console the place name on hover
population.on('featureOver', function(e, pos, pixel, data) {
console.log(data.name);
});
population.setInteraction(true);
}, 3000);
// show population only in USA
setTimeout(function() {
population.setSQL("select * from ne_10m_populated_p_2 where adm0name = 'United States of America'")
}, 6000);
// bigger points in USA
setTimeout(function() {
population.setCartoCSS( '#layer { marker-fill: black; line-color: #333; marker-width: 10; marker-opacity: 0.6; }' );
}, 8000);
// remove the countries layer
setTimeout(function() {
layer.getSubLayer(0).remove();
}, 10000);
});
}
window.onload = main;
</script>
</body>
</html>