0
0
mirror of https://github.com/Maks1mS/free-ozon-dpr.git synced 2024-12-24 02:52:58 +03:00
free-ozon-dpr/src/geolocation.js
Maxim Slipenko deeed2e2ef
chore: improve ux and dx (#1)
* move to src

* hide popup at startup

* add eslint
2024-06-08 20:18:09 +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],
}),
});