Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
375 lines (329 loc) · 13.2 KB
/
Copy pathindex.html
File metadata and controls
375 lines (329 loc) · 13.2 KB
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<
8000
/div>
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
---
layout: default
category: introduction
section: developers
examples:
- title: 'Basic'
id: 'map-basic'
description: 'With just a few lines of code, embed your own map with customizable controls like search and share.'
code: |
<script>
var map = L.mapbox.map('map-basic', 'examples.map-9ijuk24y')
.setView([37.8, -96], 4);
map.addControl(L.mapbox.geocoderControl('examples.map-9ijuk24y'))
map.addControl(L.mapbox.shareControl())
</script>
- title: 'Markers'
id: 'map-markers'
description: 'Use <a href="http://www.geojson.org/">GeoJSON</a>, a simple specification for adding data to create points of interest on a map and much more.'
code: |
<script>
var geojson = [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [-77.03238901390978,38.913188059745586]
},
"properties": {
"title": "MapBox DC",
"description": "1714 14th St NW, Washington DC",
"marker-color": "#fc4353",
"marker-size": "large",
"marker-symbol": "monument"
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [-122.414, 37.776]
},
"properties": {
"title": "MapBox SF",
"description": "155 9th St, San Francisco",
"marker-color": "#fc4353",
"marker-size": "large",
"marker-symbol": "harbor"
}
}
];
L.mapbox.map('map-markers', 'examples.map-9ijuk24y')
.setView([37.8, -96], 4)
.markerLayer.setGeoJSON(geojson);
</script>
- title: 'Storytelling'
id: 'map-storytelling'
description: 'Tell stories like a walk through of locations told in Doyle's Sherlock Holmes short narrative, "The Adventure of the Bruce-Partington Plans".'
code: |
8000
<script>
var mapstories = L.mapbox.map('map-storytelling', 'examples.map-9ijuk24y')
.setView([51.5086, -0.1214], 13);
var markers = L.mapbox.markerLayer()
.loadURL('/mapbox.js/examples/storytelling.geojson')
.addTo(mapstories);
mapstories.markerLayer.on('ready', function(e) {
var chapters = [];
markers.eachLayer(function(chapter) {
chapters.push(chapter);
});
cycle(chapters);
});
function cycle(chapters) {
var i = 0;
function run() {
if (++i > chapters.length - 1) i = 0;
mapstories.setView(chapters[i].getLatLng(), 13);
chapters[i].openPopup();
window.setTimeout(run, 3000);
}
run();
}
</script>
- title: 'Data Visualizations'
id: 'map-dataviz'
description: 'Create choropleths from data using Leaflet's <a href="http://leafletjs.com/reference.html#geojson">L.geoJson</a>.'
code: |
<style>
.map-legend .swatch {
width:20px;
height:20px;
float:left;
margin-right:10px;
}
.leaflet-popup-close-button {
display: none;
}
.leaflet-popup-content-wrapper {
pointer-events: none;
}
</style>
<script src='./examples/us-states.js'></script>
<script>
var mapdataviz = L.mapbox.map('map-dataviz', 'examples.map-9ijuk24y')
.setView([37.8, -96], 4);
var popup = new L.Popup({ autoPan: false });
// statesData comes from the 'us-states.js' script included above
var statesLayer = L.geoJson(statesData, {
style: getStyle,
onEachFeature: onEachFeature
}).addTo(mapdataviz);
function getStyle(feature) {
return {
weight: 2,
opacity: 0.1,
color: 'black',
fillOpacity: 0.7,
fillColor: getColor(feature.properties.density)
};
}
// get color depending on population density value
function getColor(d) {
return d > 1000 ? '#8c2d04' :
d > 500 ? '#cc4c02' :
d > 200 ? '#ec7014' :
d > 100 ? '#fe9929' :
d > 50 ? '#fec44f' :
d > 20 ? '#fee391' :
d > 10 ? '#fff7bc' :
'#ffffe5';
}
function onEachFeature(feature, layer) {
layer.on({
mousemove: mousemove,
mouseout: mouseout,
click: zoomToFeature
});
}
var closeTooltip;
function mousemove(e) {
var layer = e.target;
popup.setLatLng(e.latlng);
popup.setContent('<div class="marker-title">' + layer.feature.properties.name + '</div>' +
layer.feature.properties.density + ' people per square mile');
if (!popup._map) popup.openOn(mapdataviz);
window.clearTimeout(closeTooltip);
// highlight feature
layer.setStyle({
weight: 3,
opacity: 0.3,
fillOpacity: 0.9
});
if (!L.Browser.ie && !L.Browser.opera) {
layer.bringToFront();
}
}
function mouseout(e) {
statesLayer.resetStyle(e.target);
closeTooltip = window.setTimeout(function() {
mapdataviz.closePopup();
}, 100);
}
function zoomToFeature(e) {
mapdataviz.fitBounds(e.target.getBounds());
}
mapdataviz.legendControl.addLegend(getLegendHTML());
function getLegendHTML() {
var grades = [0, 10, 20, 50, 100, 200, 500, 1000],
labels = [],
from, to;
for (var i = 0; i < grades.length; i++) {
from = grades[i];
to = grades[i + 1];
labels.push(
'<li><span class="swatch" style="background:' + getColor(from + 1) + '"></span> ' +
from + (to ? '–' + to : '+')) + '</li>';
}
return '<span>People per square mile</span><ul>' + labels.join('') + '</ul>';
}
</script>
---
{% include header.html %}
<div class='col12 pad2y space-bottom center clearfix'>
<div class='col8 margin2'>
<h1 class='space-bottom1'>Build maps the way you want</h1>
<p>Using the powerful MapBox Javascript API</p>
</div>
</div>
{% capture htmltop %}<html>
<head>
<meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no' />
<link href='//api.tiles.mapbox.com/mapbox.js/{{site.mapboxjs}}/mapbox.css' rel='stylesheet' />
<script src='//api.tiles.mapbox.com/mapbox.js/{{site.mapboxjs}}/mapbox.js'></script>
<style>#map { position:absolute; width:100%; height:100%; }</style>
</head>
<body>{% endcapture %}
{% capture htmlbottom %}</body>
</html>
{% endcapture %}
<div class='col10 margin1 clearfix keyline-all round space-bottom'>
<div class='clearfix col12 pad2'>
<div class='example clearfix tabs'>
{% for eg in page.examples %}
<a class='select-example col3 {% if forloop.index == 1 %}active{% endif %}' href='#active{{forloop.index}}'>{{eg.title}}</a>
{% endfor %}
</div>
</div>
<div id='examples' class='col12 clip sliding h active1 fill-light row10 clearfix'>
{% for example in page.examples %}
<div class='example animate col12 clearfix row10'>
<div class='sliding v active1 row10'>
<div class='col12 row10 animate'>
<div id='{{example.id}}' class='col12 row10'></div>
{{example.code}}
</div>
<div class='col12 row10 animate'>
<div class='row8 code pad1 keyline-bottom'>
{% highlight html %}{{htmltop}}<div id='{{example.id}}'></div>
{{example.code}}{{htmlbottom}}{% endhighlight %}
</div>
</div>
</div>
<div class='pad2y pad1x col12 pin-bottom fill-darken3 dark clearfix'>
<div class='col8 pad1x prose'>
{{example.description}}
</div>
<div class='col4 pad1x'>
<div class='tabs col12 clearfix'>
<a class='col6 toggle active' href='#active1'>Map</a>
<a class='col6 toggle icon sprocket' href='#active2'>Code</a>
</div>
</div>
</div>
</div>
{% endfor %}
</div>
</div>
<div class='pad2y'>
<div class='clearfix'>
<div class='col10 margin1 clearfix'>
<div class='col6 pad2'>
<h2 id='mapbox-and-leaflet' class='space-bottom1'>Leaflet built-in</h2>
<div class='prose'>
<p>MapBox.js is built on top of <a href='http://leafletjs.com/'>Leaflet</a> — an open-source mapping library. <a href='http://leafletjs.com/reference.html'>Leaflet's API</a> handles much of the fundamental operations of using maps. MapBox.js documentation should be read in conjunction with the <a href='http://leafletjs.com/reference.html'>Leaflet API reference</a>.</p>
</div>
</div>
<div class='col6 pad2'>
<h2 id='open-specs' class='space-bottom1'>Open</h2>
<div class='prose'>
<p>The source code is open source and available on <a href='//github.com/mapbox/mapbox.js/'>GitHub</a>. It takes advantage of open specifications like <a href='http://mapbox.com/developers/tilejson/'>TileJSON</a>, <a href='http://mapbox.com/developers/utfgrid/'>UTFGrid</a> and <a href='http://www.geojson.org/'>GeoJSON</a>.</p>
</div>
</div>
</div>
</div>
<div class='clearfix'>
<div class='col10 margin1 clearfix'>
<div class='col6 pad2'>
<h2 id='resources' class='space-bottom1'>A community to help</h2>
<div class='prose'>
<p>Have a question? Ask in <a href='//support.mapbox.com/discussions/mapboxjs'>support.mapbox.com</a>: we are here to help.</p>
</div>
</div>
<div class='col6 pad2'>
<h2 id='mobile' class='space-bottom1'>Optimized for mobile</h2>
<div class='prose'>
<p>MapBox.js is optimized for mobile devices and small screens by default. For additional tools for managing mobile maps, check out the <a href='{{site.baseurl}}/api/{{site.mapboxjs}}/#section-mobile'>Mobile section in the documentation</a>.</p>
</div>
</div>
</div>
</div>
<div class='clearfix pad2y'>
<div class='col10 margin1 center clearfix'>
<h2 id='browser-supported' class='space-bottom1'>Browser tested & supported</h2>
<div class='prose'>
<p>MapBox.js is compatible with IE8+ and <a href='http://browsehappy.com/'>modern browsers</a> like Chrome, Firefox, and Safari.</p>
</div>
</div>
</div>
<div class='clearfix pad2y'>
<div class='col10 margin1 keyline-all round'>
<div class='pad2'>
<h2 id='getting-started' class='space-bottom1'>Get started fast</h2>
<div class='prose'>
<p>MapBox.js is hosted on the same reliable and speedy CDN that powers MapBox tiles. There's no API key to use it. All that's needed is a reference to the script & CSS in your HTML.</p>
{% highlight html %}<link href='//api.tiles.mapbox.com/mapbox.js/{{site.mapboxjs}}/mapbox.css' rel='stylesheet' />
<script src='//api.tiles.mapbox.com/mapbox.js/{{site.mapboxjs}}/mapbox.js'></script>{% endhighlight %}
<a href='#standalone' id='trigger-standalone' class='small strong'>Need MapBox.js without Leaflet bundled?</a>
</div>
</div>
<div id='standalone' class='note hidden'>
<h3 id='standalone' class='space-bottom1'>MapBox.js standalone</h3>
<div class='prose'>
<p>A standalone version of MapBox.js is also available without Leaflet included. Add the following in your HTML document:</p>
{% highlight html %}<link href='//api.tiles.mapbox.com/mapbox.js/{{site.mapboxjs}}/mapbox.standalone.css' rel='stylesheet' />
<script src='//api.tiles.mapbox.com/mapbox.js/{{site.mapboxjs}}/mapbox.standalone.js'></script>{% endhighlight %}
<small>Note: <strong>Leaflet 0.7</strong> or greater is required.</small>
</div>
</div>
</div>
</div>
</div>
<script>
$(function() {
if (window.location.hash === '#standalone') $('#standalone').removeClass('hidden');
var docs = new Docs();
$('.select-example').click(function() {
var current = $(this).attr('href').split('#').pop();
var exmaples = document.getElementById('examples');
// Remove the activeN value from the container
examples.className = examples.className.replace(/active[0-9]+/, current);
$(this).addClass('active').siblings().removeClass('active');
return false;
});
$('#trigger-standalone').click(function() {
$('#standalone').removeClass('hidden');
return false;
});
$('.toggle').click(function() {
var current = $(this).attr('href').split('#').pop();
$(this).addClass('active').siblings().removeClass('active');
$(this)
.parents('.example')
.find('.v')
.removeClass('active1 active2')
.addClass(current);
return false;
});
});
</script>
{% include developers-footer.html %}
You can’t perform that action at this time.