0
0
mirror of https://github.com/Maks1mS/free-ozon-dpr.git synced 2024-12-23 18:42:59 +03:00
free-ozon-dpr/geolocation.js
2024-06-05 14:56:19 +03:00

49 lines
1.2 KiB
JavaScript

import map, { view } from "./map";
import Feature from "ol/Feature.js";
import Geolocation from "ol/Geolocation.js";
import Point from "ol/geom/Point.js";
import { Circle as CircleStyle, Fill, Stroke, Style } from "ol/style.js";
import { Vector as VectorSource } from "ol/source.js";
import { Vector as VectorLayer } from "ol/layer.js";
const geolocation = new Geolocation({
tracking: true,
trackingOptions: {
enableHighAccuracy: true,
},
projection: view.getProjection(),
});
const positionFeature = new Feature();
positionFeature.setStyle(
new Style({
image: new CircleStyle({
radius: 6,
fill: new Fill({
color: "#3399CC",
}),
stroke: new Stroke({
color: "#fff",
width: 2,
}),
}),
})
);
const accuracyFeature = new Feature();
geolocation.on("change:accuracyGeometry", function () {
accuracyFeature.setGeometry(geolocation.getAccuracyGeometry());
});
geolocation.on("change:position", function () {
const coordinates = geolocation.getPosition();
positionFeature.setGeometry(coordinates ? new Point(coordinates) : null);
});
new VectorLayer({
map: map,
source: new VectorSource({
features: [accuracyFeature, positionFeature],
}),
});