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

Map class cleanup #7060

Merged
merged 3 commits into from
Aug 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
40 changes: 38 additions & 2 deletions src/geo/transform.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @flow

import LngLat from './lng_lat';

import LngLatBounds from './lng_lat_bounds';
import Point from '@mapbox/point-geometry';
import Coordinate from './coordinate';
import { wrap, clamp } from '../util/util';
Expand Down Expand Up @@ -52,7 +52,7 @@ class Transform {
this._minZoom = minZoom || 0;
this._maxZoom = maxZoom || 22;

this.latRange = [-85.05113, 85.05113];
this.setMaxBounds();

this.width = 0;
this.height = 0;
Expand Down Expand Up @@ -401,6 +401,42 @@ class Transform {
return new Point(p[0] / p[3], p[1] / p[3]);
}

/**
* Returns the map's geographical bounds. When the bearing or pitch is non-zero, the visible region is not
* an axis-aligned rectangle, and the result is the smallest bounds that encompasses the visible region.
*/
getBounds(): LngLatBounds {
return new LngLatBounds()
.extend(this.pointLocation(new Point(0, 0)))
.extend(this.pointLocation(new Point(this.width, 0)))
.extend(this.pointLocation(new Point(this.width, this.height)))
.extend(this.pointLocation(new Point(0, this.height)));
}

/**
* Returns the maximum geographical bounds the map is constrained to, or `null` if none set.
*/
getMaxBounds(): LngLatBounds | null {
if (!this.latRange || this.latRange.length !== 2 ||
!this.lngRange || this.lngRange.length !== 2) return null;

return new LngLatBounds([this.lngRange[0], this.latRange[0]], [this.lngRange[1], this.latRange[1]]);
}

/**
* Sets or clears the map's geographical constraints.
*/
setMaxBounds(bounds?: LngLatBounds) {
if (bounds) {
this.lngRange = [bounds.getWest(), bounds.getEast()];
this.latRange = [bounds.getSouth(), bounds.getNorth()];
this._constrain();
} else {
this.lngRange = null;
this.latRange = [-85.05113, 85.05113];
}
}

/**
* Calculate the posMatrix that, given a tile coordinate, would be used to display the tile on a map.
* @param {UnwrappedTileID} unwrappedTileID;
Expand Down
6 changes: 4 additions & 2 deletions src/style/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -899,13 +899,15 @@ class Style extends Evented {
}

const sourceResults = [];
const queryCoordinates = queryGeometry.map((p) => transform.pointCoordinate(p));

for (const id in this.sourceCaches) {
if (params.layers && !includedSources[id]) continue;
sourceResults.push(
queryRenderedFeatures(
this.sourceCaches[id],
this._layers,
queryGeometry.worldCoordinate,
queryCoordinates,
params,
transform)
);
Expand All @@ -918,7 +920,7 @@ class Style extends Evented {
queryRenderedSymbols(
this._layers,
this.sourceCaches,
queryGeometry.viewport,
queryGeometry,
params,
this.placement.collisionIndex,
this.placement.retainedQueryData)
Expand Down
Loading