refactor: easy polylabel algorithm to view polygon label

This commit is contained in:
taDuc
2026-05-12 18:43:12 +07:00
parent 7b1f7538ab
commit 51f432f0fe
6 changed files with 258 additions and 7 deletions
+13 -2
View File
@@ -10,8 +10,8 @@ import {
POLYGON_STROKE_BY_TYPE,
} from "@/uhm/lib/map/styles/style";
import { EMPTY_FEATURE_COLLECTION } from "@/uhm/lib/map/geo/constants";
import { PATH_ARROW_ICON_ID, PATH_ARROW_SOURCE_ID } from "@/uhm/lib/map/constants";
import { ensurePointGeotypeIcons, getAllGeotypeLayers } from "@/uhm/lib/map/styles/geotypes";
import { PATH_ARROW_ICON_ID, PATH_ARROW_SOURCE_ID, POLYGON_LABEL_SOURCE_ID } from "@/uhm/lib/map/constants";
import { ensurePointGeotypeIcons, getAllGeotypeLabelLayers, getAllGeotypeLayers } from "@/uhm/lib/map/styles/geotypes";
import {
applyBackgroundLayerVisibility,
buildTypeMatchExpression,
@@ -325,6 +325,12 @@ export function setupMapLayers(
promoteId: "id",
});
map.addSource(POLYGON_LABEL_SOURCE_ID, {
type: "geojson",
data: EMPTY_FEATURE_COLLECTION,
promoteId: "id",
});
ensurePointGeotypeIcons(map);
const geotypeLayers = getAllGeotypeLayers("countries", PATH_ARROW_SOURCE_ID, "places");
@@ -332,6 +338,11 @@ export function setupMapLayers(
map.addLayer(layer);
}
const geotypeLabelLayers = getAllGeotypeLabelLayers(POLYGON_LABEL_SOURCE_ID);
for (const layer of geotypeLabelLayers) {
map.addLayer(layer);
}
// editing overlays
map.addSource("edit-shape", {
type: "geojson",