Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs sprint primary pull request #9607

Merged
merged 74 commits into from
Apr 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
410fa94
[docsprint] Clarify meaning of Map#isSourceLoaded (#9589)
adrianababakanian Apr 20, 2020
9f18918
[docsprint] Add geolocate trigger example (#9552)
samfader Apr 20, 2020
d54cef2
[docsprint] Add inline snippet to marker#addTo (#9592)
HeyStenson Apr 20, 2020
0f7c8b9
[docsprint] Add inline snippet and related examples to popup.setHTML …
danswick Apr 20, 2020
c625efa
Add inline and related example for panTo (#9547)
Apr 20, 2020
4ed7ca8
Add inline snippet to LngLatBounds.contains (#9548)
jbranigan Apr 20, 2020
254f29f
[docsprint] Add inline snippet and examples to map.jumpTo (#9549)
jstratman Apr 20, 2020
c201f06
added inline and tutorial examples for map.getCenter (#9551)
jstratman Apr 20, 2020
74fc5ef
add example for Marker class setLngLat (#9553)
Apr 20, 2020
08c55fb
added examples to get- and setLayoutProperty (#9554)
jstratman Apr 20, 2020
10ed623
add inline snippet and examples to map.triggerRepaint (#9555)
jstratman Apr 20, 2020
6874d42
CameraOptions - update pitch and bearing definitions, add inline code…
Apr 20, 2020
a5eed0e
add inline code snippet to map.showTileBoundaries (#9557)
jstratman Apr 20, 2020
d821161
Mark Debug namespace as private to hide it from the docs (#9558)
Apr 20, 2020
f7e35a9
[docsprint] Add detail to docs on setFeatureState, removeFeatureState…
Apr 20, 2020
319c5eb
[docsprint] map.on: remove extra on section, link to event types, add…
danswick Apr 20, 2020
0f4a3f0
add examples to open and close popup events (#9565)
Apr 20, 2020
ce1e98d
[docsprint] Clarify how map.moveLayer works (#9566)
Apr 20, 2020
0711003
[doscprint] add links to EPSG and minor example changes for LngLat (#…
geografa Apr 20, 2020
d536278
document the layer object's properties in addLayer (#9571)
Apr 20, 2020
8279ca5
[docsprint] Add inline snippet and examples to popup.addTo (#9572)
jstratman Apr 20, 2020
3f39525
Add inline example for trackPointer (#9575)
Apr 20, 2020
41f52a0
Add inline example for Popup#getElement (#9576)
Apr 20, 2020
e5954f2
[docsprint] Add inline examples for Point & PointLike types (#9577)
adrianababakanian Apr 20, 2020
6b419c2
[docsprint] Cleanup doc for MapBoxZoomEvent (#9564)
Apr 20, 2020
73bc120
Describe map style object returned by Map#getStyle (#9579)
adrianababakanian Apr 20, 2020
21a7fe9
[docsprint] Add inline example for getClusterLeaves (#9580)
Apr 20, 2020
1d27338
[docsprint] PaddingOptions - update definition, example, and related …
pjleonard37 Apr 20, 2020
cde46be
[docsprint] Add inline snippet to marker#setPopup, marker#getPopup, a…
HeyStenson Apr 20, 2020
6228c72
update setFilter jsdoc (#9586)
Apr 20, 2020
ea0f47e
add more details to getSource (#9587)
Apr 20, 2020
48a3546
add clearStorage example (#9588)
Apr 20, 2020
93774c6
[docsprint] Add documentation for RequestParameters (#9573)
Apr 20, 2020
523a445
[docsprint] Add inline example for setZoomRate and setWheelZoomRate o…
Apr 20, 2020
176e092
Add inline examples for map zoom-related methods (#9594)
adrianababakanian Apr 20, 2020
e8aab02
[docsprint] Add example to MapMouseEvent (#9595)
Apr 20, 2020
4bbd7f0
Add examples for GeolocateControl events (#9596)
adrianababakanian Apr 20, 2020
b0623b8
[docsprint] Add example to MapDataEvent (#9597)
Apr 20, 2020
a55e8e8
add example for getLngLat (#9591)
dpdiliberto Apr 20, 2020
4866026
suggested edits for clarifying mouse events
colleenmcginnis Apr 16, 2020
3379e24
Small grammar fix: "optional the `layerId`" -> "the optional `layerId"
Apr 22, 2020
94217f9
Remove stray `}`; Add missing `);`
Apr 22, 2020
72a6f6f
Update src/geo/lng_lat_bounds.js
Apr 23, 2020
efff4fa
Update src/source/geojson_source.js
Apr 23, 2020
2659433
Update src/ui/camera.js
Apr 23, 2020
1cea620
Update src/ui/map.js
Apr 23, 2020
da7fbf4
Update src/util/ajax.js
Apr 23, 2020
cf16abe
Update src/ui/events.js
Apr 23, 2020
95e2773
Update src/ui/events.js
Apr 23, 2020
4cf5c75
Update src/ui/events.js
Apr 23, 2020
173196b
Update src/ui/events.js
Apr 23, 2020
05a1650
Update src/ui/map.js
Apr 23, 2020
165afe8
Update src/ui/camera.js
Apr 23, 2020
001da7b
Update src/ui/events.js
Apr 23, 2020
1c22562
Update src/ui/events.js
Apr 23, 2020
8a8d020
Update src/ui/marker.js
Apr 23, 2020
d56984a
Update src/ui/marker.js
Apr 23, 2020
35e14e9
Update src/ui/marker.js
Apr 23, 2020
b0ad7ef
Apply suggestions from code review
Apr 23, 2020
2d2597f
Update pitch param definition; add Display buildings in 3D example
Apr 23, 2020
b8a3249
whitespace adjustments
Apr 23, 2020
fc3fd85
remove example object, light formatting and copyediting
Apr 23, 2020
944a324
Apply suggestions from code review
Apr 23, 2020
14385ab
Apply suggestions from code review
Apr 23, 2020
9d4aee9
Update src/ui/camera.js
danswick Apr 23, 2020
f6285e8
Update src/ui/camera.js
danswick Apr 23, 2020
fe8ce62
Update src/ui/camera.js
danswick Apr 23, 2020
ff6bfef
Update src/ui/events.js
danswick Apr 23, 2020
b417ce0
Update src/ui/events.js
danswick Apr 23, 2020
c5923cd
Update src/util/ajax.js
danswick Apr 23, 2020
6c67225
Update src/ui/control/geolocate_control.js
danswick Apr 23, 2020
b90fcd2
Update src/ui/map.js
danswick Apr 24, 2020
ab887c4
Update src/ui/map.js
danswick Apr 24, 2020
b01e962
Fix typo in src/ui/events.js
karimnaaji Apr 24, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/geo/lng_lat.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ export const earthRadius = 6371008.8;

/**
* A `LngLat` object represents a given longitude and latitude coordinate, measured in degrees.
* These coordinates are based on the [WGS84 (EPSG:4326) standard](https://en.wikipedia.org/wiki/World_Geodetic_System#WGS84).
*
* Mapbox GL uses longitude, latitude coordinate order (as opposed to latitude, longitude) to match GeoJSON.
* Mapbox GL uses longitude, latitude coordinate order (as opposed to latitude, longitude) to match the
* [GeoJSON specification](https://tools.ietf.org/html/rfc7946).
*
* Note that any Mapbox GL method that accepts a `LngLat` object as an argument or option
* can also accept an `Array` of two numbers and will perform an implicit conversion.
Expand All @@ -22,7 +24,8 @@ export const earthRadius = 6371008.8;
* @param {number} lng Longitude, measured in degrees.
* @param {number} lat Latitude, measured in degrees.
* @example
* var ll = new mapboxgl.LngLat(-73.9749, 40.7736);
* var ll = new mapboxgl.LngLat(-123.9749, 40.7736);
* ll.lng; // = -123.9749
katydecorah marked this conversation as resolved.
Show resolved Hide resolved
* @see [Get coordinates of the mouse pointer](https://www.mapbox.com/mapbox-gl-js/example/mouse-position/)
* @see [Display a popup](https://www.mapbox.com/mapbox-gl-js/example/popup/)
* @see [Highlight features within a bounding box](https://www.mapbox.com/mapbox-gl-js/example/using-box-queryrenderedfeatures/)
Expand Down
9 changes: 9 additions & 0 deletions src/geo/lng_lat_bounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,15 @@ class LngLatBounds {
*
* @param {LngLatLike} lnglat geographic point to check against.
* @returns {boolean} True if the point is within the bounding box.
* @example
* var llb = new mapboxgl.LngLatBounds(
* new mapboxgl.LngLat(-73.9876, 40.7661),
* new mapboxgl.LngLat(-73.9397, 40.8002)
* );
*
* var ll = new mapboxgl.LngLat(-73.9567, 40.7789);
*
* console.log(llb.contains(ll)); // = true
*/
contains(lnglat: LngLatLike) {
const {lng, lat} = LngLat.convert(lnglat);
Expand Down
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ const exported = {
*
* @function clearStorage
* @param {Function} callback Called with an error argument if there is an error.
* @example
* mapboxgl.clearStorage();
*/
clearStorage(callback?: (err: ?Error) => void) {
clearTileCache(callback);
Expand Down
16 changes: 16 additions & 0 deletions src/source/geojson_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,22 @@ class GeoJSONSource extends Evented implements Source {
* @param offset The number of features to skip (e.g. for pagination).
* @param callback A callback to be called when the features are retrieved (`(error, features) => { ... }`).
* @returns {GeoJSONSource} this
* @example
danswick marked this conversation as resolved.
Show resolved Hide resolved
* // Retrieve cluster leaves on click
* map.on('click', 'clusters', function(e) {
* var features = map.queryRenderedFeatures(e.point, {
* layers: ['clusters']
* });
*
* var clusterId = features[0].properties.cluster_id;
* var pointCount = features[0].properties.point_count;
* var clusterSource = map.getSource('clusters');
*
* clusterSource.getClusterLeaves(clusterId, pointCount, 0, function(error, features) {
* // Print cluster leaves in the console
* console.log('Cluster leaves:', error, features);
* })
* });
*/
getClusterLeaves(clusterId: number, limit: number, offset: number, callback: Callback<Array<GeoJSONFeature>>) {
this.actor.send('geojson.getClusterLeaves', {
Expand Down
85 changes: 78 additions & 7 deletions src/ui/camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,28 @@ import type {PaddingOptions} from '../geo/edge_insets';
* @typedef {Object} CameraOptions
* @property {LngLatLike} center The desired center.
* @property {number} zoom The desired zoom level.
* @property {number} bearing The desired bearing, in degrees. The bearing is the compass direction that
* is "up"; for example, a bearing of 90° orients the map so that east is up.
* @property {number} pitch The desired pitch, in degrees.
* @property {number} bearing The desired bearing in degrees. The bearing is the compass direction that
* is "up". For example, `bearing: 90` orients the map so that east is up.
* @property {number} pitch The desired pitch in degrees. The pitch is the angle towards the horizon
* measured in degrees with a range between 0 and 60 degrees. For example, pitch: 0 provides the appearance
* of looking straight down at the map, while pitch: 60 tilts the user's perspective towards the horizon.
* Increasing the pitch value is often used to display 3D objects.
* @property {LngLatLike} around If `zoom` is specified, `around` determines the point around which the zoom is centered.
* @property {PaddingOptions} padding Dimensions in pixels applied on each side of the viewport for shifting the vanishing point.
* @example
* // set the map's initial perspective with CameraOptions
* var map = new mapboxgl.Map({
* container: 'map',
* style: 'mapbox://styles/mapbox/streets-v11',
* center: [-73.5804, 45.53483],
* pitch: 60,
* bearing: -60,
* zoom: 10
* });
* @see [Set pitch and bearing](https://docs.mapbox.com/mapbox-gl-js/example/set-perspective/)
* @see [Jump to a series of locations](https://docs.mapbox.com/mapbox-gl-js/example/jump-to/)
* @see [Fly to a location](https://docs.mapbox.com/mapbox-gl-js/example/flyto/)
* @see [Display buildings in 3D](https://docs.mapbox.com/mapbox-gl-js/example/3d-buildings/)
*/
export type CameraOptions = {
center?: LngLatLike,
Expand Down Expand Up @@ -71,14 +88,28 @@ export type AnimationOptions = {
};

/**
* Options for setting padding on a call to {@link Map#fitBounds}. All properties of this object must be
* Options for setting padding on calls to methods such as {@link Map#fitBounds}, {@link Map#fitScreenCoordinates}, and {@link Map#setPadding}. Adjust these options to set the amount of padding in pixels added to the edges of the canvas. Set a uniform padding on all edges or individual values for each edge. All properties of this object must be
* non-negative integers.
*
* @typedef {Object} PaddingOptions
* @property {number} top Padding in pixels from the top of the map canvas.
* @property {number} bottom Padding in pixels from the bottom of the map canvas.
* @property {number} left Padding in pixels from the left of the map canvas.
* @property {number} right Padding in pixels from the right of the map canvas.
*
* @example
* var bbox = [[-79, 43], [-73, 45]];
* map.fitBounds(bbox, {
* padding: {top: 10, bottom:25, left: 15, right: 5}
* });
*
* @example
* var bbox = [[-79, 43], [-73, 45]];
* map.fitBounds(bbox, {
* padding: 20
* });
* @see [Fit to the bounds of a LineString](https://docs.mapbox.com/mapbox-gl-js/example/zoomto-linestring/)
* @see [Fit a map to a bounding box](https://docs.mapbox.com/mapbox-gl-js/example/fitbounds/)
*/

class Camera extends Evented {
Expand Down Expand Up @@ -119,6 +150,12 @@ class Camera extends Evented {
*
* @memberof Map#
* @returns The map's geographical centerpoint.
* @example
* // return a LngLat object such as {lng: 0, lat: 0}
* var center = map.getCenter();
* // access longitude and latitude values directly
* var {longitude, latitude} = map.getCenter();
* @see Tutorial: [Use Mapbox GL JS in a React app](https://docs.mapbox.com/help/tutorials/use-mapbox-gl-js-with-react/#store-the-new-coordinates)
*/
getCenter(): LngLat { return new LngLat(this.transform.center.lng, this.transform.center.lat); }

Expand Down Expand Up @@ -156,15 +193,21 @@ class Camera extends Evented {
}

/**
* Pans the map to the specified location, with an animated transition.
* Pans the map to the specified location with an animated transition.
*
* @memberof Map#
* @param lnglat The location to pan the map to.
* @param options Options object
* @param options Options describing the destination and animation of the transition.
karimnaaji marked this conversation as resolved.
Show resolved Hide resolved
* @param eventData Additional properties to be added to event objects of events triggered by this method.
* @fires movestart
* @fires moveend
* @returns {Map} `this`
* @example
* map.panTo([-74, 38]);
* @example
* // Specify that the panTo animation should last 5000 milliseconds.
* map.panTo([-74, 38], {duration: 5000});
* @see [Update a feature in realtime](https://docs.mapbox.com/mapbox-gl-js/example/live-update-feature/)
*/
panTo(lnglat: LngLatLike, options?: AnimationOptions, eventData?: Object) {
return this.easeTo(extend({
Expand All @@ -177,6 +220,8 @@ class Camera extends Evented {
*
* @memberof Map#
* @returns The map's current zoom level.
* @example
* map.getZoom();
*/
getZoom(): number { return this.transform.zoom; }

Expand All @@ -194,7 +239,7 @@ class Camera extends Evented {
* @fires zoomend
* @returns {Map} `this`
* @example
* // zoom the map to 5
* // Zoom to the zoom level 5 without an animated transition
* map.setZoom(5);
*/
setZoom(zoom: number, eventData?: Object) {
Expand All @@ -216,6 +261,14 @@ class Camera extends Evented {
* @fires moveend
* @fires zoomend
* @returns {Map} `this`
* @example
* // Zoom to the zoom level 5 without an animated transition
* map.zoomTo(5);
* // Zoom to the zoom level 8 with an animated transition
* map.zoomTo(8, {
* duration: 2000,
* offset: [100, 50]
* });
*/
zoomTo(zoom: number, options: ? AnimationOptions, eventData?: Object) {
return this.easeTo(extend({
Expand All @@ -236,6 +289,9 @@ class Camera extends Evented {
* @fires moveend
* @fires zoomend
* @returns {Map} `this`
* @example
* // zoom the map in one level with a custom animation duration
* map.zoomIn({duration: 1000});
*/
zoomIn(options?: AnimationOptions, eventData?: Object) {
this.zoomTo(this.getZoom() + 1, options, eventData);
Expand All @@ -255,6 +311,9 @@ class Camera extends Evented {
* @fires moveend
* @fires zoomend
* @returns {Map} `this`
* @example
* // zoom the map out one level with a custom animation offset
* map.zoomOut({offset: [80, 60]});
*/
zoomOut(options?: AnimationOptions, eventData?: Object) {
this.zoomTo(this.getZoom() - 1, options, eventData);
Expand Down Expand Up @@ -631,6 +690,18 @@ class Camera extends Evented {
* @fires zoomend
* @fires pitchend
* @returns {Map} `this`
* @example
* // jump to coordinates at current zoom
* map.jumpTo({center: [0, 0]});
* // jump with zoom, pitch, and bearing options
* map.jumpTo({
* center: [0, 0],
* zoom: 8,
* pitch: 45,
* bearing: 90
* });
* @see [Jump to a series of locations](https://docs.mapbox.com/mapbox-gl-js/example/jump-to/)
* @see [Update a feature in realtime](https://docs.mapbox.com/mapbox-gl-js/example/live-update-feature/)
*/
jumpTo(options: CameraOptions, eventData?: Object) {
this.stop();
Expand Down
96 changes: 92 additions & 4 deletions src/ui/control/geolocate_control.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,10 +406,23 @@ class GeolocateControl extends Evented {
}

/**
* Trigger a geolocation
*
* @returns {boolean} Returns `false` if called before control was added to a map, otherwise returns `true`.
*/
* Programmatically request and move the map to the user's location.
*
* @returns {boolean} Returns `false` if called before control was added to a map, otherwise returns `true`.
* @example
* // Initialize the geolocate control.
* var geolocate = new mapboxgl.GeolocateControl({
* positionOptions: {
* enableHighAccuracy: true
* },
* trackUserLocation: true
* });
* // Add the control to the map.
* map.addControl(geolocate);
* map.on('load', function() {
* geolocate.trigger();
* });
*/
trigger() {
if (!this._setup) {
warnOnce('Geolocate control triggered before added to a map');
Expand Down Expand Up @@ -552,6 +565,21 @@ export default GeolocateControl;
* @memberof GeolocateControl
* @instance
* @property {Position} data The returned [Position](https://developer.mozilla.org/en-US/docs/Web/API/Position) object from the callback in [Geolocation.getCurrentPosition()](https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/getCurrentPosition) or [Geolocation.watchPosition()](https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/watchPosition).
* @example
* // Initialize the geolocate control.
* var geolocate = new mapboxgl.GeolocateControl({
* positionOptions: {
* enableHighAccuracy: true
* },
* trackUserLocation: true
* });
* // Add the control to the map.
* map.addControl(geolocate);
* // Set an event listener that fires
* // when a geolocate event occurs.
* geolocate.on('geolocate', function() {
* console.log('A geolocate event has occurred.')
* });
*
*/

Expand All @@ -562,6 +590,21 @@ export default GeolocateControl;
* @memberof GeolocateControl
* @instance
* @property {PositionError} data The returned [PositionError](https://developer.mozilla.org/en-US/docs/Web/API/PositionError) object from the callback in [Geolocation.getCurrentPosition()](https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/getCurrentPosition) or [Geolocation.watchPosition()](https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/watchPosition).
* @example
* // Initialize the geolocate control.
* var geolocate = new mapboxgl.GeolocateControl({
* positionOptions: {
* enableHighAccuracy: true
* },
* trackUserLocation: true
* });
* // Add the control to the map.
* map.addControl(geolocate);
* // Set an event listener that fires
* // when an error event occurs.
* geolocate.on('error', function() {
* console.log('An error event has occurred.')
* });
*
*/

Expand All @@ -572,6 +615,21 @@ export default GeolocateControl;
* @memberof GeolocateControl
* @instance
* @property {Position} data The returned [Position](https://developer.mozilla.org/en-US/docs/Web/API/Position) object from the callback in [Geolocation.getCurrentPosition()](https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/getCurrentPosition) or [Geolocation.watchPosition()](https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/watchPosition).
* @example
* // Initialize the geolocate control.
* var geolocate = new mapboxgl.GeolocateControl({
* positionOptions: {
* enableHighAccuracy: true
* },
* trackUserLocation: true
* });
* // Add the control to the map.
* map.addControl(geolocate);
* // Set an event listener that fires
* // when an outofmaxbounds event occurs.
* geolocate.on('outofmaxbounds', function() {
* console.log('An outofmaxbounds event has occurred.')
* });
*
*/

Expand All @@ -581,6 +639,21 @@ export default GeolocateControl;
* @event trackuserlocationstart
* @memberof GeolocateControl
* @instance
* @example
* // Initialize the geolocate control.
* var geolocate = new mapboxgl.GeolocateControl({
* positionOptions: {
* enableHighAccuracy: true
* },
* trackUserLocation: true
* });
* // Add the control to the map.
* map.addControl(geolocate);
* // Set an event listener that fires
* // when a trackuserlocationstart event occurs.
* geolocate.on('trackuserlocationstart', function() {
* console.log('A trackuserlocationstart event has occurred.')
* });
*
*/

Expand All @@ -590,5 +663,20 @@ export default GeolocateControl;
* @event trackuserlocationend
* @memberof GeolocateControl
* @instance
* @example
* // Initialize the geolocate control.
* var geolocate = new mapboxgl.GeolocateControl({
* positionOptions: {
* enableHighAccuracy: true
* },
* trackUserLocation: true
* });
* // Add the control to the map.
* map.addControl(geolocate);
* // Set an event listener that fires
* // when a trackuserlocationend event occurs.
* geolocate.on('trackuserlocationend', function() {
* console.log('A trackuserlocationend event has occurred.')
* });
*
*/
Loading