@mapcairn/core 0.1.0-rc.1 → 0.1.0-rc.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/README.md +3 -1
- package/dist/contracts/mapAdapter.contract.js +29 -0
- package/dist/contracts/mapAdapter.contract.js.map +1 -1
- package/dist/directions/directions.js +10 -21
- package/dist/directions/directions.js.map +1 -1
- package/dist/fakes/FakeLayerSource.js +3 -3
- package/dist/fakes/FakeLayerSource.js.map +1 -1
- package/dist/fakes/FakeMapAdapter.js +1 -1
- package/dist/fakes/FakeMapAdapter.js.map +1 -1
- package/dist/index.d.ts +78 -10
- package/dist/index.js +4 -3
- package/dist/layers/feed.js +86 -9
- package/dist/layers/feed.js.map +1 -1
- package/dist/layers/query.js +82 -8
- package/dist/layers/query.js.map +1 -1
- package/dist/spatial/boundsOfPaths.js +122 -0
- package/dist/spatial/boundsOfPaths.js.map +1 -0
- package/dist/spatial/boundsOfPoints.js +26 -13
- package/dist/spatial/boundsOfPoints.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -6,6 +6,8 @@ It has no dependency on another MapCairn package, React, a map engine or a brows
|
|
|
6
6
|
|
|
7
7
|
**Status:** a release candidate, for early adopters. The API is still settling, so a breaking change can land before `0.1.0`; the [changelog](https://github.com/MapCairn/mapcairn/blob/main/CHANGELOG.md) lists each one. Until `0.1.0`, add `@next` to every package name in the install commands below.
|
|
8
8
|
|
|
9
|
+
If you would rather install and import the whole SDK once, [`@mapcairn/sdk`](https://github.com/MapCairn/mapcairn/tree/main/packages/sdk) re-exports this package with the others.
|
|
10
|
+
|
|
9
11
|
## Install
|
|
10
12
|
|
|
11
13
|
```bash
|
|
@@ -50,7 +52,7 @@ The Source column names folders under `packages/core/src` in the repository.
|
|
|
50
52
|
| Fakes | `src/fakes` | In-memory implementations of every port (`FakeMapAdapter`, `FakeSearchProvider`, `MemorySettingsStore` and so on) and `createFakeServices()`, for unit tests that run with no browser, WebGL or network. `pngHeader` and `readPngSize` build and read the start of a PNG (`readPngSize` gives `undefined` for bytes that are not one), so a test can check the size of an image a fake or an adapter made. |
|
|
51
53
|
| Contract suites | `src/contracts` (`@mapcairn/core/contracts`) | One shared suite per port, run against the fake and the real adapter, so they cannot drift apart. `PORT_REGISTRY` lists them. |
|
|
52
54
|
| Surface and sheet | `src/surface`, `src/sheet`, `src/layout` | The surface state machine (`surfaceReducer` and its actions), sheet detents and snapping, and the chrome layout rules. |
|
|
53
|
-
| Map maths | `src/zoom`, `src/scale`, `src/format`, `src/units`, `src/spatial` | Zoom conversion (the app uses 256 px tile zoom, the engine zoom is one lower), metres per pixel, the scale bar, coordinate and number formatting, unit conversion, and line distance and polygon area measurement (`measureLineDistance`, `measurePolygonArea`), the bounds of a set of points (`boundsOfPoints`) and rounding a position before a reverse lookup (`roundForLookup`).
|
|
55
|
+
| Map maths | `src/zoom`, `src/scale`, `src/format`, `src/units`, `src/spatial` | Zoom conversion (the app uses 256 px tile zoom, the engine zoom is one lower), metres per pixel, the scale bar, coordinate and number formatting, unit conversion, and line distance and polygon area measurement (`measureLineDistance`, `measurePolygonArea`), the bounds of a set of points (`boundsOfPoints`, which takes the short way across the antimeridian, so `east` passes 180 for points on both sides of it) and of the rings and lines of a shape (`boundsOfPaths`, which also holds every edge, so a sparse shape wider than half the globe is fitted on the side it covers) and rounding a position before a reverse lookup (`roundForLookup`). |
|
|
54
56
|
| Coordinates | `src/coordinates` | `parseCoordinates`, which reads typed coordinates (decimal degrees, degrees minutes and seconds, hemisphere letters, and a language's own letters and words when given its catalogue) in linear time and refuses anything ambiguous or out of range, and `coordinateSearchResult`, which turns such text into one `SearchResult` so a search box can answer it without a geocoder request. |
|
|
55
57
|
| Geometry | `src/geometry` | Pure helpers over GeoJSON geometries and features: `buffer` (metres, with a step count), `union`, `intersect`, `difference`, `simplify` (tolerance in metres), `centroid`, `boundingBox` with `boundingBoxToBounds`, `pointInPolygon` (holes and multipolygons) and `geometryLength` and `geometryArea` (built on the measurement helpers). `wgs84ToWebMercator` and `webMercatorToWgs84` convert between EPSG:4326 and EPSG:3857. `parseWkt` and `formatWkt` read and write Well-Known Text with a hand-written tokenizer, so hostile text takes linear time; the reader takes longitude then latitude unless given `axisOrder: "lat-lng"`, accepts an EWKT `SRID=4326;` prefix at the start of a geometry and refuses any other SRID with an `UnsupportedSridError` (an `unsupported` `GeometryError` that carries the `srid`), `readWktSequence` reads several geometries one after another without checking their shapes, for a caller that applies its own rules, and gives up at the first fault, `readWktRecovering` is its forgiving sibling that gives each stretch of the text in turn as a geometry or as the `GeometryError` for it and goes on after one it cannot use, and `startsLikeWkt` says whether a text starts with a WKT type name or an SRID prefix. Every helper checks its input and throws a `GeometryError` (`invalid`, `empty` or `unsupported`). Longitude is a flat axis: a buffer that would cross the antimeridian or enclose a pole is refused, and a shape that crosses 180 degrees must be split first. The geometry helpers (WKT, Web Mercator conversion, union, intersect, difference, simplify, centroid, point in polygon, bounding box and length) are deliberate SDK surface for hosts that need them. The reference host does not use most of them yet. |
|
|
56
58
|
| Keyboard, announcements and URL | `src/keyboard`, `src/announce`, `src/urlHash` | The map key bindings and their help text, the announcement strings for screen readers, and `#map=` parsing and serialising. |
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { readPngSize } from "../fakes/pngHeader.js";
|
|
2
|
+
import { wrapLongitude } from "../globe/longitude.js";
|
|
2
3
|
import { MAX_IMAGE_SIDE_PX } from "../imageExport/plan.js";
|
|
3
4
|
import { MapEngineError, MapImageExportError } from "../ports/errors.js";
|
|
4
5
|
import { afterEach, describe, expect, it } from "vitest";
|
|
@@ -198,6 +199,34 @@ function runMapAdapterContract(name, create) {
|
|
|
198
199
|
expect(northEast.x).toBeLessThanOrEqual(controls.hostSize.width + 1);
|
|
199
200
|
expect(southWest.y).toBeLessThanOrEqual(controls.hostSize.height + 1);
|
|
200
201
|
});
|
|
202
|
+
it("fits a box across the antimeridian the short way", async () => {
|
|
203
|
+
const { adapter, controls } = await mounted();
|
|
204
|
+
const bounds = {
|
|
205
|
+
south: -17.5,
|
|
206
|
+
west: 179.2,
|
|
207
|
+
north: -16.5,
|
|
208
|
+
east: 181.4
|
|
209
|
+
};
|
|
210
|
+
adapter.fitBounds(bounds, {
|
|
211
|
+
...NO_ANIMATION,
|
|
212
|
+
maxZoom: 12
|
|
213
|
+
});
|
|
214
|
+
await controls.settle();
|
|
215
|
+
const view = adapter.getView();
|
|
216
|
+
expect(view.zoom).toBeGreaterThan(5);
|
|
217
|
+
expect(view.center.lat).toBeCloseTo(-17, 1);
|
|
218
|
+
expect(view.center.lng).toBeCloseTo(-179.7, 1);
|
|
219
|
+
const southWest = adapter.project({
|
|
220
|
+
lat: bounds.south,
|
|
221
|
+
lng: wrapLongitude(179.2)
|
|
222
|
+
});
|
|
223
|
+
const northEast = adapter.project({
|
|
224
|
+
lat: bounds.north,
|
|
225
|
+
lng: wrapLongitude(181.4)
|
|
226
|
+
});
|
|
227
|
+
expect(southWest.x).toBeGreaterThanOrEqual(-1);
|
|
228
|
+
expect(northEast.x).toBeLessThanOrEqual(controls.hostSize.width + 1);
|
|
229
|
+
});
|
|
201
230
|
it("projects the view centre to the middle of the host", async () => {
|
|
202
231
|
const { adapter, controls } = await mounted();
|
|
203
232
|
const point = adapter.project(adapter.getView().center);
|