0
0
mirror of https://github.com/Maks1mS/free-ozon-dpr.git synced 2024-12-24 02:52:58 +03:00
free-ozon-dpr/utils.js

52 lines
1.1 KiB
JavaScript
Raw Normal View History

2024-06-05 14:56:19 +03:00
import { toLonLat } from "ol/proj";
import { getDistance } from "ol/sphere";
export function el(id) {
return document.getElementById(id);
}
export function removeDuplicatesByRadius(features, radius) {
const uniqueFeatures = [];
const coordinatesSet = new Set();
features.forEach((feature) => {
const coordinates = feature.getGeometry().getCoordinates();
const lonLat = toLonLat(coordinates);
let isDuplicate = false;
coordinatesSet.forEach((setCoordinates) => {
if (getDistance(setCoordinates, lonLat) <= radius) {
isDuplicate = true;
}
});
if (!isDuplicate) {
uniqueFeatures.push(feature);
coordinatesSet.add(lonLat);
}
});
return uniqueFeatures;
}
export function removeDuplicatesByUrl(features) {
const uniqueFeatures = [];
const urlSet = new Set();
features.forEach((feature) => {
let isDuplicate = false;
const link = feature.get("link");
if (urlSet.has(link)) {
isDuplicate = true;
}
if (!isDuplicate) {
uniqueFeatures.push(feature);
urlSet.add(link);
}
});
return uniqueFeatures;
}