terra-draw 0.0.1-alpha.67 → 0.0.1-alpha.68

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.
@@ -163,6 +163,84 @@ test.describe("polygon mode", () => {
163
163
  // One point + one line
164
164
  await expectPaths({ page, count: 1 });
165
165
  });
166
+
167
+ test("can use validation setting to prevent maximum size", async ({
168
+ page,
169
+ }) => {
170
+ const mapDiv = await setupMap({
171
+ page,
172
+ configQueryParam: "validationFailure",
173
+ });
174
+ await changeMode({ page, mode });
175
+
176
+ // The length of the square sides in pixels
177
+ const sideLength = 100;
178
+
179
+ // Calculating the half of the side length
180
+ const halfLength = sideLength / 2;
181
+
182
+ // Coordinates of the center
183
+ const centerX = mapDiv.width / 2;
184
+ const centerY = mapDiv.height / 2;
185
+
186
+ // Coordinates of the four corners of the square
187
+ const topLeft = { x: centerX - halfLength, y: centerY - halfLength };
188
+ const topRight = { x: centerX + halfLength, y: centerY - halfLength };
189
+ const bottomLeft = { x: centerX - halfLength, y: centerY + halfLength };
190
+ const bottomRight = { x: centerX + halfLength, y: centerY + halfLength };
191
+
192
+ // Perform clicks at each corner
193
+ await page.mouse.click(topLeft.x, topLeft.y);
194
+ await page.mouse.click(topRight.x, topRight.y);
195
+ await page.mouse.click(bottomRight.x, bottomRight.y);
196
+ await page.mouse.click(bottomLeft.x, bottomLeft.y);
197
+
198
+ // Attempt to close the square
199
+ await page.mouse.click(bottomLeft.x, bottomLeft.y);
200
+
201
+ // Square will fail, as triangle will be 705665 square meters, but square will be
202
+ // over the limit of 1000000 square meters.
203
+ await expectPaths({ page, count: 3 });
204
+ });
205
+
206
+ test("can use validation setting to draw underneath maximum size ", async ({
207
+ page,
208
+ }) => {
209
+ const mapDiv = await setupMap({
210
+ page,
211
+ configQueryParam: "validationSuccess",
212
+ });
213
+ await changeMode({ page, mode });
214
+
215
+ // The length of the square sides in pixels
216
+ const sideLength = 100;
217
+
218
+ // Calculating the half of the side length
219
+ const halfLength = sideLength / 2;
220
+
221
+ // Coordinates of the center
222
+ const centerX = mapDiv.width / 2;
223
+ const centerY = mapDiv.height / 2;
224
+
225
+ // Coordinates of the four corners of the square
226
+ const topLeft = { x: centerX - halfLength, y: centerY - halfLength };
227
+ const topRight = { x: centerX + halfLength, y: centerY - halfLength };
228
+ const bottomLeft = { x: centerX - halfLength, y: centerY + halfLength };
229
+ const bottomRight = { x: centerX + halfLength, y: centerY + halfLength };
230
+
231
+ // Perform clicks at each corner
232
+ await page.mouse.click(topLeft.x, topLeft.y);
233
+ await page.mouse.click(topRight.x, topRight.y);
234
+ await page.mouse.click(bottomRight.x, bottomRight.y);
235
+ await page.mouse.click(bottomLeft.x, bottomLeft.y);
236
+
237
+ // Attempt to close the square
238
+ await page.mouse.click(bottomLeft.x, bottomLeft.y);
239
+
240
+ // Square will fail, as triangle will be 705665 square meters, but square will be
241
+ // over the limit of 1000000 square meters.
242
+ await expectPaths({ page, count: 1 });
243
+ });
166
244
  });
167
245
 
168
246
  test.describe("rectangle mode", () => {
@@ -320,7 +398,93 @@ test.describe("select mode", () => {
320
398
  await expectGroupPosition({ page, x: 538, y: 308 });
321
399
  });
322
400
 
323
- test("selected rectangle can has it's shape maintained when coordinates are dragged", async ({
401
+ test("selected polygon can have individual coordinates dragged and fail when validation fails", async ({
402
+ page,
403
+ }) => {
404
+ const mapDiv = await setupMap({
405
+ page,
406
+ configQueryParam: "validationFailure",
407
+ });
408
+
409
+ await changeMode({ page, mode: "polygon" });
410
+
411
+ // Draw a rectangle
412
+ const { topLeft } = await drawRectangularPolygon({
413
+ mapDiv,
414
+ page,
415
+ size: "small",
416
+ });
417
+
418
+ // Change to select mode
419
+ await changeMode({ page, mode });
420
+
421
+ // Before drag
422
+ const x = topLeft.x - 2;
423
+ const y = topLeft.y - 2;
424
+ await expectGroupPosition({ page, x, y });
425
+
426
+ // Select
427
+ await page.mouse.click(mapDiv.width / 2, mapDiv.height / 2);
428
+ // await expectPaths({ page, count: 9 }); // 8 selection points and 1 square
429
+
430
+ // Drag
431
+ await page.mouse.move(topLeft.x, topLeft.y);
432
+ await page.mouse.down();
433
+ await page.mouse.move(0, 0, { steps: 30 });
434
+ await page.mouse.up();
435
+
436
+ // Deselect
437
+ await page.mouse.click(mapDiv.width - 10, mapDiv.height / 2);
438
+
439
+ // We are attempting to dragg right tothe top left corner but it is not getting there
440
+ // because it is capped by the validation. If this was allowed x would be ~90
441
+ await expectGroupPosition({ page, x: 563, y: 301 });
442
+ });
443
+
444
+ test("selected polygon can have individual coordinates dragged and succeeds when validation succeeds", async ({
445
+ page,
446
+ }) => {
447
+ const mapDiv = await setupMap({
448
+ page,
449
+ configQueryParam: "validationSuccess",
450
+ });
451
+
452
+ await changeMode({ page, mode: "polygon" });
453
+
454
+ // Draw a rectangle
455
+ const { topLeft } = await drawRectangularPolygon({
456
+ mapDiv,
457
+ page,
458
+ size: "small",
459
+ });
460
+
461
+ // Change to select mode
462
+ await changeMode({ page, mode });
463
+
464
+ // Before drag
465
+ const x = topLeft.x - 2;
466
+ const y = topLeft.y - 2;
467
+ await expectGroupPosition({ page, x, y });
468
+
469
+ // Select
470
+ await page.mouse.click(mapDiv.width / 2, mapDiv.height / 2);
471
+ // await expectPaths({ page, count: 9 }); // 8 selection points and 1 square
472
+
473
+ // Drag
474
+ await page.mouse.move(topLeft.x, topLeft.y);
475
+ await page.mouse.down();
476
+ await page.mouse.move(topLeft.x - 50, topLeft.y - 50, { steps: 30 });
477
+ await page.mouse.up();
478
+
479
+ // Deselect
480
+ await page.mouse.click(mapDiv.width - 10, mapDiv.height / 2);
481
+
482
+ // We are attempting to dragg right tothe top left corner but it is not getting there
483
+ // because it is capped by the validation. If this was allowed x would be ~90
484
+ await expectGroupPosition({ page, x: 553, y: 273 });
485
+ });
486
+
487
+ test("selected rectangle has it's shape maintained when coordinates are dragged with resizeable flag", async ({
324
488
  page,
325
489
  }) => {
326
490
  const mapDiv = await setupMap({ page });
@@ -4,15 +4,21 @@ export const pageUrl = "http://localhost:3000/";
4
4
 
5
5
  export const setupMap = async ({
6
6
  page,
7
+ configQueryParam,
7
8
  }: {
8
9
  page: Page;
10
+ configQueryParam?: "validationSuccess" | "validationFailure";
9
11
  }): Promise<{
10
12
  x: number;
11
13
  y: number;
12
14
  width: number;
13
15
  height: number;
14
16
  }> => {
15
- await page.goto(pageUrl);
17
+ if (configQueryParam) {
18
+ await page.goto(pageUrl + "?config=" + configQueryParam);
19
+ } else {
20
+ await page.goto(pageUrl);
21
+ }
16
22
 
17
23
  const mapDiv = await page.getByRole("application");
18
24
 
@@ -108,6 +114,7 @@ export const expectGroupPosition = async ({
108
114
  export const drawRectangularPolygon = async ({
109
115
  mapDiv,
110
116
  page,
117
+ size = "regular",
111
118
  }: {
112
119
  mapDiv: {
113
120
  x: number;
@@ -116,9 +123,10 @@ export const drawRectangularPolygon = async ({
116
123
  height: number;
117
124
  };
118
125
  page: Page;
126
+ size?: "regular" | "small";
119
127
  }) => {
120
128
  // Draw a rectangle
121
- const sideLength = 100;
129
+ const sideLength = size === "regular" ? 100 : 70;
122
130
  const halfLength = sideLength / 2;
123
131
  const centerX = mapDiv.width / 2;
124
132
  const centerY = mapDiv.height / 2;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "terra-draw",
3
- "version": "0.0.1-alpha.67",
3
+ "version": "0.0.1-alpha.68",
4
4
  "description": "Frictionless map drawing across mapping provider",
5
5
  "scripts": {
6
6
  "docs": "typedoc",
@@ -51,37 +51,37 @@
51
51
  "maplibre"
52
52
  ],
53
53
  "devDependencies": {
54
- "@arcgis/core": "^4.27.6",
55
- "@commitlint/cli": "^17.1.2",
56
- "@commitlint/config-conventional": "^17.1.0",
57
- "@googlemaps/js-api-loader": "^1.14.3",
58
- "@swc/jest": "^0.2.36",
59
- "@types/geojson": "^7946.0.8",
60
- "@types/google.maps": "^3.49.2",
61
- "@types/jest": "^29.5.12",
62
- "@types/leaflet": "^1.7.11",
63
- "@types/mapbox-gl": "^2.7.3",
64
- "@types/rbush": "^3.0.0",
65
- "@typescript-eslint/eslint-plugin": "^7.5.0",
66
- "@typescript-eslint/parser": "^7.5.0",
67
- "eslint": "^8.24.0",
68
- "eslint-config-prettier": "^9.0.0",
69
- "eslint-plugin-prettier": "^5.0.0",
70
- "husky": "^7.0.0",
71
- "jest": "^29.7.0",
72
- "jest-environment-jsdom": "^29.7.0",
73
- "leaflet": "^1.8.0",
74
- "mapbox-gl": "^2.13.0",
54
+ "@arcgis/core": "4.27.6",
55
+ "@commitlint/cli": "17.1.2",
56
+ "@commitlint/config-conventional": "17.1.0",
57
+ "@googlemaps/js-api-loader": "1.14.3",
58
+ "@swc/jest": "0.2.36",
59
+ "@types/geojson": "7946.0.8",
60
+ "@types/google.maps": "3.49.2",
61
+ "@types/jest": "29.5.12",
62
+ "@types/leaflet": "1.7.11",
63
+ "@types/mapbox-gl": "2.7.3",
64
+ "@types/rbush": "3.0.0",
65
+ "@typescript-eslint/eslint-plugin": "7.5.0",
66
+ "@typescript-eslint/parser": "7.5.0",
67
+ "eslint": "8.57.0",
68
+ "eslint-config-prettier": "9.0.0",
69
+ "eslint-plugin-prettier": "5.0.0",
70
+ "husky": "7.0.0",
71
+ "jest": "29.7.0",
72
+ "jest-environment-jsdom": "29.7.0",
73
+ "leaflet": "1.8.0",
74
+ "mapbox-gl": "2.13.0",
75
75
  "maplibre-gl": "3.2.0",
76
- "microbundle": "^0.15.0",
77
- "ol": "^7.1.0",
78
- "serve": "^14.1.2",
79
- "standard-version": "^9.5.0",
80
- "ts-jest": "^29.1.2",
81
- "ts-loader": "^9.5.1",
82
- "tsx": "^4.7.2",
83
- "typedoc": "^0.25.12",
84
- "typescript": "^5.4.4"
76
+ "microbundle": "0.15.0",
77
+ "ol": "7.1.0",
78
+ "serve": "14.1.2",
79
+ "standard-version": "9.5.0",
80
+ "ts-jest": "29.1.2",
81
+ "ts-loader": "9.5.1",
82
+ "tsx": "4.7.2",
83
+ "typedoc": "0.25.12",
84
+ "typescript": "5.4.4"
85
85
  },
86
86
  "commitlint": {
87
87
  "extends": [
package/tsconfig.json CHANGED
@@ -15,5 +15,13 @@
15
15
  "exclude": ["src/geometry/**/*.ts", "src/test/**/*.ts", "src/util/**/*.ts"],
16
16
  "out": "docs",
17
17
  "skipErrorChecking": true
18
- }
18
+ },
19
+ "exclude": [
20
+ "node_modules/",
21
+ "guides/",
22
+ "docs/",
23
+ "dist/",
24
+ "development/dist",
25
+ "development/node_modules"
26
+ ]
19
27
  }
@@ -1,2 +0,0 @@
1
- import { GeoJSONStoreFeatures } from "../../terra-draw";
2
- export declare function isValidLineStringFeature(feature: GeoJSONStoreFeatures, coordinatePrecision: number): boolean;
@@ -1,2 +0,0 @@
1
- import { GeoJSONStoreFeatures } from "../../terra-draw";
2
- export declare function isValidPoint(feature: GeoJSONStoreFeatures, coordinatePrecision: number): boolean;
@@ -1,3 +0,0 @@
1
- import { GeoJSONStoreFeatures } from "../../terra-draw";
2
- export declare function isValidPolygonFeature(feature: GeoJSONStoreFeatures, coordinatePrecision: number): boolean;
3
- export declare function isValidNonIntersectingPolygonFeature(feature: GeoJSONStoreFeatures, coordinatePrecision: number): boolean;