@mark1russell7/cartography 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -15,71 +15,6 @@ var MapError = class extends Error {
15
15
  this.code = code;
16
16
  }
17
17
  };
18
- // src/filter.ts
19
- /** This function gives the kind of a geometry. */
20
- function geometryKind(geometry) {
21
- switch (geometry.type) {
22
- case "Point":
23
- case "MultiPoint": return "point";
24
- case "LineString":
25
- case "MultiLineString": return "line";
26
- case "Polygon":
27
- case "MultiPolygon": return "area";
28
- case "GeometryCollection": {
29
- const kinds = new Set(geometry.geometries.map(geometryKind));
30
- return kinds.size === 1 ? [...kinds][0] : "mixed";
31
- }
32
- }
33
- }
34
- /** This function tells if a feature matches a filter. A feature with no geometry matches no `{ geometry }` filter. */
35
- function matchesFilter(filter, feature) {
36
- if ("all" in filter) return filter.all.every((item) => matchesFilter(item, feature));
37
- if ("any" in filter) return filter.any.some((item) => matchesFilter(item, feature));
38
- if ("not" in filter) return !matchesFilter(filter.not, feature);
39
- if ("geometry" in filter) return feature.geometry !== null && geometryKind(feature.geometry) === filter.geometry;
40
- const properties = feature.properties ?? {};
41
- const has = Object.hasOwn(properties, filter.property);
42
- if ("exists" in filter) return has === filter.exists;
43
- return has && filter.in.includes(properties[filter.property]);
44
- }
45
- const KINDS = [
46
- "point",
47
- "line",
48
- "area",
49
- "mixed"
50
- ];
51
- /**
52
- * This function refuses a value that is not a `Filter`, for example a filter from JSON.
53
- *
54
- * @throws MapError - The code is `filter`.
55
- */
56
- function checkFilter(filter, path = "filter") {
57
- const fail = (reason) => {
58
- throw new MapError("filter", `${path}: ${reason}`);
59
- };
60
- if (typeof filter !== "object" || filter === null || Array.isArray(filter)) fail("a filter must be an object");
61
- const value = filter;
62
- const keys = Object.keys(value).toSorted().join(",");
63
- if (keys === "all" || keys === "any") {
64
- const items = value[keys];
65
- if (!Array.isArray(items)) fail(`the member ${keys} must be an array`);
66
- items.forEach((item, i) => checkFilter(item, `${path}.${keys}[${i}]`));
67
- } else if (keys === "not") checkFilter(value["not"], `${path}.not`);
68
- else if (keys === "geometry") {
69
- if (!KINDS.includes(value["geometry"])) fail(`the geometry must be one of ${KINDS.join(", ")}`);
70
- } else if (keys === "in,property" || keys === "exists,property") {
71
- if (typeof value["property"] !== "string") fail("the property must be a string");
72
- if (keys === "exists,property" && typeof value["exists"] !== "boolean") fail("the member exists must be true or false");
73
- if (keys === "in,property") {
74
- const items = value["in"];
75
- if (!Array.isArray(items) || !items.every((item) => [
76
- "string",
77
- "number",
78
- "boolean"
79
- ].includes(typeof item))) fail("the member in must be an array of strings, numbers and booleans");
80
- }
81
- } else fail(`the members ${keys === "" ? "(none)" : keys} are not a form of a filter`);
82
- }
83
18
  // src/frame.ts
84
19
  /**
85
20
  * The frame of a map: the part of the Earth that the map shows, its scale and its size on the paper.
@@ -165,6 +100,308 @@ function frameBBox(frame) {
165
100
  }
166
101
  return bboxOfPoints(points);
167
102
  }
103
+ /** The first digits of a round scale, for example 1:25,000 or 1:1,500,000. `frameAround` rounds a scale up to one of them. */
104
+ const NICE_SCALE_STEPS = [
105
+ 1,
106
+ 1.25,
107
+ 1.5,
108
+ 2,
109
+ 2.5,
110
+ 3,
111
+ 4,
112
+ 5,
113
+ 6,
114
+ 7.5
115
+ ];
116
+ /** This function gives the smallest round scale that is not less than the value, from `NICE_SCALE_STEPS`. */
117
+ function niceScale(value) {
118
+ if (!(Number.isFinite(value) && value > 0)) throw new MapError("frame", `The scale ${value} is not a finite number more than 0`);
119
+ const power = 10 ** Math.floor(Math.log10(value));
120
+ for (const step of [...NICE_SCALE_STEPS, 10]) if (step * power >= value * (1 - 1e-9)) return step * power;
121
+ return 10 * power;
122
+ }
123
+ /**
124
+ * This function gives the frame with the largest scale that shows each point inside the margin.
125
+ *
126
+ * - The center is the middle of the box of the points, or the option `center`. The frame has the center at the middle
127
+ * of the paper, so the space on the two sides of the center is the same.
128
+ * - The function finds the scale on the plane of the projection, as `frameView` uses it.
129
+ * - With `roundScale`, the scale goes up to a round value. A larger denominator shows more ground, so each point stays inside.
130
+ *
131
+ * @throws MapError - The code is `frame`: no point, a size or a margin that is not correct, or all the points at the center.
132
+ */
133
+ function frameAround(points, options) {
134
+ const { widthMm, heightMm } = options;
135
+ const margin = options.marginMm ?? 0;
136
+ if (points.length === 0) throw new MapError("frame", "The frame has no point to show");
137
+ if (!(Number.isFinite(margin) && margin >= 0)) throw new MapError("frame", `The margin ${margin} is not a finite number from 0`);
138
+ checkFrame({
139
+ projection: options.projection(points[0]),
140
+ center: points[0],
141
+ scale: 1,
142
+ widthMm,
143
+ heightMm
144
+ });
145
+ const halfWidth = widthMm / 2 - margin;
146
+ const halfHeight = heightMm / 2 - margin;
147
+ if (halfWidth <= 0 || halfHeight <= 0) throw new MapError("frame", `The margin ${margin} mm leaves no space in the frame`);
148
+ const box = bboxOfPoints(points);
149
+ const center = options.center ?? {
150
+ lat: (box.south + box.north) / 2,
151
+ lon: (box.west + box.east) / 2
152
+ };
153
+ const projection = options.projection(center);
154
+ const origin = projection.toPlane(center);
155
+ let reachX = 0;
156
+ let reachY = 0;
157
+ for (const point of points) {
158
+ const plane = projection.toPlane(point);
159
+ reachX = Math.max(reachX, Math.abs(plane.x - origin.x));
160
+ reachY = Math.max(reachY, Math.abs(plane.y - origin.y));
161
+ }
162
+ if (reachX === 0 && reachY === 0) throw new MapError("frame", "All the points are at the center, so no scale fits them");
163
+ const planeMetersPerMm = Math.max(reachX / halfWidth, reachY / halfHeight);
164
+ const factors = projection.scale(center);
165
+ const exact = planeMetersPerMm * 1e3 * Math.sqrt(factors.max * factors.min);
166
+ return {
167
+ projection,
168
+ center,
169
+ scale: options.roundScale === false ? exact : niceScale(exact),
170
+ widthMm,
171
+ heightMm
172
+ };
173
+ }
174
+ // src/atlas.ts
175
+ /** The default width of the overlap of neighbor pages, in millimetres. */
176
+ const ATLAS_OVERLAP_MM = 10;
177
+ /**
178
+ * This function gives the name of a column: A to Z, then AA, AB and the next names.
179
+ *
180
+ * @throws MapError - The code is `atlas`. The index is not an integer of 0 or more.
181
+ */
182
+ function columnName(index) {
183
+ if (!(Number.isInteger(index) && index >= 0)) throw new MapError("atlas", `The column ${index} is not an integer of 0 or more`);
184
+ let name = "";
185
+ for (let rest = index + 1; rest > 0; rest = Math.floor((rest - 1) / 26)) name = String.fromCharCode(65 + (rest - 1) % 26) + name;
186
+ return name;
187
+ }
188
+ /**
189
+ * This function gives the pages of an atlas: a grid of frames on the plane of the projection.
190
+ * The middle of the grid is at the center of the area.
191
+ *
192
+ * - Neighbor pages share a strip of `overlapMm` at their common edge.
193
+ * - The grid has the smallest number of columns and rows that shows the full circle.
194
+ * - Each page has the scale of the plan at its own center. For `azimuthalEquidistant` over 50 km, the edges of neighbor pages agree to 0.01 mm.
195
+ *
196
+ * @throws MapError - The code is `frame` or `atlas`.
197
+ */
198
+ function atlasPages(plan) {
199
+ const overlapMm = plan.overlapMm ?? 10;
200
+ checkFrame(plan);
201
+ if (!(Number.isFinite(plan.radiusMeters) && plan.radiusMeters > 0)) throw new MapError("atlas", `The radius ${plan.radiusMeters} of the atlas is not a finite number more than 0`);
202
+ if (!(Number.isFinite(overlapMm) && overlapMm >= 0 && overlapMm < Math.min(plan.widthMm, plan.heightMm) / 2)) throw new MapError("atlas", `The overlap ${overlapMm} of the atlas is not from 0 to less than half of the smaller side of the page`);
203
+ const middle = frameView(plan);
204
+ const origin = plan.projection.toPlane(plan.center);
205
+ const radiusMm = plan.radiusMeters * middle.mmPerMeter;
206
+ const stepX = plan.widthMm - overlapMm;
207
+ const stepY = plan.heightMm - overlapMm;
208
+ const columns = Math.max(1, Math.ceil((2 * radiusMm - plan.widthMm) / stepX) + 1);
209
+ const rows = Math.max(1, Math.ceil((2 * radiusMm - plan.heightMm) / stepY) + 1);
210
+ const offsetX = (column) => (column - (columns - 1) / 2) * stepX;
211
+ const offsetY = (row) => ((rows - 1) / 2 - row) * stepY;
212
+ const shows = (column, row) => {
213
+ if (column < 0 || column >= columns || row < 0 || row >= rows) return false;
214
+ const dx = Math.max(Math.abs(offsetX(column)) - plan.widthMm / 2, 0);
215
+ const dy = Math.max(Math.abs(offsetY(row)) - plan.heightMm / 2, 0);
216
+ return dx * dx + dy * dy < radiusMm * radiusMm;
217
+ };
218
+ const name = (column, row) => `${columnName(column)}${row + 1}`;
219
+ const pages = [];
220
+ for (let row = 0; row < rows; row += 1) for (let column = 0; column < columns; column += 1) {
221
+ if (!shows(column, row)) continue;
222
+ const center = plan.projection.fromPlane({
223
+ x: origin.x + offsetX(column) / middle.mmPerPlaneMeter,
224
+ y: origin.y + offsetY(row) / middle.mmPerPlaneMeter
225
+ });
226
+ const neighbors = {};
227
+ for (const [edge, dc, dr] of [
228
+ [
229
+ "top",
230
+ 0,
231
+ -1
232
+ ],
233
+ [
234
+ "right",
235
+ 1,
236
+ 0
237
+ ],
238
+ [
239
+ "bottom",
240
+ 0,
241
+ 1
242
+ ],
243
+ [
244
+ "left",
245
+ -1,
246
+ 0
247
+ ]
248
+ ]) if (shows(column + dc, row + dr)) neighbors[edge] = name(column + dc, row + dr);
249
+ const frame = {
250
+ projection: plan.projection,
251
+ center,
252
+ scale: plan.scale,
253
+ widthMm: plan.widthMm,
254
+ heightMm: plan.heightMm
255
+ };
256
+ pages.push({
257
+ id: name(column, row),
258
+ column,
259
+ row,
260
+ frame,
261
+ neighbors
262
+ });
263
+ }
264
+ return {
265
+ plan,
266
+ columns,
267
+ rows,
268
+ pages
269
+ };
270
+ }
271
+ /**
272
+ * This function gives the outline of each page of an atlas as a polygon feature, with the name of the page in the property `id`.
273
+ * A layer of an index map draws them. Each edge has `pointsPerEdge` points, because the edges of the pages are curves on the Earth.
274
+ *
275
+ * @throws MapError - The code is `atlas`. The number of points is not an integer of 1 or more.
276
+ */
277
+ function atlasOutlines(atlas, pointsPerEdge = 16) {
278
+ if (!(Number.isInteger(pointsPerEdge) && pointsPerEdge >= 1)) throw new MapError("atlas", `The number of points ${pointsPerEdge} of an edge is not an integer of 1 or more`);
279
+ return atlas.pages.map((page) => {
280
+ const view = frameView(page.frame);
281
+ const { widthMm: w, heightMm: h } = page.frame;
282
+ const ring = [];
283
+ for (let i = 0; i < pointsPerEdge; i += 1) ring.push(lonLat(view.fromPaper({
284
+ x: i / pointsPerEdge * w,
285
+ y: 0
286
+ })));
287
+ for (let i = 0; i < pointsPerEdge; i += 1) ring.push(lonLat(view.fromPaper({
288
+ x: w,
289
+ y: i / pointsPerEdge * h
290
+ })));
291
+ for (let i = 0; i < pointsPerEdge; i += 1) ring.push(lonLat(view.fromPaper({
292
+ x: w - i / pointsPerEdge * w,
293
+ y: h
294
+ })));
295
+ for (let i = 0; i < pointsPerEdge; i += 1) ring.push(lonLat(view.fromPaper({
296
+ x: 0,
297
+ y: h - i / pointsPerEdge * h
298
+ })));
299
+ ring.reverse();
300
+ ring.push(ring[0]);
301
+ return {
302
+ type: "Feature",
303
+ geometry: {
304
+ type: "Polygon",
305
+ coordinates: [ring]
306
+ },
307
+ properties: { id: page.id }
308
+ };
309
+ });
310
+ }
311
+ /**
312
+ * This function gives the frame of an index map of an atlas. The frame shows all the pages of the grid in the space, at the largest scale.
313
+ * Its center is the middle of the grid.
314
+ *
315
+ * @throws MapError - The code is `frame`.
316
+ */
317
+ function atlasIndexFrame(atlas, widthMm, heightMm) {
318
+ const { plan } = atlas;
319
+ checkFrame({
320
+ ...plan,
321
+ widthMm,
322
+ heightMm
323
+ });
324
+ const overlapMm = plan.overlapMm ?? 10;
325
+ const gridWidthMm = (atlas.columns - 1) * (plan.widthMm - overlapMm) + plan.widthMm;
326
+ const gridHeightMm = (atlas.rows - 1) * (plan.heightMm - overlapMm) + plan.heightMm;
327
+ const scale = plan.scale * Math.max(gridWidthMm / widthMm, gridHeightMm / heightMm);
328
+ return {
329
+ projection: plan.projection,
330
+ center: plan.center,
331
+ scale,
332
+ widthMm,
333
+ heightMm
334
+ };
335
+ }
336
+ /** This function gives the GeoJSON position `[lon, lat]` of a point. */
337
+ function lonLat(point) {
338
+ return [point.lon, point.lat];
339
+ }
340
+ // src/filter.ts
341
+ /** This function gives the kind of a geometry. */
342
+ function geometryKind(geometry) {
343
+ switch (geometry.type) {
344
+ case "Point":
345
+ case "MultiPoint": return "point";
346
+ case "LineString":
347
+ case "MultiLineString": return "line";
348
+ case "Polygon":
349
+ case "MultiPolygon": return "area";
350
+ case "GeometryCollection": {
351
+ const kinds = new Set(geometry.geometries.map(geometryKind));
352
+ return kinds.size === 1 ? [...kinds][0] : "mixed";
353
+ }
354
+ }
355
+ }
356
+ /** This function tells if a feature matches a filter. A feature with no geometry matches no `{ geometry }` filter. */
357
+ function matchesFilter(filter, feature) {
358
+ if ("all" in filter) return filter.all.every((item) => matchesFilter(item, feature));
359
+ if ("any" in filter) return filter.any.some((item) => matchesFilter(item, feature));
360
+ if ("not" in filter) return !matchesFilter(filter.not, feature);
361
+ if ("geometry" in filter) return feature.geometry !== null && geometryKind(feature.geometry) === filter.geometry;
362
+ const properties = feature.properties ?? {};
363
+ const has = Object.hasOwn(properties, filter.property);
364
+ if ("exists" in filter) return has === filter.exists;
365
+ return has && filter.in.includes(properties[filter.property]);
366
+ }
367
+ const KINDS = [
368
+ "point",
369
+ "line",
370
+ "area",
371
+ "mixed"
372
+ ];
373
+ /**
374
+ * This function refuses a value that is not a `Filter`, for example a filter from JSON.
375
+ *
376
+ * @throws MapError - The code is `filter`.
377
+ */
378
+ function checkFilter(filter, path = "filter") {
379
+ const fail = (reason) => {
380
+ throw new MapError("filter", `${path}: ${reason}`);
381
+ };
382
+ if (typeof filter !== "object" || filter === null || Array.isArray(filter)) fail("a filter must be an object");
383
+ const value = filter;
384
+ const keys = Object.keys(value).toSorted().join(",");
385
+ if (keys === "all" || keys === "any") {
386
+ const items = value[keys];
387
+ if (!Array.isArray(items)) fail(`the member ${keys} must be an array`);
388
+ items.forEach((item, i) => checkFilter(item, `${path}.${keys}[${i}]`));
389
+ } else if (keys === "not") checkFilter(value["not"], `${path}.not`);
390
+ else if (keys === "geometry") {
391
+ if (!KINDS.includes(value["geometry"])) fail(`the geometry must be one of ${KINDS.join(", ")}`);
392
+ } else if (keys === "in,property" || keys === "exists,property") {
393
+ if (typeof value["property"] !== "string") fail("the property must be a string");
394
+ if (keys === "exists,property" && typeof value["exists"] !== "boolean") fail("the member exists must be true or false");
395
+ if (keys === "in,property") {
396
+ const items = value["in"];
397
+ if (!Array.isArray(items) || !items.every((item) => [
398
+ "string",
399
+ "number",
400
+ "boolean"
401
+ ].includes(typeof item))) fail("the member in must be an array of strings, numbers and booleans");
402
+ }
403
+ } else fail(`the members ${keys === "" ? "(none)" : keys} are not a form of a filter`);
404
+ }
168
405
  // src/style.ts
169
406
  /**
170
407
  * The black and white styles of the layers: lines with dashes, areas with gray levels and hatches, and point symbols.
@@ -525,7 +762,7 @@ function areaOnFrame(area, view) {
525
762
  * - Each point symbol of the layers and the north arrow are obstacles too.
526
763
  * - A text with a part on the frame and no free place is in `skipped`. A text with no part on the frame is in neither list.
527
764
  *
528
- * @param obstacles - The boxes on the paper that no label covers, as the middle and the half size in millimetres.
765
+ * @param obstacles - The boxes on the paper that no label covers, as the middle and the half size in millimetres. A box with `halfHeight` has the half width `half`.
529
766
  * @throws MapError - The code is `label`: the width of a text from `measure` is not a finite number of 0 or more.
530
767
  */
531
768
  function placeLabels(layers, view, font, obstacles = []) {
@@ -534,7 +771,7 @@ function placeLabels(layers, view, font, obstacles = []) {
534
771
  x: o.x,
535
772
  y: o.y,
536
773
  hw: o.half,
537
- hh: o.half,
774
+ hh: o.halfHeight ?? o.half,
538
775
  angle: 0
539
776
  });
540
777
  for (const layer of layers) {
@@ -650,7 +887,7 @@ function labelsSvg(placement, font) {
650
887
  }
651
888
  // src/marks.ts
652
889
  /**
653
- * The marks of a map: the scale bar and the north arrow.
890
+ * The marks of a map: the scale bar, the north arrow and the texts at the edges of the frame.
654
891
  *
655
892
  * @packageDocumentation
656
893
  */
@@ -711,6 +948,57 @@ function scaleBarSvg(x, y, length, mmPerMeter) {
711
948
  function northArrowSvg(x, y, northDegrees) {
712
949
  return `<g class="north-arrow" transform="translate(${mm(x)} ${mm(y)}) rotate(${mm(northDegrees)})"><circle r="4.5" fill="#ffffff" stroke="#000000" stroke-width="0.2"/><path d="M0 -3.6L1.6 1.2L0 0.4L-1.6 1.2Z" fill="#000000"/><text y="3.9" font-size="2.2" text-anchor="middle">N</text></g>`;
713
950
  }
951
+ /** The four edges of a frame, in the sequence of the marks. */
952
+ const FRAME_EDGES = [
953
+ "top",
954
+ "right",
955
+ "bottom",
956
+ "left"
957
+ ];
958
+ /** The size of the font of a text at an edge of the frame, in millimetres. */
959
+ const EDGE_TEXT_MM = 2.6;
960
+ /** The space in the box of an edge text around the arrow and the text, and the size of the arrow, in millimetres. */
961
+ const EDGE = {
962
+ pad: .8,
963
+ arrow: 1.8,
964
+ gap: .7
965
+ };
966
+ /** The angle of the arrow of each edge. The arrow points out of the frame. */
967
+ const EDGE_TURN = {
968
+ top: 0,
969
+ right: 90,
970
+ bottom: 180,
971
+ left: 270
972
+ };
973
+ /**
974
+ * This function gives the marks of the texts at the middle of the edges of a frame, in the sequence top, right, bottom and left.
975
+ * An edge with no text has no mark.
976
+ *
977
+ * @param measure - This function gives the width of a text in millimetres at the size `EDGE_TEXT_MM`.
978
+ */
979
+ function edgeMarks(widthMm, heightMm, texts, measure) {
980
+ return FRAME_EDGES.flatMap((edge) => {
981
+ const text = texts[edge];
982
+ if (text === void 0) return [];
983
+ const boxWidth = 2 * EDGE.pad + EDGE.arrow + EDGE.gap + measure(text);
984
+ const boxHeight = 2 * EDGE.pad + EDGE_TEXT_MM;
985
+ const x = edge === "left" ? boxWidth / 2 : edge === "right" ? widthMm - boxWidth / 2 : widthMm / 2;
986
+ const y = edge === "top" ? boxHeight / 2 : edge === "bottom" ? heightMm - boxHeight / 2 : heightMm / 2;
987
+ const left = x - boxWidth / 2;
988
+ const top = y - boxHeight / 2;
989
+ const arrowX = left + EDGE.pad + EDGE.arrow / 2;
990
+ const half = EDGE.arrow / 2;
991
+ const svg = `<g class="edge-${edge}"><rect x="${mm(left)}" y="${mm(top)}" width="${mm(boxWidth)}" height="${mm(boxHeight)}" fill="#ffffff" stroke="#000000" stroke-width="0.2"/><path transform="translate(${mm(arrowX)} ${mm(y)}) rotate(${EDGE_TURN[edge]})" d="M0 ${mm(-half)}L${mm(half)} ${mm(half)}L${mm(-half)} ${mm(half)}Z" fill="#000000"/><text x="${mm(arrowX + half + EDGE.gap)}" y="${mm(y + EDGE_TEXT_MM * .35)}" font-size="${EDGE_TEXT_MM}" font-weight="bold">${escapeHtml(text)}</text></g>`;
992
+ return [{
993
+ edge,
994
+ x,
995
+ y,
996
+ halfWidth: boxWidth / 2,
997
+ halfHeight: boxHeight / 2,
998
+ svg
999
+ }];
1000
+ });
1001
+ }
714
1002
  // src/render.ts
715
1003
  /**
716
1004
  * A map as data, and its render to SVG.
@@ -748,6 +1036,13 @@ function checkMap(map) {
748
1036
  if (layer.label !== void 0) checkLabelRule(layer.label, layer.id);
749
1037
  if (layer.simplifyMm !== void 0 && !(Number.isFinite(layer.simplifyMm) && layer.simplifyMm > 0)) throw new MapError("style", `The layer "${layer.id}": the tolerance ${layer.simplifyMm} is not a finite number more than 0`);
750
1038
  }
1039
+ if (map.edges !== void 0) {
1040
+ if (typeof map.edges !== "object" || map.edges === null) throw new MapError("label", "The edge texts of the map are not an object");
1041
+ for (const [edge, text] of Object.entries(map.edges)) {
1042
+ if (!FRAME_EDGES.includes(edge)) throw new MapError("label", `The edge "${edge}" is not top, right, bottom or left`);
1043
+ if (text !== void 0 && (typeof text !== "string" || text.trim() === "")) throw new MapError("label", `The text of the edge "${edge}" is not a text that is not empty`);
1044
+ }
1045
+ }
751
1046
  }
752
1047
  /** The box of the points on the paper that a feature uses. */
753
1048
  var PaperBox = class {
@@ -832,12 +1127,22 @@ const NORTH_ARROW = {
832
1127
  inset: 6.5,
833
1128
  half: 4.7
834
1129
  };
1130
+ /** This function gives the marks of the edge texts of a map. Without a font, the width of a text is an estimate. */
1131
+ function edgeMarksOf(map, font) {
1132
+ const measure = (text) => font === void 0 ? text.length * EDGE_TEXT_MM * CHARACTER_WIDTH : font.measure(text, EDGE_TEXT_MM);
1133
+ return edgeMarks(map.frame.widthMm, map.frame.heightMm, map.edges ?? {}, measure);
1134
+ }
835
1135
  function placementOf(map, features, view, font) {
836
- const obstacles = map.northArrow === false ? [] : [{
1136
+ const obstacles = [...map.northArrow === false ? [] : [{
837
1137
  x: map.frame.widthMm - NORTH_ARROW.inset,
838
1138
  y: NORTH_ARROW.inset,
839
1139
  half: NORTH_ARROW.half
840
- }];
1140
+ }], ...edgeMarksOf(map, font).map((mark) => ({
1141
+ x: mark.x,
1142
+ y: mark.y,
1143
+ half: mark.halfWidth,
1144
+ halfHeight: mark.halfHeight
1145
+ }))];
841
1146
  return placeLabels(map.layers.map((layer, i) => ({
842
1147
  id: layer.id,
843
1148
  features: features[i],
@@ -1055,8 +1360,9 @@ function renderMap(map, options = {}) {
1055
1360
  const total = firstLine + (lines.length - 1) * 3 + 1.5;
1056
1361
  const width = side ? sideX + layout.columnMm : w;
1057
1362
  const arrow = map.northArrow === false ? "" : northArrowSvg(w - 6.5, 6.5, view.northDegrees);
1058
- return `<svg xmlns="http://www.w3.org/2000/svg" width="${mm(width)}mm" height="${mm(total)}mm" viewBox="0 0 ${mm(width)} ${mm(total)}" role="img" aria-label="${escapeAttribute(map.title)}" font-family="sans-serif"><title>${escapeHtml(map.title)}</title><defs>${defs.join("")}</defs><rect width="${mm(width)}" height="${mm(total)}" fill="#ffffff"/><g clip-path="url(#${map.id}-clip)">${layers.join("")}</g>${labels}<rect width="${mm(w)}" height="${mm(h)}" fill="none" stroke="#000000" stroke-width="0.3"/>${arrow}<g class="legend">${scaleBars}${legend}</g><g class="attribution">${attribution}</g></svg>`;
1363
+ const edges = edgeMarksOf(map, measureFontOf(options)).map((mark) => mark.svg).join("");
1364
+ return `<svg xmlns="http://www.w3.org/2000/svg" width="${mm(width)}mm" height="${mm(total)}mm" viewBox="0 0 ${mm(width)} ${mm(total)}" role="img" aria-label="${escapeAttribute(map.title)}" font-family="sans-serif"><title>${escapeHtml(map.title)}</title><defs>${defs.join("")}</defs><rect width="${mm(width)}" height="${mm(total)}" fill="#ffffff"/><g clip-path="url(#${map.id}-clip)">${layers.join("")}</g>${labels}<rect width="${mm(w)}" height="${mm(h)}" fill="none" stroke="#000000" stroke-width="0.3"/>${arrow}${edges}<g class="legend">${scaleBars}${legend}</g><g class="attribution">${attribution}</g></svg>`;
1059
1365
  }
1060
- export { MapError, SCALE_BAR_ROW_MM, attributionLines, checkFilter, checkFrame, checkLabelRule, checkMap, checkStyle, fitFrame, frameBBox, frameView, geometryKind, grayColor, hatchPattern, labelText, labelsSvg, mapLabels, mapMargins, matchesFilter, mm, niceNumber, northArrowSvg, placeLabels, pointSymbol, renderMap, scaleBarLength, scaleBarSvg, strokeAttributes };
1366
+ export { ATLAS_OVERLAP_MM, EDGE_TEXT_MM, FRAME_EDGES, MapError, NICE_SCALE_STEPS, SCALE_BAR_ROW_MM, atlasIndexFrame, atlasOutlines, atlasPages, attributionLines, checkFilter, checkFrame, checkLabelRule, checkMap, checkStyle, columnName, edgeMarks, fitFrame, frameAround, frameBBox, frameView, geometryKind, grayColor, hatchPattern, labelText, labelsSvg, mapLabels, mapMargins, matchesFilter, mm, niceNumber, niceScale, northArrowSvg, placeLabels, pointSymbol, renderMap, scaleBarLength, scaleBarSvg, strokeAttributes };
1061
1367
 
1062
1368
  //# sourceMappingURL=index.js.map