855 lines
24 KiB
JavaScript
855 lines
24 KiB
JavaScript
import {
|
|
Toggle_default
|
|
} from "./chunk-NNBJMTCH.js";
|
|
import "./chunk-VCBXDRBT.js";
|
|
import {
|
|
Vector_default as Vector_default2
|
|
} from "./chunk-PD2E5XZ4.js";
|
|
import "./chunk-S3QBQTEW.js";
|
|
import "./chunk-V7WRBSQ6.js";
|
|
import "./chunk-W7BDJOQY.js";
|
|
import {
|
|
Circle_default,
|
|
LineString_default
|
|
} from "./chunk-7JXPN73Q.js";
|
|
import {
|
|
Feature_default
|
|
} from "./chunk-E53S5GN6.js";
|
|
import {
|
|
Vector_default
|
|
} from "./chunk-T3TT2KJN.js";
|
|
import "./chunk-HM3IY3H4.js";
|
|
import "./chunk-JFXZSSOM.js";
|
|
import "./chunk-ZUI5NXIU.js";
|
|
import "./chunk-I4Q72WOW.js";
|
|
import "./chunk-RTVPCGIJ.js";
|
|
import {
|
|
Interaction_default
|
|
} from "./chunk-MSWSBYBR.js";
|
|
import "./chunk-QCJTGAWF.js";
|
|
import "./chunk-CAVOO5JW.js";
|
|
import "./chunk-VRTURNK3.js";
|
|
import "./chunk-2C73OZ6M.js";
|
|
import "./chunk-M5TTSD4C.js";
|
|
import "./chunk-ZCRXKB7J.js";
|
|
import "./chunk-RW3V7S4F.js";
|
|
import {
|
|
Circle_default as Circle_default2,
|
|
Fill_default,
|
|
RegularShape_default,
|
|
Stroke_default,
|
|
Style_default
|
|
} from "./chunk-PAB2HIXK.js";
|
|
import "./chunk-I6K7MRGV.js";
|
|
import "./chunk-PGWX4545.js";
|
|
import "./chunk-AYBYZSAV.js";
|
|
import "./chunk-YLJGUH5Z.js";
|
|
import {
|
|
Point_default,
|
|
Polygon_default,
|
|
circular,
|
|
fromCircle
|
|
} from "./chunk-AZGMK675.js";
|
|
import "./chunk-BHVDQB66.js";
|
|
import "./chunk-6EWLK2BW.js";
|
|
import "./chunk-6Y7C6NBJ.js";
|
|
import "./chunk-5D2XPBR2.js";
|
|
import "./chunk-SHUBVYN4.js";
|
|
import "./chunk-FM44FOIC.js";
|
|
import "./chunk-LMC3RO5P.js";
|
|
import "./chunk-X52LGBOS.js";
|
|
import "./chunk-QFCIXVZ3.js";
|
|
import {
|
|
get,
|
|
getTransformFromProjections,
|
|
identityTransform,
|
|
transform
|
|
} from "./chunk-A3RXLHYB.js";
|
|
import {
|
|
getDistance
|
|
} from "./chunk-ZLPTRF2L.js";
|
|
import {
|
|
toRadians
|
|
} from "./chunk-54BTDBAD.js";
|
|
import "./chunk-UPTVWZ45.js";
|
|
import "./chunk-5XHD7RSF.js";
|
|
import {
|
|
Object_default
|
|
} from "./chunk-Q5ZULJHM.js";
|
|
import {
|
|
Event_default
|
|
} from "./chunk-NGFXCWUF.js";
|
|
import "./chunk-K25ZO44T.js";
|
|
import {
|
|
containsCoordinate,
|
|
containsExtent
|
|
} from "./chunk-SRXHWJOY.js";
|
|
import "./chunk-5RHQVMYD.js";
|
|
import "./chunk-DC5AMYBS.js";
|
|
|
|
// node_modules/ol/Geolocation.js
|
|
var Property = {
|
|
ACCURACY: "accuracy",
|
|
ACCURACY_GEOMETRY: "accuracyGeometry",
|
|
ALTITUDE: "altitude",
|
|
ALTITUDE_ACCURACY: "altitudeAccuracy",
|
|
HEADING: "heading",
|
|
POSITION: "position",
|
|
PROJECTION: "projection",
|
|
SPEED: "speed",
|
|
TRACKING: "tracking",
|
|
TRACKING_OPTIONS: "trackingOptions"
|
|
};
|
|
var GeolocationErrorType = {
|
|
/**
|
|
* Triggered when a `GeolocationPositionError` occurs.
|
|
* @event module:ol/Geolocation.GeolocationError#error
|
|
* @api
|
|
*/
|
|
ERROR: "error"
|
|
};
|
|
var GeolocationError = class extends Event_default {
|
|
/**
|
|
* @param {GeolocationPositionError} error error object.
|
|
*/
|
|
constructor(error) {
|
|
super(GeolocationErrorType.ERROR);
|
|
this.code = error.code;
|
|
this.message = error.message;
|
|
}
|
|
};
|
|
var Geolocation = class extends Object_default {
|
|
/**
|
|
* @param {Options} [options] Options.
|
|
*/
|
|
constructor(options) {
|
|
super();
|
|
this.on;
|
|
this.once;
|
|
this.un;
|
|
options = options || {};
|
|
this.position_ = null;
|
|
this.transform_ = identityTransform;
|
|
this.watchId_ = void 0;
|
|
this.addChangeListener(Property.PROJECTION, this.handleProjectionChanged_);
|
|
this.addChangeListener(Property.TRACKING, this.handleTrackingChanged_);
|
|
if (options.projection !== void 0) {
|
|
this.setProjection(options.projection);
|
|
}
|
|
if (options.trackingOptions !== void 0) {
|
|
this.setTrackingOptions(options.trackingOptions);
|
|
}
|
|
this.setTracking(options.tracking !== void 0 ? options.tracking : false);
|
|
}
|
|
/**
|
|
* Clean up.
|
|
* @override
|
|
*/
|
|
disposeInternal() {
|
|
this.setTracking(false);
|
|
super.disposeInternal();
|
|
}
|
|
/**
|
|
* @private
|
|
*/
|
|
handleProjectionChanged_() {
|
|
const projection = this.getProjection();
|
|
if (projection) {
|
|
this.transform_ = getTransformFromProjections(
|
|
get("EPSG:4326"),
|
|
projection
|
|
);
|
|
if (this.position_) {
|
|
this.set(Property.POSITION, this.transform_(this.position_));
|
|
}
|
|
}
|
|
}
|
|
/**
|
|
* @private
|
|
*/
|
|
handleTrackingChanged_() {
|
|
if ("geolocation" in navigator) {
|
|
const tracking = this.getTracking();
|
|
if (tracking && this.watchId_ === void 0) {
|
|
this.watchId_ = navigator.geolocation.watchPosition(
|
|
this.positionChange_.bind(this),
|
|
this.positionError_.bind(this),
|
|
this.getTrackingOptions()
|
|
);
|
|
} else if (!tracking && this.watchId_ !== void 0) {
|
|
navigator.geolocation.clearWatch(this.watchId_);
|
|
this.watchId_ = void 0;
|
|
}
|
|
}
|
|
}
|
|
/**
|
|
* @private
|
|
* @param {GeolocationPosition} position position event.
|
|
*/
|
|
positionChange_(position) {
|
|
const coords = position.coords;
|
|
this.set(Property.ACCURACY, coords.accuracy);
|
|
this.set(
|
|
Property.ALTITUDE,
|
|
coords.altitude === null ? void 0 : coords.altitude
|
|
);
|
|
this.set(
|
|
Property.ALTITUDE_ACCURACY,
|
|
coords.altitudeAccuracy === null ? void 0 : coords.altitudeAccuracy
|
|
);
|
|
this.set(
|
|
Property.HEADING,
|
|
coords.heading === null ? void 0 : toRadians(coords.heading)
|
|
);
|
|
if (!this.position_) {
|
|
this.position_ = [coords.longitude, coords.latitude];
|
|
} else {
|
|
this.position_[0] = coords.longitude;
|
|
this.position_[1] = coords.latitude;
|
|
}
|
|
const projectedPosition = this.transform_(this.position_);
|
|
this.set(Property.POSITION, projectedPosition.slice());
|
|
this.set(Property.SPEED, coords.speed === null ? void 0 : coords.speed);
|
|
const geometry = circular(this.position_, coords.accuracy);
|
|
geometry.applyTransform(this.transform_);
|
|
this.set(Property.ACCURACY_GEOMETRY, geometry);
|
|
this.changed();
|
|
}
|
|
/**
|
|
* @private
|
|
* @param {GeolocationPositionError} error error object.
|
|
*/
|
|
positionError_(error) {
|
|
this.dispatchEvent(new GeolocationError(error));
|
|
}
|
|
/**
|
|
* Get the accuracy of the position in meters.
|
|
* @return {number|undefined} The accuracy of the position measurement in
|
|
* meters.
|
|
* @observable
|
|
* @api
|
|
*/
|
|
getAccuracy() {
|
|
return (
|
|
/** @type {number|undefined} */
|
|
this.get(Property.ACCURACY)
|
|
);
|
|
}
|
|
/**
|
|
* Get a geometry of the position accuracy.
|
|
* @return {?import("./geom/Polygon.js").default} A geometry of the position accuracy.
|
|
* @observable
|
|
* @api
|
|
*/
|
|
getAccuracyGeometry() {
|
|
return (
|
|
/** @type {?import("./geom/Polygon.js").default} */
|
|
this.get(Property.ACCURACY_GEOMETRY) || null
|
|
);
|
|
}
|
|
/**
|
|
* Get the altitude associated with the position.
|
|
* @return {number|undefined} The altitude of the position in meters above mean
|
|
* sea level.
|
|
* @observable
|
|
* @api
|
|
*/
|
|
getAltitude() {
|
|
return (
|
|
/** @type {number|undefined} */
|
|
this.get(Property.ALTITUDE)
|
|
);
|
|
}
|
|
/**
|
|
* Get the altitude accuracy of the position.
|
|
* @return {number|undefined} The accuracy of the altitude measurement in
|
|
* meters.
|
|
* @observable
|
|
* @api
|
|
*/
|
|
getAltitudeAccuracy() {
|
|
return (
|
|
/** @type {number|undefined} */
|
|
this.get(Property.ALTITUDE_ACCURACY)
|
|
);
|
|
}
|
|
/**
|
|
* Get the heading as radians clockwise from North.
|
|
* Note: depending on the browser, the heading is only defined if the `enableHighAccuracy`
|
|
* is set to `true` in the tracking options.
|
|
* @return {number|undefined} The heading of the device in radians from north.
|
|
* @observable
|
|
* @api
|
|
*/
|
|
getHeading() {
|
|
return (
|
|
/** @type {number|undefined} */
|
|
this.get(Property.HEADING)
|
|
);
|
|
}
|
|
/**
|
|
* Get the position of the device.
|
|
* @return {import("./coordinate.js").Coordinate|undefined} The current position of the device reported
|
|
* in the current projection.
|
|
* @observable
|
|
* @api
|
|
*/
|
|
getPosition() {
|
|
return (
|
|
/** @type {import("./coordinate.js").Coordinate|undefined} */
|
|
this.get(Property.POSITION)
|
|
);
|
|
}
|
|
/**
|
|
* Get the projection associated with the position.
|
|
* @return {import("./proj/Projection.js").default|undefined} The projection the position is
|
|
* reported in.
|
|
* @observable
|
|
* @api
|
|
*/
|
|
getProjection() {
|
|
return (
|
|
/** @type {import("./proj/Projection.js").default|undefined} */
|
|
this.get(Property.PROJECTION)
|
|
);
|
|
}
|
|
/**
|
|
* Get the speed in meters per second.
|
|
* @return {number|undefined} The instantaneous speed of the device in meters
|
|
* per second.
|
|
* @observable
|
|
* @api
|
|
*/
|
|
getSpeed() {
|
|
return (
|
|
/** @type {number|undefined} */
|
|
this.get(Property.SPEED)
|
|
);
|
|
}
|
|
/**
|
|
* Determine if the device location is being tracked.
|
|
* @return {boolean} The device location is being tracked.
|
|
* @observable
|
|
* @api
|
|
*/
|
|
getTracking() {
|
|
return (
|
|
/** @type {boolean} */
|
|
this.get(Property.TRACKING)
|
|
);
|
|
}
|
|
/**
|
|
* Get the tracking options.
|
|
* See https://www.w3.org/TR/geolocation-API/#position-options.
|
|
* @return {PositionOptions|undefined} PositionOptions as defined by
|
|
* the [HTML5 Geolocation spec
|
|
* ](https://www.w3.org/TR/geolocation-API/#position_options_interface).
|
|
* @observable
|
|
* @api
|
|
*/
|
|
getTrackingOptions() {
|
|
return (
|
|
/** @type {PositionOptions|undefined} */
|
|
this.get(Property.TRACKING_OPTIONS)
|
|
);
|
|
}
|
|
/**
|
|
* Set the projection to use for transforming the coordinates.
|
|
* @param {import("./proj.js").ProjectionLike} projection The projection the position is
|
|
* reported in.
|
|
* @observable
|
|
* @api
|
|
*/
|
|
setProjection(projection) {
|
|
this.set(Property.PROJECTION, get(projection));
|
|
}
|
|
/**
|
|
* Enable or disable tracking.
|
|
* @param {boolean} tracking Enable tracking.
|
|
* @observable
|
|
* @api
|
|
*/
|
|
setTracking(tracking) {
|
|
this.set(Property.TRACKING, tracking);
|
|
}
|
|
/**
|
|
* Set the tracking options.
|
|
* See http://www.w3.org/TR/geolocation-API/#position-options.
|
|
* @param {PositionOptions} options PositionOptions as defined by the
|
|
* [HTML5 Geolocation spec
|
|
* ](http://www.w3.org/TR/geolocation-API/#position_options_interface).
|
|
* @observable
|
|
* @api
|
|
*/
|
|
setTrackingOptions(options) {
|
|
this.set(Property.TRACKING_OPTIONS, options);
|
|
}
|
|
};
|
|
var Geolocation_default = Geolocation;
|
|
|
|
// node_modules/ol-ext/interaction/GeolocationDraw.js
|
|
var ol_interaction_GeolocationDraw = class olinteractionGeolocationDraw extends Interaction_default {
|
|
constructor(options) {
|
|
options = options || {};
|
|
super({
|
|
handleEvent: function() {
|
|
return !this.get("followTrack") || this.get("followTrack") == "auto";
|
|
}
|
|
});
|
|
this.geolocation = new Geolocation_default({
|
|
projection: "EPSG:4326",
|
|
trackingOptions: {
|
|
maximumAge: 1e4,
|
|
enableHighAccuracy: true,
|
|
timeout: 6e5
|
|
}
|
|
});
|
|
this.geolocation.on("change", this.draw_.bind(this));
|
|
this.path_ = [];
|
|
this.lastPosition_ = false;
|
|
var white = [255, 255, 255, 1];
|
|
var blue = [0, 153, 255, 1];
|
|
var width = 3;
|
|
var circle = new Circle_default2({
|
|
radius: width * 2,
|
|
fill: new Fill_default({ color: blue }),
|
|
stroke: new Stroke_default({ color: white, width: width / 2 })
|
|
});
|
|
var style = [
|
|
new Style_default({
|
|
stroke: new Stroke_default({ color: white, width: width + 2 })
|
|
}),
|
|
new Style_default({
|
|
stroke: new Stroke_default({ color: blue, width }),
|
|
fill: new Fill_default({
|
|
color: [255, 255, 255, 0.5]
|
|
})
|
|
})
|
|
];
|
|
var triangle = new RegularShape_default({
|
|
radius: width * 3.5,
|
|
points: 3,
|
|
rotation: 0,
|
|
fill: new Fill_default({ color: blue }),
|
|
stroke: new Stroke_default({ color: white, width: width / 2 })
|
|
});
|
|
var c = triangle.getImage();
|
|
var ctx = c.getContext("2d");
|
|
var c2 = document.createElement("canvas");
|
|
c2.width = c2.height = c.width;
|
|
c2.getContext("2d").drawImage(c, 0, 0);
|
|
ctx.clearRect(0, 0, c.width, c.height);
|
|
ctx.drawImage(c2, 0, 0, c.width, c.height, width, 0, c.width - 2 * width, c.height);
|
|
var defaultStyle = function(f) {
|
|
if (f.get("heading") === void 0) {
|
|
style[1].setImage(circle);
|
|
} else {
|
|
style[1].setImage(triangle);
|
|
triangle.setRotation(f.get("heading") || 0);
|
|
}
|
|
return style;
|
|
};
|
|
this.locStyle = {
|
|
error: new Style_default({ fill: new Fill_default({ color: [255, 0, 0, 0.2] }) }),
|
|
warn: new Style_default({ fill: new Fill_default({ color: [255, 192, 0, 0.2] }) }),
|
|
ok: new Style_default({ fill: new Fill_default({ color: [0, 255, 0, 0.2] }) })
|
|
};
|
|
this.overlayLayer_ = new Vector_default({
|
|
source: new Vector_default2(),
|
|
name: "GeolocationDraw overlay",
|
|
style: options.style || defaultStyle
|
|
});
|
|
this.sketch_ = [new Feature_default(), new Feature_default(), new Feature_default()];
|
|
this.overlayLayer_.getSource().addFeatures(this.sketch_);
|
|
this.features_ = options.features;
|
|
this.source_ = options.source;
|
|
this.condition_ = options.condition || function(loc) {
|
|
return loc.getAccuracy() < this.get("minAccuracy");
|
|
};
|
|
this.set("type", options.type || "LineString");
|
|
this.set("attributes", options.attributes || {});
|
|
this.set("minAccuracy", options.minAccuracy || 20);
|
|
this.set("tolerance", options.tolerance || 5);
|
|
this.set("zoom", options.zoom);
|
|
this.set("minZoom", options.minZoom);
|
|
this.setFollowTrack(options.followTrack === void 0 ? true : options.followTrack);
|
|
this.setActive(false);
|
|
}
|
|
/** Simplify 3D geometry
|
|
* @param {ol.geom.Geometry} geo
|
|
* @param {number} tolerance
|
|
*/
|
|
simplify3D(geo, tolerance) {
|
|
var geom = geo.getCoordinates();
|
|
var proj = this.getMap().getView().getProjection();
|
|
if (this.get("type") === "Polygon") {
|
|
geom = geom[0];
|
|
}
|
|
var simply = [geom[0]];
|
|
var pi, p = transform(geom[0], proj, "EPSG:4326");
|
|
for (var i = 1; i < geom.length; i++) {
|
|
pi = transform(geom[i], proj, "EPSG:4326");
|
|
var d = getDistance(p, pi);
|
|
if (d > tolerance) {
|
|
simply.push(geom[i]);
|
|
p = pi;
|
|
}
|
|
}
|
|
if (simply[simply.length - 1] !== geom[geom.length - 1]) {
|
|
simply.push(geom[geom.length - 1]);
|
|
}
|
|
if (this.get("type") === "Polygon") {
|
|
geo = new Polygon_default([simply], "XYZM");
|
|
} else {
|
|
geo = new LineString_default(simply, "XYZM");
|
|
}
|
|
return geo;
|
|
}
|
|
/**
|
|
* Remove the interaction from its current map, if any, and attach it to a new
|
|
* map, if any. Pass `null` to just remove the interaction from the current map.
|
|
* @param {ol.Map} map Map.
|
|
* @api stable
|
|
*/
|
|
setMap(map) {
|
|
if (this.getMap()) this.getMap().removeLayer(this.overlayLayer_);
|
|
super.setMap(map);
|
|
this.overlayLayer_.setMap(map);
|
|
if (map) this.geolocation.setProjection(map.getView().getProjection());
|
|
}
|
|
/** Activate or deactivate the interaction.
|
|
* @param {boolean} active
|
|
*/
|
|
setActive(active) {
|
|
if (active === this.getActive()) return;
|
|
super.setActive(active);
|
|
if (this.getMap()) {
|
|
this.geolocation.setTracking(active);
|
|
try {
|
|
this.getMap().renderSync();
|
|
} catch (e) {
|
|
}
|
|
}
|
|
if (!this.overlayLayer_) return;
|
|
this.overlayLayer_.setVisible(active);
|
|
this.pause(!active);
|
|
if (active) {
|
|
this.reset();
|
|
this.dispatchEvent({ type: "drawstart", feature: this.sketch_[1] });
|
|
} else {
|
|
var f = this.sketch_[1].clone();
|
|
if (f.getGeometry()) {
|
|
if (this.features_)
|
|
this.features_.push(f);
|
|
if (this.source_)
|
|
this.source_.addFeature(f);
|
|
}
|
|
this.dispatchEvent({ type: "drawend", feature: f });
|
|
}
|
|
}
|
|
/** Simulate a track and override current geolocation
|
|
* @param {Array<ol.coordinate>|boolean} track a list of point or false to stop
|
|
* @param {*} options
|
|
* @param {number} delay delay in ms, default 1000 (1s)
|
|
* @param {number} accuracy gps accuracy, default 10
|
|
* @param {boolean} repeat repeat track, default true
|
|
*/
|
|
simulate(track, options) {
|
|
if (this._track) {
|
|
clearTimeout(this._track.timeout);
|
|
}
|
|
if (!track) {
|
|
this._track = false;
|
|
return;
|
|
}
|
|
options = options || {};
|
|
var delay = options.delay || 1e3;
|
|
function handleTrack() {
|
|
if (this._track.pos >= this._track.track.length) {
|
|
this._track = false;
|
|
return;
|
|
}
|
|
var coord = this._track.track[this._track.pos];
|
|
coord[2] = coord[3] || 0;
|
|
coord[3] = (/* @__PURE__ */ new Date()).getTime();
|
|
this._track.pos++;
|
|
if (options.repeat !== false) {
|
|
this._track.pos = this._track.pos % this._track.track.length;
|
|
}
|
|
if (this.getActive())
|
|
this.draw_(true, coord, options.accuracy);
|
|
this._track.timeout = setTimeout(handleTrack.bind(this), delay);
|
|
}
|
|
this._track = {
|
|
track,
|
|
pos: 0,
|
|
timeout: setTimeout(handleTrack.bind(this), 0)
|
|
};
|
|
}
|
|
/** Is simulation on ?
|
|
* @returns {boolean}
|
|
*/
|
|
simulating() {
|
|
return !!this._track;
|
|
}
|
|
/** Reset drawing
|
|
*/
|
|
reset() {
|
|
this.sketch_[1].setGeometry();
|
|
this.path_ = [];
|
|
this.lastPosition_ = false;
|
|
}
|
|
/** Start tracking = setActive(true)
|
|
*/
|
|
start() {
|
|
this.setActive(true);
|
|
}
|
|
/** Stop tracking = setActive(false)
|
|
*/
|
|
stop() {
|
|
this.setActive(false);
|
|
}
|
|
/** Pause drawing
|
|
* @param {boolean} b
|
|
*/
|
|
pause(b) {
|
|
this.pause_ = b !== false;
|
|
}
|
|
/** Is paused
|
|
* @return {boolean} b
|
|
*/
|
|
isPaused() {
|
|
return this.pause_;
|
|
}
|
|
/** Enable following the track on the map
|
|
* @param {boolean|auto|position|visible} follow,
|
|
* false: don't follow,
|
|
* true: follow (position+zoom),
|
|
* 'position': follow only position,
|
|
* 'auto': start following until user move the map,
|
|
* 'visible': center when position gets out of the visible extent
|
|
*/
|
|
setFollowTrack(follow) {
|
|
this.set("followTrack", follow);
|
|
var map = this.getMap();
|
|
if (this.getActive() && map) {
|
|
var zoom;
|
|
if (follow !== "position") {
|
|
if (this.get("minZoom")) {
|
|
zoom = Math.max(this.get("minZoom"), map.getView().getZoom());
|
|
} else {
|
|
zoom = this.get("zoom");
|
|
}
|
|
}
|
|
if (follow !== false && !this.lastPosition_) {
|
|
var pos = this.path_[this.path_.length - 1];
|
|
if (pos) {
|
|
map.getView().animate({
|
|
center: pos,
|
|
zoom
|
|
});
|
|
}
|
|
} else if (follow === "auto" && this.lastPosition_) {
|
|
map.getView().animate({
|
|
center: this.lastPosition_,
|
|
zoom
|
|
});
|
|
}
|
|
}
|
|
this.lastPosition_ = false;
|
|
this.dispatchEvent({ type: "follow", following: follow !== false });
|
|
}
|
|
/** Add a new point to the current path
|
|
* @private
|
|
*/
|
|
draw_(simulate, coord, accuracy) {
|
|
var map = this.getMap();
|
|
if (!map)
|
|
return;
|
|
var accu, pos, p, loc, heading;
|
|
if (this._track) {
|
|
if (simulate !== true)
|
|
return;
|
|
pos = coord;
|
|
accu = accuracy || 10;
|
|
if (this.path_ && this.path_.length) {
|
|
var pt = this.path_[this.path_.length - 1];
|
|
heading = Math.atan2(coord[0] - pt[0], coord[1] - pt[1]);
|
|
}
|
|
var circle = new Circle_default(pos, map.getView().getResolution() * accu);
|
|
p = fromCircle(circle);
|
|
} else {
|
|
loc = this.geolocation;
|
|
accu = loc.getAccuracy();
|
|
pos = this.getPosition(loc);
|
|
p = loc.getAccuracyGeometry();
|
|
heading = loc.getHeading();
|
|
}
|
|
switch (this.get("followTrack")) {
|
|
// Follow center + zoom
|
|
case true: {
|
|
if (this.get("followTrack") == true) {
|
|
if (this.get("minZoom")) {
|
|
if (this.get("minZoom") > map.getView().getZoom()) {
|
|
map.getView().setZoom(this.get("minZoom"));
|
|
}
|
|
} else {
|
|
map.getView().setZoom(this.get("zoom") || 16);
|
|
}
|
|
if (!containsExtent(map.getView().calculateExtent(map.getSize()), p.getExtent())) {
|
|
map.getView().fit(p.getExtent());
|
|
}
|
|
}
|
|
map.getView().setCenter(pos);
|
|
break;
|
|
}
|
|
// Follow position
|
|
case "position": {
|
|
map.getView().setCenter(pos);
|
|
break;
|
|
}
|
|
// Keep on following
|
|
case "auto": {
|
|
if (this.lastPosition_) {
|
|
var center = map.getView().getCenter();
|
|
if (center[0] != this.lastPosition_[0] || center[1] != this.lastPosition_[1]) {
|
|
this.setFollowTrack(false);
|
|
} else {
|
|
map.getView().setCenter(pos);
|
|
this.lastPosition_ = pos;
|
|
}
|
|
} else {
|
|
map.getView().setCenter(pos);
|
|
if (this.get("minZoom")) {
|
|
if (this.get("minZoom") > map.getView().getZoom()) {
|
|
map.getView().setZoom(this.get("minZoom"));
|
|
}
|
|
} else if (this.get("zoom")) {
|
|
map.getView().setZoom(this.get("zoom"));
|
|
}
|
|
this.lastPosition_ = pos;
|
|
}
|
|
break;
|
|
}
|
|
// Force to stay on the map
|
|
case "visible": {
|
|
if (!containsCoordinate(map.getView().calculateExtent(map.getSize()), pos)) {
|
|
map.getView().setCenter(pos);
|
|
}
|
|
break;
|
|
}
|
|
// Don't follow
|
|
default:
|
|
break;
|
|
}
|
|
var f = this.sketch_[0];
|
|
f.setGeometry(p);
|
|
if (accu < this.get("minAccuracy") / 2)
|
|
f.setStyle(this.locStyle.ok);
|
|
else if (accu < this.get("minAccuracy"))
|
|
f.setStyle(this.locStyle.warn);
|
|
else
|
|
f.setStyle(this.locStyle.error);
|
|
var geo;
|
|
if (this.pause_) {
|
|
this.lastPosition_ = pos;
|
|
}
|
|
if (!this.pause_ && (!loc || this.condition_.call(this, loc))) {
|
|
f = this.sketch_[1];
|
|
this.path_.push(pos);
|
|
switch (this.get("type")) {
|
|
case "Point":
|
|
this.path_ = [pos];
|
|
f.setGeometry(new Point_default(pos, "XYZM"));
|
|
var attr = this.get("attributes");
|
|
if (attr.heading)
|
|
f.set("heading", loc.getHeading());
|
|
if (attr.accuracy)
|
|
f.set("accuracy", loc.getAccuracy());
|
|
if (attr.altitudeAccuracy)
|
|
f.set("altitudeAccuracy", loc.getAltitudeAccuracy());
|
|
if (attr.speed)
|
|
f.set("speed", loc.getSpeed());
|
|
break;
|
|
case "LineString":
|
|
if (this.path_.length > 1) {
|
|
geo = new LineString_default(this.path_, "XYZM");
|
|
if (this.get("tolerance"))
|
|
geo = this.simplify3D(geo, this.get("tolerance"));
|
|
f.setGeometry(geo);
|
|
} else {
|
|
f.setGeometry();
|
|
}
|
|
break;
|
|
case "Polygon":
|
|
if (this.path_.length > 2) {
|
|
geo = new Polygon_default([this.path_], "XYZM");
|
|
if (this.get("tolerance"))
|
|
geo = this.simplify3D(geo, this.get("tolerance"));
|
|
f.setGeometry(geo);
|
|
} else
|
|
f.setGeometry();
|
|
break;
|
|
}
|
|
this.dispatchEvent({ type: "drawing", feature: this.sketch_[1], geolocation: loc });
|
|
}
|
|
this.sketch_[2].setGeometry(new Point_default(pos));
|
|
this.sketch_[2].set("heading", heading);
|
|
this.dispatchEvent({ type: "tracking", feature: this.sketch_[1], geolocation: loc });
|
|
}
|
|
/** Get a position according to the geolocation
|
|
* @param {Geolocation} loc
|
|
* @returns {Array<any>} an array of measure X,Y,Z,T
|
|
* @api
|
|
*/
|
|
getPosition(loc) {
|
|
var pos = loc.getPosition();
|
|
pos.push(Math.round((loc.getAltitude() || 0) * 100) / 100);
|
|
pos.push(Math.round((/* @__PURE__ */ new Date()).getTime() / 1e3));
|
|
return pos;
|
|
}
|
|
};
|
|
var GeolocationDraw_default = ol_interaction_GeolocationDraw;
|
|
|
|
// node_modules/ol-ext/control/GeolocationButton.js
|
|
var ol_control_GeolocationButton = class olcontrolGeolocationButton extends Toggle_default {
|
|
constructor(options) {
|
|
options = options || {};
|
|
options.followTrack = options.followTrack || "auto";
|
|
options.zoom = options.zoom || 16;
|
|
var interaction = new GeolocationDraw_default(options);
|
|
super({
|
|
className: options.className = ((options.className || "") + " ol-geobt").trim(),
|
|
interaction,
|
|
title: options.title || "Geolocation",
|
|
onToggle: function() {
|
|
interaction.pause(true);
|
|
interaction.setFollowTrack(options.followTrack || "auto");
|
|
}
|
|
});
|
|
this.setActive(false);
|
|
interaction.on("tracking", (function(e) {
|
|
this.dispatchEvent({ type: "position", coordinate: e.geolocation.getPosition() });
|
|
}).bind(this));
|
|
var tout;
|
|
interaction.on("change:active", (function() {
|
|
this.dispatchEvent({ type: "position" });
|
|
if (tout) {
|
|
clearTimeout(tout);
|
|
tout = null;
|
|
}
|
|
if (interaction.getActive()) {
|
|
tout = setTimeout((function() {
|
|
interaction.setActive(false);
|
|
tout = null;
|
|
}).bind(this), options.delay || 3e3);
|
|
}
|
|
}).bind(this));
|
|
}
|
|
};
|
|
var GeolocationButton_default = ol_control_GeolocationButton;
|
|
export {
|
|
GeolocationButton_default as default
|
|
};
|
|
//# sourceMappingURL=ol-ext_control_GeolocationButton.js.map
|