213 lines
5.9 KiB
JavaScript
213 lines
5.9 KiB
JavaScript
import {
|
|
Control_default,
|
|
EventType_default
|
|
} from "./chunk-LXWL6YOU.js";
|
|
import {
|
|
get,
|
|
getTransformFromProjections,
|
|
getUserProjection,
|
|
identityTransform
|
|
} from "./chunk-XZU4LSFD.js";
|
|
import {
|
|
wrapX
|
|
} from "./chunk-3JZANJYE.js";
|
|
import {
|
|
listen
|
|
} from "./chunk-KJXIHBKT.js";
|
|
|
|
// node_modules/ol/control/MousePosition.js
|
|
var PROJECTION = "projection";
|
|
var COORDINATE_FORMAT = "coordinateFormat";
|
|
var MousePosition = class extends Control_default {
|
|
/**
|
|
* @param {Options} [options] Mouse position options.
|
|
*/
|
|
constructor(options) {
|
|
options = options ? options : {};
|
|
const element = document.createElement("div");
|
|
element.className = options.className !== void 0 ? options.className : "ol-mouse-position";
|
|
super({
|
|
element,
|
|
render: options.render,
|
|
target: options.target
|
|
});
|
|
this.on;
|
|
this.once;
|
|
this.un;
|
|
this.addChangeListener(PROJECTION, this.handleProjectionChanged_);
|
|
if (options.coordinateFormat) {
|
|
this.setCoordinateFormat(options.coordinateFormat);
|
|
}
|
|
if (options.projection) {
|
|
this.setProjection(options.projection);
|
|
}
|
|
this.renderOnMouseOut_ = options.placeholder !== void 0;
|
|
this.placeholder_ = this.renderOnMouseOut_ ? options.placeholder : " ";
|
|
this.renderedHTML_ = element.innerHTML;
|
|
this.mapProjection_ = null;
|
|
this.transform_ = null;
|
|
this.wrapX_ = options.wrapX === false ? false : true;
|
|
}
|
|
/**
|
|
* @private
|
|
*/
|
|
handleProjectionChanged_() {
|
|
this.transform_ = null;
|
|
}
|
|
/**
|
|
* Return the coordinate format type used to render the current position or
|
|
* undefined.
|
|
* @return {import("../coordinate.js").CoordinateFormat|undefined} The format to render the current
|
|
* position in.
|
|
* @observable
|
|
* @api
|
|
*/
|
|
getCoordinateFormat() {
|
|
return (
|
|
/** @type {import("../coordinate.js").CoordinateFormat|undefined} */
|
|
this.get(COORDINATE_FORMAT)
|
|
);
|
|
}
|
|
/**
|
|
* Return the projection that is used to report the mouse position.
|
|
* @return {import("../proj/Projection.js").default|undefined} The projection to report mouse
|
|
* position in.
|
|
* @observable
|
|
* @api
|
|
*/
|
|
getProjection() {
|
|
return (
|
|
/** @type {import("../proj/Projection.js").default|undefined} */
|
|
this.get(PROJECTION)
|
|
);
|
|
}
|
|
/**
|
|
* @param {MouseEvent} event Browser event.
|
|
* @protected
|
|
*/
|
|
handleMouseMove(event) {
|
|
const map = this.getMap();
|
|
this.updateHTML_(map.getEventPixel(event));
|
|
}
|
|
/**
|
|
* @param {Event} event Browser event.
|
|
* @protected
|
|
*/
|
|
handleMouseOut(event) {
|
|
this.updateHTML_(null);
|
|
}
|
|
/**
|
|
* Remove the control from its current map and attach it to the new map.
|
|
* Pass `null` to just remove the control from the current map.
|
|
* Subclasses may set up event handlers to get notified about changes to
|
|
* the map here.
|
|
* @param {import("../Map.js").default|null} map Map.
|
|
* @api
|
|
* @override
|
|
*/
|
|
setMap(map) {
|
|
super.setMap(map);
|
|
if (map) {
|
|
const viewport = map.getViewport();
|
|
this.listenerKeys.push(
|
|
listen(viewport, EventType_default.POINTERMOVE, this.handleMouseMove, this)
|
|
);
|
|
if (this.renderOnMouseOut_) {
|
|
this.listenerKeys.push(
|
|
listen(viewport, EventType_default.POINTEROUT, this.handleMouseOut, this)
|
|
);
|
|
}
|
|
this.updateHTML_(null);
|
|
}
|
|
}
|
|
/**
|
|
* Set the coordinate format type used to render the current position.
|
|
* @param {import("../coordinate.js").CoordinateFormat} format The format to render the current
|
|
* position in.
|
|
* @observable
|
|
* @api
|
|
*/
|
|
setCoordinateFormat(format) {
|
|
this.set(COORDINATE_FORMAT, format);
|
|
}
|
|
/**
|
|
* Set the projection that is used to report the mouse position.
|
|
* @param {import("../proj.js").ProjectionLike} projection The projection to report mouse
|
|
* position in.
|
|
* @observable
|
|
* @api
|
|
*/
|
|
setProjection(projection) {
|
|
this.set(PROJECTION, get(projection));
|
|
}
|
|
/**
|
|
* @param {?import("../pixel.js").Pixel} pixel Pixel.
|
|
* @private
|
|
*/
|
|
updateHTML_(pixel) {
|
|
let html = this.placeholder_;
|
|
if (pixel && this.mapProjection_) {
|
|
if (!this.transform_) {
|
|
const projection = this.getProjection();
|
|
if (projection) {
|
|
this.transform_ = getTransformFromProjections(
|
|
this.mapProjection_,
|
|
projection
|
|
);
|
|
} else {
|
|
this.transform_ = identityTransform;
|
|
}
|
|
}
|
|
const map = this.getMap();
|
|
const coordinate = map.getCoordinateFromPixelInternal(pixel);
|
|
if (coordinate) {
|
|
const userProjection = getUserProjection();
|
|
if (userProjection) {
|
|
this.transform_ = getTransformFromProjections(
|
|
this.mapProjection_,
|
|
userProjection
|
|
);
|
|
}
|
|
this.transform_(coordinate, coordinate);
|
|
if (this.wrapX_) {
|
|
const projection = userProjection || this.getProjection() || this.mapProjection_;
|
|
wrapX(coordinate, projection);
|
|
}
|
|
const coordinateFormat = this.getCoordinateFormat();
|
|
if (coordinateFormat) {
|
|
html = coordinateFormat(coordinate);
|
|
} else {
|
|
html = coordinate.toString();
|
|
}
|
|
}
|
|
}
|
|
if (!this.renderedHTML_ || html !== this.renderedHTML_) {
|
|
this.element.innerHTML = html;
|
|
this.renderedHTML_ = html;
|
|
}
|
|
}
|
|
/**
|
|
* Update the projection. Rendering of the coordinates is done in
|
|
* `handleMouseMove` and `handleMouseUp`.
|
|
* @param {import("../MapEvent.js").default} mapEvent Map event.
|
|
* @override
|
|
*/
|
|
render(mapEvent) {
|
|
const frameState = mapEvent.frameState;
|
|
if (!frameState) {
|
|
this.mapProjection_ = null;
|
|
} else {
|
|
if (this.mapProjection_ != frameState.viewState.projection) {
|
|
this.mapProjection_ = frameState.viewState.projection;
|
|
this.transform_ = null;
|
|
}
|
|
}
|
|
}
|
|
};
|
|
var MousePosition_default = MousePosition;
|
|
|
|
export {
|
|
MousePosition_default
|
|
};
|
|
//# sourceMappingURL=chunk-76BTNKGA.js.map
|