- map-zones type gains territory and country border (informational political boundaries that never gate placement, default fills amber 0.1 / violet 0.06) - map-roads labelVisible is tri-state: unset means auto, where paved roads always label and dirt/trail only label at 4 m/px or finer (roadLabelShown) - migration clears the old implicit label default on non-paved roads - new pure snapping lib: findSnap (vertices own their neighborhood, edges must be twice as close), closestPointOnSegment, segmentMidpoints - tests for label angles, tri-state rule, snapping, political zones
115 lines
3 KiB
TypeScript
115 lines
3 KiB
TypeScript
import { CollectionConfig } from "payload";
|
|
import { requirePermission } from "@/utils/access-control/hasPermission";
|
|
import { validateHexColor } from "@/lib/map/style";
|
|
import { validatePolyline } from "@/lib/map/points";
|
|
|
|
/**
|
|
* Road network segments for a map, used by ground shipment routing.
|
|
* Points are [x, y] tuples in real meters on the map's grid. Roads connect
|
|
* where endpoints (or points) coincide within the routing epsilon; author
|
|
* them so shared endpoints use identical coordinates.
|
|
*/
|
|
export const MapRoads: CollectionConfig = {
|
|
slug: "map-roads",
|
|
admin: {
|
|
group: "World",
|
|
useAsTitle: "name",
|
|
},
|
|
access: {
|
|
read: ({ req }) => !!req.user,
|
|
create: requirePermission("maps:create"),
|
|
update: requirePermission("maps:update"),
|
|
delete: requirePermission("maps:delete"),
|
|
},
|
|
fields: [
|
|
{
|
|
name: "name",
|
|
type: "text",
|
|
admin: {
|
|
description: 'Road or route label (e.g. "Highway 1", "Kavala ridge trail").',
|
|
},
|
|
},
|
|
{
|
|
name: "description",
|
|
type: "textarea",
|
|
admin: {
|
|
description: "Shown in the road's tooltip and popup on the map.",
|
|
},
|
|
},
|
|
{
|
|
name: "map",
|
|
type: "relationship",
|
|
relationTo: "maps",
|
|
required: true,
|
|
},
|
|
{
|
|
name: "surface",
|
|
type: "select",
|
|
required: true,
|
|
defaultValue: "paved",
|
|
options: [
|
|
{ label: "Paved", value: "paved" },
|
|
{ label: "Dirt", value: "dirt" },
|
|
{ label: "Trail", value: "trail" },
|
|
],
|
|
},
|
|
{
|
|
name: "speedMultiplier",
|
|
type: "number",
|
|
required: true,
|
|
defaultValue: 1,
|
|
min: 0.1,
|
|
max: 5,
|
|
admin: {
|
|
description:
|
|
"Routing weight multiplier. Higher = faster/preferred (1 = neutral). Affects which route Dijkstra picks; fuel is charged on geometric length.",
|
|
},
|
|
},
|
|
{
|
|
name: "strokeColor",
|
|
type: "text",
|
|
validate: validateHexColor,
|
|
admin: {
|
|
description: "Line color as hex (e.g. #cbd5e1). Empty = default color for the surface.",
|
|
},
|
|
},
|
|
{
|
|
name: "strokeWeight",
|
|
type: "number",
|
|
min: 1,
|
|
max: 10,
|
|
defaultValue: 2,
|
|
admin: {
|
|
description: "Line thickness in pixels.",
|
|
},
|
|
},
|
|
{
|
|
name: "strokeStyle",
|
|
type: "select",
|
|
defaultValue: "solid",
|
|
options: [
|
|
{ label: "Solid", value: "solid" },
|
|
{ label: "Dashed", value: "dashed" },
|
|
{ label: "Dotted", value: "dotted" },
|
|
],
|
|
},
|
|
{
|
|
name: "labelVisible",
|
|
type: "checkbox",
|
|
label: "Show Name Label",
|
|
admin: {
|
|
description:
|
|
"Auto (unset): only paved roads show labels. Check to force on, uncheck to force off. The map authoring toolbar's Label select writes this.",
|
|
},
|
|
},
|
|
{
|
|
name: "points",
|
|
type: "json",
|
|
required: true,
|
|
validate: validatePolyline,
|
|
admin: {
|
|
description: "Array of [x, y] meter tuples in map order.",
|
|
},
|
|
},
|
|
],
|
|
};
|