@trackunit/react-map-draw 0.0.46 → 0.0.47
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/index.cjs.js +7 -12
- package/index.esm.js +8 -13
- package/migrations/entry.js.map +1 -0
- package/package.json +2 -2
- package/src/drawValue.d.ts +4 -3
- package/terraDrawEngine.cjs.js +6 -7
- package/terraDrawEngine.esm.js +7 -8
package/index.cjs.js
CHANGED
|
@@ -28,17 +28,12 @@ const normalizeDrawValue = (value) => value.features.length === 0 ? reactMapAdap
|
|
|
28
28
|
/** Full feature equality (ids, properties and geometry). Used for controlled-input updates. */
|
|
29
29
|
const drawValuesIdentical = (a, b) => a === b || esToolkit.isEqual(a.features, b.features);
|
|
30
30
|
/**
|
|
31
|
-
* Geometry-only equality
|
|
32
|
-
*
|
|
33
|
-
*
|
|
31
|
+
* Geometry-only equality of two drawings.
|
|
32
|
+
*
|
|
33
|
+
* @deprecated Import `drawValuesEqual` from `@trackunit/react-map-adapter-shared`, where it
|
|
34
|
+
* lives next to the `DrawPort` contract since `useDraw` needs it too. Kept for this package's API.
|
|
34
35
|
*/
|
|
35
|
-
const drawValuesEqual =
|
|
36
|
-
if (a === b)
|
|
37
|
-
return true;
|
|
38
|
-
if (a.features.length !== b.features.length)
|
|
39
|
-
return false;
|
|
40
|
-
return esToolkit.isEqual(a.features.map(feature => feature.geometry), b.features.map(feature => feature.geometry));
|
|
41
|
-
};
|
|
36
|
+
const drawValuesEqual = reactMapAdapterShared.drawValuesEqual;
|
|
42
37
|
|
|
43
38
|
const sameIndices = (a, b) => a.length === b.length && a.every((index, position) => index === b[position]);
|
|
44
39
|
/**
|
|
@@ -117,7 +112,7 @@ class DrawController {
|
|
|
117
112
|
// without touching geometry. Engine echoes are filtered geometry-only below.
|
|
118
113
|
if (drawValuesIdentical(this.value, normalized))
|
|
119
114
|
return;
|
|
120
|
-
const sameGeometry = drawValuesEqual(this.value, normalized);
|
|
115
|
+
const sameGeometry = reactMapAdapterShared.drawValuesEqual(this.value, normalized);
|
|
121
116
|
this.batch(() => {
|
|
122
117
|
this.value = normalized;
|
|
123
118
|
this.notify();
|
|
@@ -204,7 +199,7 @@ class DrawController {
|
|
|
204
199
|
adoptEngineValue(engine, rendered) {
|
|
205
200
|
const kept = this.rejectedFeatures();
|
|
206
201
|
const next = kept.length === 0 ? rendered : { type: "FeatureCollection", features: [...kept, ...rendered.features] };
|
|
207
|
-
if (drawValuesEqual(this.value, next))
|
|
202
|
+
if (reactMapAdapterShared.drawValuesEqual(this.value, next))
|
|
208
203
|
return;
|
|
209
204
|
this.batch(() => {
|
|
210
205
|
this.value = next;
|
package/index.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EMPTY_DRAW_VALUE, NO_DRAW_ERRORS } from '@trackunit/react-map-adapter-shared';
|
|
1
|
+
import { drawValuesEqual as drawValuesEqual$1, EMPTY_DRAW_VALUE, NO_DRAW_ERRORS } from '@trackunit/react-map-adapter-shared';
|
|
2
2
|
import { geoJsonPolygonSchema } from '@trackunit/geo-json-utils';
|
|
3
3
|
import { isEqual } from 'es-toolkit';
|
|
4
4
|
|
|
@@ -26,17 +26,12 @@ const normalizeDrawValue = (value) => value.features.length === 0 ? EMPTY_DRAW_V
|
|
|
26
26
|
/** Full feature equality (ids, properties and geometry). Used for controlled-input updates. */
|
|
27
27
|
const drawValuesIdentical = (a, b) => a === b || isEqual(a.features, b.features);
|
|
28
28
|
/**
|
|
29
|
-
* Geometry-only equality
|
|
30
|
-
*
|
|
31
|
-
*
|
|
29
|
+
* Geometry-only equality of two drawings.
|
|
30
|
+
*
|
|
31
|
+
* @deprecated Import `drawValuesEqual` from `@trackunit/react-map-adapter-shared`, where it
|
|
32
|
+
* lives next to the `DrawPort` contract since `useDraw` needs it too. Kept for this package's API.
|
|
32
33
|
*/
|
|
33
|
-
const drawValuesEqual =
|
|
34
|
-
if (a === b)
|
|
35
|
-
return true;
|
|
36
|
-
if (a.features.length !== b.features.length)
|
|
37
|
-
return false;
|
|
38
|
-
return isEqual(a.features.map(feature => feature.geometry), b.features.map(feature => feature.geometry));
|
|
39
|
-
};
|
|
34
|
+
const drawValuesEqual = drawValuesEqual$1;
|
|
40
35
|
|
|
41
36
|
const sameIndices = (a, b) => a.length === b.length && a.every((index, position) => index === b[position]);
|
|
42
37
|
/**
|
|
@@ -115,7 +110,7 @@ class DrawController {
|
|
|
115
110
|
// without touching geometry. Engine echoes are filtered geometry-only below.
|
|
116
111
|
if (drawValuesIdentical(this.value, normalized))
|
|
117
112
|
return;
|
|
118
|
-
const sameGeometry = drawValuesEqual(this.value, normalized);
|
|
113
|
+
const sameGeometry = drawValuesEqual$1(this.value, normalized);
|
|
119
114
|
this.batch(() => {
|
|
120
115
|
this.value = normalized;
|
|
121
116
|
this.notify();
|
|
@@ -202,7 +197,7 @@ class DrawController {
|
|
|
202
197
|
adoptEngineValue(engine, rendered) {
|
|
203
198
|
const kept = this.rejectedFeatures();
|
|
204
199
|
const next = kept.length === 0 ? rendered : { type: "FeatureCollection", features: [...kept, ...rendered.features] };
|
|
205
|
-
if (drawValuesEqual(this.value, next))
|
|
200
|
+
if (drawValuesEqual$1(this.value, next))
|
|
206
201
|
return;
|
|
207
202
|
this.batch(() => {
|
|
208
203
|
this.value = next;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entry.js","sourceRoot":"","sources":["../../../../../libs/react/map-draw/migrations/entry.ts"],"names":[],"mappings":"","sourcesContent":["export {};\n"]}
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/react-map-draw",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.47",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"engines": {
|
|
7
7
|
"node": ">=24.x"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@trackunit/react-map-adapter-shared": "0.0.
|
|
10
|
+
"@trackunit/react-map-adapter-shared": "0.0.209",
|
|
11
11
|
"@trackunit/geo-json-utils": "1.21.41",
|
|
12
12
|
"es-toolkit": "^1.52.0",
|
|
13
13
|
"terra-draw": "^1.36.0"
|
package/src/drawValue.d.ts
CHANGED
|
@@ -17,8 +17,9 @@ export declare const normalizeDrawValue: (value: DrawValue) => DrawValue;
|
|
|
17
17
|
/** Full feature equality (ids, properties and geometry). Used for controlled-input updates. */
|
|
18
18
|
export declare const drawValuesIdentical: (a: DrawValue, b: DrawValue) => boolean;
|
|
19
19
|
/**
|
|
20
|
-
* Geometry-only equality
|
|
21
|
-
*
|
|
22
|
-
*
|
|
20
|
+
* Geometry-only equality of two drawings.
|
|
21
|
+
*
|
|
22
|
+
* @deprecated Import `drawValuesEqual` from `@trackunit/react-map-adapter-shared`, where it
|
|
23
|
+
* lives next to the `DrawPort` contract since `useDraw` needs it too. Kept for this package's API.
|
|
23
24
|
*/
|
|
24
25
|
export declare const drawValuesEqual: (a: DrawValue, b: DrawValue) => boolean;
|
package/terraDrawEngine.cjs.js
CHANGED
|
@@ -28,20 +28,19 @@ const roundCoordinate = (value) => {
|
|
|
28
28
|
};
|
|
29
29
|
/**
|
|
30
30
|
* Converts one committed polygon into a Terra Draw store feature, or null when the
|
|
31
|
-
* feature is not a single-ring polygon (holes,
|
|
32
|
-
*
|
|
33
|
-
*
|
|
31
|
+
* feature is not a single-ring polygon (holes, open rings). Ids are dropped so the
|
|
32
|
+
* store assigns its own (Terra Draw validates ids against its id strategy), and
|
|
33
|
+
* coordinates are rounded to the store precision so validation does not reject
|
|
34
34
|
* high-precision input.
|
|
35
35
|
*/
|
|
36
36
|
const toStoreFeature = (feature) => {
|
|
37
|
-
|
|
38
|
-
if (geometry === null || geometry.type !== "Polygon" || !index.isDrawablePolygonFeature(feature))
|
|
37
|
+
if (!index.isDrawablePolygonFeature(feature))
|
|
39
38
|
return null;
|
|
40
39
|
return {
|
|
41
40
|
type: "Feature",
|
|
42
41
|
geometry: {
|
|
43
42
|
type: "Polygon",
|
|
44
|
-
coordinates: geometry.coordinates.map(ring => ring.map(([lng, lat]) => [roundCoordinate(lng), roundCoordinate(lat)])),
|
|
43
|
+
coordinates: feature.geometry.coordinates.map(ring => ring.map(([lng, lat]) => [roundCoordinate(lng), roundCoordinate(lat)])),
|
|
45
44
|
},
|
|
46
45
|
properties: { mode: POLYGON_MODE },
|
|
47
46
|
};
|
|
@@ -208,7 +207,7 @@ const createTerraDrawEngine = ({ adapter, style }) => {
|
|
|
208
207
|
};
|
|
209
208
|
const emitIfChanged = () => {
|
|
210
209
|
const next = toDrawValue(draw.getSnapshot());
|
|
211
|
-
if (
|
|
210
|
+
if (reactMapAdapterShared.drawValuesEqual(lastEmitted, next))
|
|
212
211
|
return;
|
|
213
212
|
lastEmitted = next;
|
|
214
213
|
listeners.forEach(listener => listener(next));
|
package/terraDrawEngine.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { EMPTY_DRAW_VALUE } from '@trackunit/react-map-adapter-shared';
|
|
1
|
+
import { EMPTY_DRAW_VALUE, drawValuesEqual } from '@trackunit/react-map-adapter-shared';
|
|
2
2
|
import { TerraDrawPolygonMode, ValidateNotSelfIntersecting, TerraDrawSelectMode, TerraDraw } from 'terra-draw';
|
|
3
|
-
import { DEFAULT_DRAW_STYLE, isDrawablePolygonFeature, DRAW_COORDINATE_PRECISION
|
|
3
|
+
import { DEFAULT_DRAW_STYLE, isDrawablePolygonFeature, DRAW_COORDINATE_PRECISION } from './index.esm.js';
|
|
4
4
|
import '@trackunit/geo-json-utils';
|
|
5
5
|
import 'es-toolkit';
|
|
6
6
|
|
|
@@ -26,20 +26,19 @@ const roundCoordinate = (value) => {
|
|
|
26
26
|
};
|
|
27
27
|
/**
|
|
28
28
|
* Converts one committed polygon into a Terra Draw store feature, or null when the
|
|
29
|
-
* feature is not a single-ring polygon (holes,
|
|
30
|
-
*
|
|
31
|
-
*
|
|
29
|
+
* feature is not a single-ring polygon (holes, open rings). Ids are dropped so the
|
|
30
|
+
* store assigns its own (Terra Draw validates ids against its id strategy), and
|
|
31
|
+
* coordinates are rounded to the store precision so validation does not reject
|
|
32
32
|
* high-precision input.
|
|
33
33
|
*/
|
|
34
34
|
const toStoreFeature = (feature) => {
|
|
35
|
-
|
|
36
|
-
if (geometry === null || geometry.type !== "Polygon" || !isDrawablePolygonFeature(feature))
|
|
35
|
+
if (!isDrawablePolygonFeature(feature))
|
|
37
36
|
return null;
|
|
38
37
|
return {
|
|
39
38
|
type: "Feature",
|
|
40
39
|
geometry: {
|
|
41
40
|
type: "Polygon",
|
|
42
|
-
coordinates: geometry.coordinates.map(ring => ring.map(([lng, lat]) => [roundCoordinate(lng), roundCoordinate(lat)])),
|
|
41
|
+
coordinates: feature.geometry.coordinates.map(ring => ring.map(([lng, lat]) => [roundCoordinate(lng), roundCoordinate(lat)])),
|
|
43
42
|
},
|
|
44
43
|
properties: { mode: POLYGON_MODE },
|
|
45
44
|
};
|