Skip to content

Commit 0d38314

Browse files
committed
Merge remote-tracking branch 'origin/mb-pages'
2 parents 76497fb + c95f0cd commit 0d38314

File tree

6 files changed

+367
-254
lines changed

6 files changed

+367
-254
lines changed

docs/_layouts/default.html

Lines changed: 193 additions & 253 deletions
Large diffs are not rendered by default.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
layout: example
3+
category: example
4+
title: Restrict map panning to an area
5+
description: Prevent a map from being panned to a different place by setting <code>maxBounds</code>.
6+
---
7+
<div id='map'></div>
8+
<script>
9+
10+
// Set bounds to New York, New York
11+
var bounds = [
12+
[-74.04728500751165, 40.68392799015035], // Southwest coordinates
13+
[-73.91058699000139, 40.87764500765852] // Northeast coordinates
14+
];
15+
16+
var map = new mapboxgl.Map({
17+
container: 'map',
18+
style: 'mapbox://styles/mapbox/streets-v8',
19+
center: [-73.9978, 40.7209],
20+
zoom: 13,
21+
maxBounds: bounds // Sets bounds as max
22+
});
23+
</script>
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
---
2+
layout: example
3+
category: example
4+
title: Toggle interactions
5+
description: Enable or disable UI handlers on a map.
6+
---
7+
<style>
8+
.listing-group {
9+
font: 12px/20px 'Helvetica Neue', Arial, Helvetica, sans-serif;
10+
font-weight: 600;
11+
position: absolute;
12+
top: 10px;
13+
right: 10px;
14+
z-index: 1;
15+
border-radius: 3px;
16+
max-width: 20%;
17+
color: #fff;
18+
}
19+
20+
.listing-group input[type=checkbox]:first-child + label {
21+
border-radius: 3px 3px 0 0;
22+
}
23+
24+
.listing-group label:last-child {
25+
border-radius: 0 0 3px 3px;
26+
border: none;
27+
}
28+
29+
.listing-group input[type=checkbox] {
30+
display: none;
31+
}
32+
33+
.listing-group input[type=checkbox] + label {
34+
background-color: #3386c0;
35+
display: block;
36+
cursor: pointer;
37+
padding: 10px;
38+
border-bottom: 1px solid rgba(0, 0, 0, 0.25);
39+
}
40+
41+
.listing-group input[type=checkbox] + label {
42+
background-color: #3386c0;
43+
text-transform: capitalize;
44+
}
45+
46+
.listing-group input[type=checkbox] + label:hover,
47+
.listing-group input[type=checkbox]:checked + label {
48+
background-color: #4ea0da;
49+
}
50+
51+
.listing-group input[type=checkbox]:checked + label:before {
52+
content: '✔';
53+
margin-right: 5px;
54+
}
55+
</style>
56+
<div id='map'></div>
57+
<nav id='listing-group' class='listing-group'>
58+
<input type='checkbox' id='scrollZoom' checked='checked'>
59+
<label for='scrollZoom'>Scroll zoom</label>
60+
<input type='checkbox' id='boxZoom' checked='checked'>
61+
<label for='boxZoom'>Box zoom</label>
62+
<input type='checkbox' id='dragRotate' checked='checked'>
63+
<label for='dragRotate'>Drag rotate</label>
64+
<input type='checkbox' id='dragPan' checked='checked'>
65+
<label for='dragPan'>Drag pan</label>
66+
<input type='checkbox' id='keyboard' checked='checked'>
67+
<label for='keyboard'>Keyboard</label>
68+
<input type='checkbox' id='doubleClickZoom' checked='checked'>
69+
<label for='doubleClickZoom'>Double click zoom</label>
70+
<input type='checkbox' id='touchZoomRotate' checked='checked'>
71+
<label for='touchZoomRotate'>Touch zoom rotate</label>
72+
</nav>
73+
74+
<script>
75+
var map = new mapboxgl.Map({
76+
container: 'map',
77+
style: 'mapbox://styles/mapbox/streets-v8',
78+
center: [-77.04, 38.907],
79+
zoom: 11.15
80+
});
81+
82+
document.getElementById('listing-group').addEventListener('change', function(e) {
83+
var handler = e.target.id;
84+
if (e.target.checked) {
85+
map[handler].enable();
86+
} else {
87+
map[handler].disable();
88+
}
89+
});
90+
</script>
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
layout: example
3+
category: example
4+
title: Animate a point
5+
description: Animate the position of a point by updating a GeoJSON source on each frame.
6+
---
7+
<div id='map'></div>
8+
<script>
9+
var map = new mapboxgl.Map({
10+
container: 'map',
11+
style: 'mapbox://styles/mapbox/streets-v8',
12+
center: [0, 0],
13+
zoom: 2
14+
});
15+
16+
var radius = 20;
17+
18+
function pointOnCircle(angle) {
19+
return {
20+
"type": "Point",
21+
"coordinates": [
22+
Math.cos(angle) * radius,
23+
Math.sin(angle) * radius
24+
]
25+
};
26+
}
27+
28+
map.on('load', function () {
29+
// Add a source and layer displaying a point which will be animated in a circle.
30+
map.addSource('point', {
31+
"type": "geojson",
32+
"data": pointOnCircle(0)
33+
});
34+
35+
map.addLayer({
36+
"id": "point",
37+
"source": "point",
38+
"type": "circle",
39+
"paint": {
40+
"circle-radius": 10,
41+
"circle-color": "#007cbf"
42+
}
43+
});
44+
45+
function animateMarker(timestamp) {
46+
// Update the data to a new position based on the animation timestamp. The
47+
// divisor in the expression `timestamp / 1000` controls the animation speed.
48+
map.getSource('point').setData(pointOnCircle(timestamp / 1000));
49+
50+
// Request the next frame of the animation.
51+
requestAnimationFrame(animateMarker);
52+
}
53+
54+
// Start the animation.
55+
animateMarker(0);
56+
});
57+
</script>

js/ui/map.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ util.extend(Map.prototype, /** @lends Map.prototype */{
527527
* Set the filter for a given style layer.
528528
*
529529
* @param {string} layer ID of a layer
530-
* @param {Array} filter filter specification, as defined in the [Style Specification](https://www.mapbox.com/mapbox-gl-style-spec/#filter)
530+
* @param {Array} filter filter specification, as defined in the [Style Specification](https://www.mapbox.com/mapbox-gl-style-spec/#types-filter)
531531
* @returns {Map} `this`
532532
*/
533533
setFilter: function(layer, filter) {

js/ui/popup.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ var LngLat = require('../geo/lng_lat');
1313
* @param {Object} options
1414
* @param {boolean} options.closeButton
1515
* @param {boolean} options.closeOnClick
16+
* @param {string} options.anchor - One of "top", "bottom", "left", "right", "top-left",
17+
* "top-right", "bottom-left", or "bottom-right", describing where the popup's anchor
18+
* relative to the coordinate set via `setLngLat`.
1619
* @example
1720
* var tooltip = new mapboxgl.Popup()
1821
* .setLngLat(e.lngLat)

0 commit comments

Comments
 (0)