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

Better error messages #12098

Closed
wants to merge 11 commits into from
15 changes: 14 additions & 1 deletion src/ui/camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import type {PointLike} from '@mapbox/point-geometry';
import {Aabb, Frustum} from '../util/primitives.js';
import type {PaddingOptions} from '../geo/edge_insets.js';
import type {Vec3} from 'gl-matrix';
import { zoom } from 'd3';

/**
* A helper type: converts all Object type values to non-maybe types.
Expand Down Expand Up @@ -317,6 +318,13 @@ class Camera extends Evented {
* });
*/
zoomTo(zoom: number, options: ? AnimationOptions, eventData?: Object): this {
if (typeof zoom !== 'number'){
this.fire(new ErrorEvent(new Error(
`zoom requires a number not ${zoom}`)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
`zoom requires a number not ${zoom}`)));
`map.zoomTo() requires a number in the first argument. ${typeof zoom} provided`)));

return;
}


return this.easeTo(extend({
zoom
}, options), eventData);
Expand Down Expand Up @@ -1446,6 +1454,11 @@ class Camera extends Evented {
* @see [Example: Fly to a location based on scroll position](https://www.mapbox.com/mapbox-gl-js/example/scroll-fly-to/)
*/
flyTo(options: EasingOptions & {preloadOnly?: boolean}, eventData?: Object): this {
if (typeof eventData !== 'object') {
this.fire(new ErrorEvent(new Error(
`map.flyTo requires object in first argument, ${typeof eventData} provided`)));
return;
}
// Fall through to jumpTo if user has set prefers-reduced-motion
if (!options.essential && browser.prefersReducedMotion) {
const coercedOptions = pick(options, ['center', 'zoom', 'bearing', 'pitch', 'around']);
Expand Down Expand Up @@ -1756,4 +1769,4 @@ function addAssertions(camera: Camera) { //eslint-disable-line

let canary; //eslint-disable-line

export default Camera;
export default Camera;