forked from Vizzuality/cartodb-leaflet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
executable file
·506 lines (466 loc) · 24.3 KB
/
index.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
<!doctype html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8" lang="en"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9" lang="en"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">
<title>CartoDB | Leaflet library</title>
<link href="http://developers.cartodb.com/stylesheets/all.css" media="screen" rel="stylesheet" type="text/css" />
<link href="css/style.css" media="screen" rel="stylesheet" type="text/css" />
<script src="http://developers.cartodb.com/javascripts/all.js" type="text/javascript"></script>
<link rel="shortcut icon" href="img/favicon.ico" />
<script type="text/javascript">
var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-20934186-3']); _gaq.push(['_setDomainName', 'cartodb.com']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })();
</script>
</head>
<body class="developers examples" onload="initialize()">
<div class="background blue grid fixed">
<header>
<h1 class="left">
<a href="http://cartodb.com">CartoDB</a>
</h1>
<nav class="right">
<a href="http://cartodb.com/tour">Tour</a>
<a href="http://cartodb.com/maps">Maps</a>
<a class="selected" href="http://developers.cartodb.com">Developers</a>
<a href="http://cartodb.com/pricing">Pricing</a>
<a href="http://cartodb.com/login">Sign in</a>
</nav>
</header>
</div>
<div class="background floating">
<section class="shadow top">
<div class="content">
<hgroup><h2 class="dark">CartoDB Leaflet library</h2><em class="medium">0.55</em></hgroup>
</div>
<div class="content no_padding border code">
<link rel="stylesheet" href="css/leaflet.css" />
<!--[if IE]> <link rel="stylesheet" href="css/leaflet.ie.css" /> <![endif]-->
<link href="css/cartodb-leaflet.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="js/leaflet.js"></script>
<script type="text/javascript" src="js/wax.leaf.min.js"></script>
<script type="text/javascript" src="dist/cartodb-leaflet-min.js"></script>
<script type="text/javascript">
function initialize() {
// Create the map
var map = new L.Map('map').setView([20,0], 3)
// Create leaflet standard popup
, popup = new L.Popup();
// First cartodb layer, countries
var cartodb_leaflet1 = new L.CartoDBLayer({
map: map,
user_name:'examples',
table_name: 'country_colors',
query: "SELECT * FROM {{table_name}}",
auto_bound: false,
debug: true
});
// Adding layer to map
map.addLayer(cartodb_leaflet1);
// Second cartodb layer, earthquakes
cartodb_leaflet2 = new L.CartoDBLayer({
map: map,
user_name:"examples",
table_name: 'earthquakes',
query: "SELECT cartodb_id,the_geom_webmercator,the_geom,magnitude FROM {{table_name}}",
tile_style: "#{{table_name}}{marker-fill:#E25B5B}",
opacity: 0.8,
interactivity: "cartodb_id, magnitude",
featureOver: function(ev,latlng,pos,data) {
document.body.style.cursor = "pointer";
},
featureOut: function() {
document.body.style.cursor = "default";
},
featureClick: function(ev,latlng,pos,data) {
// Set popup content
var html = '';
for(var column in data) {
html += '<label>' + column + '</label>';
html += '<p>' + data[column] + '</p>';
}
popup.setContent(html);
// Set latlng
popup.setLatLng(latlng);
// Show it!
map.openPopup(popup);
},
auto_bound: true,
debug: false
});
// Adding layer to map
map.addLayer(cartodb_leaflet2);
}
</script>
<div id="map"></div>
<span class="separator"></span>
</div>
<a class="back" href="http://developers.cartodb.com/">Back</a>
</section>
<section class="shadow leftwards bottom nav">
<div class="content overflow">
<div class="left">
<h3 class="big">Overview</h3>
<p class="light margin15">Use your CartoDB tables with a Leaflet map.</p>
<p class="light margin15"><a href="http://leaflet.cloudmade.com/" target="_blank">Leaflet</a> is a modern, lightweight open-source JavaScript library for mobile-friendly interactive maps. It is developed by <a href="http://cloudmade.com/" target="_blank">CloudMade</a>. It still has all the features most developers ever need for online maps, while providing a fast, pleasant user experience.</p>
<p class="light margin15">The code is available on <a href="https://github.com/vizzuality/cartodb-leaflet" target="_blank">Github</a>. We encourage you to download the source files and not pointing them from GitHub. If you have any question there is a complete <a href="#documentation">documentation</a> or you can ask in the <a target="_blank" href="https://groups.google.com/forum/#!forum/cartodb">CartoDB mailing list</a>.</p>
</div>
<div class="right">
<a class="button blue download" href="https://github.com/Vizzuality/cartodb-leaflet/zipball/gh-pages">Download this library</a>
<h3 class="big margin40">Related resources</h3>
<ul class="vt related">
<li><a href="http://developers.cartodb.com/documentation/cartodb-apis.html#maps_api">CartoDB Maps API</a></li>
<li><a href="http://vizzuality.github.com/cartodb-gmapsv3">CartoDB Google Maps library</a></li>
<li><a href="examples/">CartoDB Leaflet examples</a></li>
</ul>
</div>
</div>
</section>
<section class="shadow margin40">
<div class="content overflow">
<h3 class="big" id="documentation">Documentation</h3>
<p class="margin15 light">Using the library is really easy. It accepts the following parameters to manage the behavior of your CartoDB layers:</p>
<table class="margin30">
<tr>
<td><b>Parameter name</b></td>
<td><b>Description</b></td>
<td><b>Type</b></td>
<td><b>Callback variables</b></td>
<td><b>Required</b></td>
</tr>
<tr>
<td><i>map</i></td>
<td>The Leaflet Map object.</td>
<td>Object</td>
<td></td>
<td>Yes</td>
</tr>
<tr>
<td><i>username</i></td>
<td>Your CartoDB user name.</td>
<td>String</td>
<td></td>
<td>Yes</td>
</tr>
<tr>
<td><i>table_name</i></td>
<td>Your CartoDB table name.</td>
<td>String</td>
<td></td>
<td>Yes</td>
</tr>
<tr>
<td><i>query</i></td>
<td>A SQL query. Default: <b>"SELECT * FROM {{table_name}}"</b></td>
<td>String</td>
<td></td>
<td>Yes</td>
</tr>
<tr>
<td><i>opacity</i></td>
<td>If you want to change the opacity of the CartoDB layer. Default: <b>1</b></td>
<td>Number</td>
<td></td>
<td>No</td>
</tr>
<tr>
<td><i>interactivity</i></td>
<td>If you want to add interactivity to the layer without making requests.</td>
<td>String (columns separated by commas)</td>
<td></td>
<td>No</td>
</tr>
<tr>
<td><i>featureOver</i></td>
<td>A callback when hovers in a feature</td>
<td>Function</td>
<td>
<b>event:</b> Mouse event object<br/>
<b>latlng:</b> The LatLng leaflet object where was clicked<br/>
<b>pos:</b> Object with x and y position in the DOM map element<br/>
<b>data:</b> The CartoDB data of the clicked feature with the `interactivity` param.
</td>
<td>No (But only will work with <i>interactivity</i> specified)</td>
</tr>
<tr>
<td><i>featureOut</i></td>
<td>A callback when hovers out a feature</td>
<td>Function</td>
<td></td>
<td>No (But only will work with <i>interactivity</i> specified)</td>
</tr>
<tr>
<td><i>featureClick</i></td>
<td>A callback when clicks in a feature</td>
<td>Function</td>
<td>
<b>event:</b> Mouse event object<br/>
<b>latlng:</b> The LatLng leaflet object where was clicked<br/>
<b>pos:</b> Object with x and y position in the DOM map element<br/>
<b>data:</b> The CartoDB data of the clicked feature with the `interactivity` param.
</td>
<td>No (But only will work with <i>interactivity</i> specified)</td>
</tr>
<tr>
<td><i>attribution</i></td>
<td>Set the layer attribution.</td>
<td>String</td>
<td></td>
<td>No</td>
</tr>
<tr>
<td><i>tile_style</i></td>
<td>If you want to add other style to the layer.</td>
<td>String</td>
<td></td>
<td>No</td>
</tr>
<tr>
<td><i>auto_bound</i></td>
<td>If you want to zoom in the area where the layer is positioned.</td>
<td>Boolean</td>
<td></td>
<td>No</td>
</tr>
<tr>
<td><i>debug</i></td>
<td>If you want to debug the library, set to true.</td>
<td>Boolean</td>
<td></td>
<td>No</td>
</tr>
<tr class="separator"><td></td><td></td><td></td><td></td><td></td></tr>
<tr>
<td><i>tiler_protocol</i></td>
<td>Protocol for the tiler URL. Default: <b>"http"</b></td>
<td>String</td>
<td></td>
<td>No</td>
</tr>
<tr>
<td><i>tiler_domain</i></td>
<td>Base domain of the tiler URL. Default: <b>"cartodb.com"</b></td>
<td>String</td>
<td></td>
<td>No</td>
</tr>
<tr>
<td><i>tiler_port</i></td>
<td>Port of the tiler URL. Default: <b>"80"</b> </td>
<td>String</td>
<td></td>
<td>No</td>
</tr>
<tr>
<td><i>sql_protocol</i></td>
<td>SQL API protocol (opcional - default = <b>"http"</b>).</td>
<td>String</td>
<td></td>
<td>No</td>
</tr>
<tr>
<td><i>sql_domain</i></td>
<td>SQL API domain (opcional - default = <b>"cartodb.com"</b>).</td>
<td>String</td>
<td></td>
<td>No</td>
</tr>
<tr>
<td><i>sql_port</i></td>
<td>SQL API port as a string (opcional - default = <b>"80"</b>).</td>
<td>String</td>
<td></td>
<td>No</td>
</tr>
</table>
<h5 class="margin30">Usage notes</h5>
<p class="margin15 light">If you want to get a feature clicked || hover data (via the <i>interactivity</i> parameter), the columns must be in a string separated by commas. If you don't want to write the name of the table several times, you can use {{table_name}} in the <i>query</i> or <i>tile_style</i> parameters. We strongly recommend the use of the files available in this repository. These are tested, and if you decide use updated ones, the library could not work.</p>
<h5 class="margin30">Example</h5>
<p class="margin15 light">First of all add the necessary script and css files:</p>
<pre class="margin10 prettyprint" data-language="html">
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.4.4/leaflet.css" />
<!--[if IE]> <link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.4.4/leaflet.ie.css" /> <![endif]-->
<link href="css/cartodb-leaflet.css" rel="stylesheet" type="text/css">
<script src="http://cdn.leafletjs.com/leaflet-0.4.4/leaflet.js"></script>
<script type="text/javascript" src="https://raw.github.com/mapbox/wax/master/dist/wax.leaf.min.js"></script>
<script type="text/javascript" src="https://raw.github.com/vizzuality/cartodb-leaflet/master/dist/cartodb-leaflet-min.js"></script>
</pre>
<p class="margin15 light">When the document is loaded, start creating the map:</p>
<pre class="prettyprint" data-language="javascript">
var map = new L.Map('map');
</pre>
<p class="margin20 light">Then create the CartoDB layer:</p>
<pre class="margin10 prettyprint" data-language="javascript">
var cartodb_leaflet = new L.CartoDBLayer({
map: map,
user_name:'example',
table_name: 'earthquakes',
query: "SELECT * FROM {{table_name}}",
tile_style: "#{{table_name}}{marker-fill:red}",
interactivity: "cartodb_id, magnitude",
featureClick: function(ev, latlng, pos, data) {alert(data)},
featureOut: function() {},
featureOver: function(ev, latlng, pos, data) {},
auto_bound: true
});
</pre>
<p class="margin20 light">And finally add it to the map:</p>
<pre class="prettyprint" data-language="javascript">map.addLayer(cartodb_leaflet);</pre>
<h5 class="margin30">Functions</h5>
<p class="margin15 light">New funcionalities are coming, in the meantime you can use:</p>
<ul class="margin20">
<li style="display:block">
<p class="light"><b>removeLayer</b>: Removes the cartodb layer from the map.</p>
<pre class="prettyprint" style="margin:5px 0 0!important" data-language="javascript"> map.removeLayer(cartodb_leaflet);</pre>
</li>
<li class="margin15" style="display:block">
<p class="light"><b>hide</b>: Hide the cartodb layer from the map.</p>
<pre class="prettyprint" style="margin:5px 0 0!important" data-language="javascript"> cartodb_leaflet.hide();</pre>
</li>
<li class="margin15" style="display:block">
<p class="light"><b>show</b>: Show again the cartodb layer in the map.</p>
<pre class="prettyprint" style="margin:5px 0 0!important" data-language="javascript"> cartodb_leaflet.show();</pre>
</li>
<li class="margin15" style="display:block">
<p class="light"><b>setInteraction</b>: Set the interaction of your layer to true or false.</p>
<pre class="prettyprint" style="margin:5px 0 0!important" data-language="javascript"> cartodb_leaflet.setInteraction(false);</pre>
</li>
<li class="margin15" style="display:block">
<p class="light"><b>setAttribution</b>: Set the layer attribution.</p>
<pre class="prettyprint" style="margin:5px 0 0!important" data-language="javascript"> cartodb_leaflet.setAttribution("CartoDB");</pre>
</li>
<li class="margin15" style="display:block">
<p class="light"><b>setOpacity</b>: Change the opacity of the CartoDB layer.</p>
<pre class="prettyprint" style="margin:5px 0 0!important" data-language="javascript"> cartodb_leaflet.setOpacity(0.3);</pre>
</li>
<li class="margin15" style="display:block">
<p class="light"><b>setQuery</b>: Change the query parameter for the layer.</p>
<pre class="prettyprint" style="margin:5px 0 0!important" data-language="javascript"> cartodb_leaflet.setQuery("SELECT * FROM {{table_name}} WHERE cartodb_id > 10");</pre>
</li>
<li class="margin15" style="display:block">
<p class="light"><b>setStyle</b>: Change the style of the layer tiles.</p>
<pre class="prettyprint" style="margin:5px 0 0!important" data-language="javascript"> cartodb_leaflet.setStyle("#{{table_name}}{marker-fill:blue}");</pre>
</li>
<li class="margin15" style="display:block">
<p class="light"><b>isVisible</b>: Get the visibility of the layer.</p>
<pre class="prettyprint" style="margin:5px 0 0!important" data-language="javascript"> cartodb_leaflet.isVisible();</pre>
</li>
<li class="margin15" style="display:block">
<p class="light"><b>isAdded</b>: Returns if the layer already belongs to the map.</p>
<pre class="prettyprint" style="margin:5px 0 0!important" data-language="javascript"> cartodb_leaflet.isAdded();</pre>
</li>
<li class="margin15" style="display:block">
<p class="light"><b>setInteractivity</b>: Change the columns you want to get data (it needs to reload the tiles).</p>
<pre class="prettyprint" style="margin:5px 0 0!important" data-language="javascript"> cartodb_leaflet.setInteractivity("cartodb_id, the_geom, magnitude");</pre>
</li>
<li class="margin15" style="display:block">
<p class="light"><b>setBounds</b>: Set bounds in the map using a new query or the default one.</p>
<pre class="prettyprint" style="margin:5px 0 0!important" data-language="javascript"> cartodb_leaflet.setBounds(); || cartodb_leaflet.setBounds("SELECT * FROM {{table_name}} WHERE cartodb_id < 100"); </pre>
</li>
<li class="margin15" style="display:block">
<p class="light"><b>setOptions</b>: Change any parameter at the same time refreshing the tiles once.</p>
<pre class="prettyprint" style="margin:5px 0 0!important" data-language="javascript"> cartodb_leaflet.setOptions({query: "SELECT * FROM {{table_name}} WHERE cartodb_id<100", interactivity: "cartodb_id,the_geom,magnitude"});</pre>
</li>
<!--li class="margin15" style="display:block">
<p class="light"><b>setLayerOrder</b>: _Not available yet_ -> Waiting for this ticket fixed: https://github.com/CloudMade/Leaflet/issues/505</p>
</li-->
</ul>
<h5 class="margin30" id="custom-popup">Custom popup</h5>
<p class="margin15 light">If you want to use the cartodb custom popup, you need to add the script in the html:</p>
<pre class="margin10 prettyprint" data-language="html">
<script type="text/javascript" src="dist/cartodb-popup-min.js"></script>
</pre>
<p class="light margin15">Create the CartoDB popup:</p>
<pre margin="prettyprint" data-language="javascript">
var popup = new L.CartoDBPopup();
</pre>
<p class="light margin15">And then use as you want:</p>
<pre class="prettyprint" data-language="javascript">
...
featureClick: function(ev,latlng,pos,data) {
// Set popup content
// You can pass an Object, an Array or a String
popup.setContent(data);
// Set latlng
popup.setLatLng(latlng);
// Show it!
map.openPopup(popup);
},
...
</pre>
<p class="light margin15">You can see an example using it <a href="examples/custom-popup.html">here</a>.</p>
</div>
</section>
<section class="grey carto shadow margin40">
<div class="content less_padding">
<div class="left">
<h2 class="compact dark">Further info? Take a look a the docs</h2>
<p class="light">Visit our support area and get some help from the community.</p>
</div>
<div class="right">
<a class="button blue right margin5" href="http://developers.cartodb.com/documentation/using-cartodb.html">Go to documentation</a>
</div>
</div>
</section>
<div class="background white border margin40">
<section>
<div class="content less_padding">
<div class="left">
<h3 class="lighter margin10">CartoDB is also used by</h3>
</div>
<div class="right">
<ul class="logos">
<li><a class="harvard" target="_blank" href="http://www.harvard.edu/"><img alt="Harvard" title="Harvard" src="http://developers.cartodb.com//images/logos/harvard.png" /></a></li>
<li><a class="unep-wcmc" target="_blank" href="http://www.unep-wcmc.org/"><img alt="UNEP-WCMC" title="UNEP-WCMC" src="http://developers.cartodb.com/images/logos/unep-wcmc.png" /></a></li>
<li><a class="nasa" target="nasa" href="http://www.nasa.gov"><img alt="NASA" title="NASA" src="http://developers.cartodb.com/images/logos/nasa.png" /></a></li>
<li><a class="diversity" target="_blank" href="http://www.cbd.int/"><img alt="Convention on Biological Diversity" title="Convention on Biological Diversity" src="http://developers.cartodb.com/images/logos/diversity.png" /></a></li>
<li><a class="wsj" target="_blank" href="http://europe.wsj.com/home-page"><img alt="Wall Street Journal" title="Wall Street Journal" src="http://developers.cartodb.com/images/logos/wsj.png" /></a></li>
<li><a class="wri" target="_blank" href="http://www.wri.org/"><img alt="WORLD RESOURCES INSTITUTE" title="WORLD RESOURCES INSTITUTE" src="http://developers.cartodb.com/images/logos/wri.png" /></a></li>
</ul>
</div>
</div>
</section>
</div>
<div class="background white border">
<section>
<div class="content no_padding">
<ul class="hz">
<li>
<h3>Common questions</h3>
</li>
<li>
<h3>Do you have any educational plans?</h3>
<p class="light margin15">Yes we have. <a href="mailto:[email protected]">Contact us</a> for getting more information. We are quite friends of academics so, you will get a lot of benefits.</p>
</li>
<li>
<h3>Need something extra? Let us know.</h3>
<p class="light margin15">Need us to help you with your visualization or application? Does your organization have unique requirements that don’t quite fit our plans? <a href="mailto:[email protected]">Contact us</a>.</p>
</li>
</ul>
</div>
</section>
</div>
<footer>
<div class="wrap">
<span class="cartodb">CartoDB</span>
<p class="lighter small left">CartoDB is a product of <a class="vizzuality" href="http://vizzuality.com">Vizzuality</a>
</p>
<nav class="right">
<a href="http://cartodb.com/tour">Feature tour</a>
<a href="http://cartodb.com/tutorial/step/1">Getting started</a>
<a href="http://cartodb.com/maps">Maps</a>
<a href="http://developers.cartodb.com/">Developers</a>
<a href="http://blog.cartodb.com">Blog</a>
<a href="http://cartodb.com/pricing">Pricing</a>
<a href="mailto:[email protected]">Contact</a>
</nav>
</div>
</footer>
</div>
<script>
prettyPrint();
</script>
</body>
</html>