Seperate internal and API methods for the map

This commit is contained in:
Tobias Kohr
2019-09-23 17:23:32 +02:00
parent 66746a61bb
commit d4c1589a01
16 changed files with 86 additions and 53 deletions

View File

@@ -27,6 +27,7 @@ import LayerGroup from './layer/Group.js';
import {hasArea} from './size.js';
import {DROP} from './structs/PriorityQueue.js';
import {create as createTransform, apply as applyTransform} from './transform.js';
import { toUserCoordinate } from './proj.js';
/**
@@ -545,7 +546,7 @@ class PluggableMap extends BaseObject {
if (!this.frameState_) {
return;
}
const coordinate = this.getCoordinateFromPixel(pixel);
const coordinate = this.getCoordinateFromPixelExternal(pixel);
opt_options = opt_options !== undefined ? opt_options :
/** @type {AtPixelOptions} */ ({});
const hitTolerance = opt_options.hitTolerance !== undefined ?
@@ -617,7 +618,7 @@ class PluggableMap extends BaseObject {
if (!this.frameState_) {
return false;
}
const coordinate = this.getCoordinateFromPixel(pixel);
const coordinate = this.getCoordinateFromPixelExternal(pixel);
opt_options = opt_options !== undefined ? opt_options :
/** @type {AtPixelOptions} */ ({});
const layerFilter = opt_options.layerFilter !== undefined ? opt_options.layerFilter : TRUE;
@@ -634,7 +635,7 @@ class PluggableMap extends BaseObject {
* @api
*/
getEventCoordinate(event) {
return this.getCoordinateFromPixel(this.getEventPixel(event));
return this.getCoordinateFromPixelExternal(this.getEventPixel(event));
}
/**
@@ -686,12 +687,22 @@ class PluggableMap extends BaseObject {
/**
* Get the coordinate for a given pixel. This returns a coordinate in the
* map view projection.
* user projection.
* @param {import("./pixel.js").Pixel} pixel Pixel position in the map viewport.
* @return {import("./coordinate.js").Coordinate} The coordinate for the pixel position.
* @api
*/
getCoordinateFromPixel(pixel) {
getCoordinateFromPixelExternal(pixel) {
return toUserCoordinate(this.getCoordinateFromPixelInternal(pixel), this.getView().getProjection())
}
/**
* Get the coordinate for a given pixel. This returns a coordinate in the
* map view projection.
* @param {import("./pixel.js").Pixel} pixel Pixel position in the map viewport.
* @return {import("./coordinate.js").Coordinate} The coordinate for the pixel position.
*/
getCoordinateFromPixelInternal(pixel) {
const frameState = this.frameState_;
if (!frameState) {
return null;
@@ -699,7 +710,7 @@ class PluggableMap extends BaseObject {
return applyTransform(frameState.pixelToCoordinateTransform, pixel.slice());
}
}
/**
* Get the map controls. Modifying this collection changes the controls
* associated with the map.
@@ -783,13 +794,24 @@ class PluggableMap extends BaseObject {
}
/**
* Get the pixel for a coordinate. This takes a coordinate in the map view
* Get the pixel for a coordinate. This takes a coordinate in the user
* projection and returns the corresponding pixel.
* @param {import("./coordinate.js").Coordinate} coordinate A map coordinate.
* @return {import("./pixel.js").Pixel} A pixel position in the map viewport.
* @api
*/
getPixelFromCoordinate(coordinate) {
getPixelFromCoordinateExternal(coordinate) {
const userCoordinate = toUserCoordinate(coordinate, this.getView().getProjection());
return this.getPixelFromCoordinateInternal(userCoordinate);
}
/**
* Get the pixel for a coordinate. This takes a coordinate in the map view
* projection and returns the corresponding pixel.
* @param {import("./coordinate.js").Coordinate} coordinate A map coordinate.
* @return {import("./pixel.js").Pixel} A pixel position in the map viewport.
*/
getPixelFromCoordinateInternal(coordinate) {
const frameState = this.frameState_;
if (!frameState) {
return null;