mirror of
https://github.com/Maks1mS/free-ozon-dpr.git
synced 2024-12-23 18:42:59 +03:00
52 lines
1.1 KiB
JavaScript
52 lines
1.1 KiB
JavaScript
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;
|
|
} |