-
Notifications
You must be signed in to change notification settings - Fork 264
/
populated-places-gmaps.html
140 lines (130 loc) · 4.26 KB
/
populated-places-gmaps.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<!DOCTYPE html>
<html>
<head>
<title>Populated places | CARTO</title>
<meta name="viewport" content="initial-scale=1.0">
<meta charset="utf-8">
<link href="https://fonts.googleapis.com/css?family=Montserrat:400,600,700|Open+Sans:300,400,600" rel="stylesheet">
<!-- Include Google Maps -->
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAORE5iCjgLb4sMcWfmyRJgtP9VwfOrbJM&v=3.32"></script>
<!-- Include CARTO.js -->
<script src="../../../dist/public/carto.js"></script>
<link href="../style.css" rel="stylesheet">
</head>
<body>
<div id="map"></div>
<aside class="toolbox">
<div class="box">
<header>
<h1>Most/less populated places</h1>
<button class="github-logo js-source-link"></button>
</header>
<section>
<p class="description open-sans">Filter the 20 most/less populated places in the world.</p>
<div class="separator"></div>
<div id="controls">
<ul class="actions">
<li onclick="setAll()">
<input type="radio" name="style" value="01" id="all" checked="">
<label for="all">ALL Places
<label>
</li>
<li onclick="setMostPopulated(20)">
<input type="radio" name="style" value="02" id="most">
<label for="most">Most populated places</label>
</li>
<li onclick="setLessPopulated(20)">
<input type="radio" name="style" value="03" id="less">
<label for="less">Less populated places</label>
</li>
</ul>
</div>
</section>
<footer class="js-footer"></footer>
</div>
</aside>
<script>
var map = new google.maps.Map(document.getElementById('map'), {
center: { lat: 30, lng: 0 },
zoom: 3,
fullscreenControl: false,
gestureHandling: 'cooperative'
});
// Hide the map labels and geometry strokes
map.set('styles', [{
elementType: 'labels',
stylers: [{ visibility: 'off' }]
}, {
elementType: 'geometry.stroke',
stylers: [{ visibility: 'off' }]
}]);
const client = new carto.Client({
apiKey: 'default_public',
username: 'cartojs-test'
});
const populatedPlacesSource = new carto.source.SQL(`
SELECT *
FROM ne_10m_populated_places_simple
`);
const populatedPlacesStyle = new carto.style.CartoCSS(`
#layer {
marker-fill: #EE4D5A;
marker-width: 7;
marker-line-color: #FFFFFF;
}
`);
const populatedPlacesLayer = new carto.layer.Layer(populatedPlacesSource, populatedPlacesStyle);
client.addLayer(populatedPlacesLayer);
map.overlayMapTypes.push(client.getGoogleMapsMapType(map));
function setAll() {
populatedPlacesSource.setQuery(`
SELECT *
FROM ne_10m_populated_places_simple
`);
populatedPlacesStyle.setContent(`
#layer {
marker-fill: #EE4D5A;
marker-width: 7;
marker-line-color: #FFFFFF;
}
`);
}
function setMostPopulated(limit) {
populatedPlacesSource.setQuery(`
SELECT *
FROM ne_10m_populated_places_simple
ORDER BY pop_max DESC LIMIT ${limit}
`);
populatedPlacesStyle.setContent(`
#layer {
marker-fill: #68B69E;
marker-width: 12;
marker-line-color: #FFFFFF;
text-name: [name];
text-face-name: 'Open Sans Regular';
text-size: 12;
text-dy: -10;
}
`);
}
function setLessPopulated(limit) {
populatedPlacesSource.setQuery(`
SELECT *
FROM ne_10m_populated_places_simple
ORDER BY pop_max ASC LIMIT ${limit}
`);
populatedPlacesStyle.setContent(`
#layer {
marker-fill: #F15743;
marker-width: 12;
marker-line-color: #FFFFFF;
text-name: [name];
text-face-name: 'Open Sans Regular';
text-size: 12;
text-dy: -10;
}
`);
}
</script>
</body>
</html>