@vidro/map-handler 1.2.176 → 1.2.177

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. package/README.md +79 -2
  2. package/package.json +1 -1
  3. package/src/index.js +31 -0
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Map Handler
2
2
 
3
- #### Version 1.2.175 - January 2025
3
+ #### Version 1.2.176 - January 2025
4
4
 
5
5
  Tool to achieve the easiest way of communication with the map iframe.
6
6
 
@@ -99,9 +99,38 @@ setDebug(0);
99
99
 
100
100
  ### Available events
101
101
 
102
+ ### Available Events
103
+
102
104
  ##### onZoomChange
103
105
 
104
- Notifies zoom level changed
106
+ The `onZoomChange` event is triggered whenever the zoom level of the map changes. This event provides detailed metadata about the new zoom state, including the current zoom level, map extent, resolution, and scale.
107
+
108
+
109
+
110
+ The event returns an object with the following properties:
111
+
112
+ | Property | Type | Description |
113
+ |-------------|--------|-------------|
114
+ | `type` | string | The event type, always `"onZoomChange"`. |
115
+ | `zoom` | number | The current zoom level after the change. |
116
+ | `maxZoom` | number | The maximum zoom level allowed in the map. |
117
+ | `minZoom` | number | The minimum zoom level allowed in the map. |
118
+ | `extent` | array | The map extent after zooming, represented as `[minX, minY, maxX, maxY]`. |
119
+ | `resolution` | number | The resolution of the map at the current zoom level. |
120
+ | `scale` | string | The approximate scale of the map in the format `"1:xxxx"`. |
121
+
122
+
123
+ ```
124
+ {
125
+ "type": "onZoomChange",
126
+ "zoom": 15.035190437015496,
127
+ "maxZoom": 25,
128
+ "minZoom": 0,
129
+ "extent": [448455.99940588913, 4595273.644846473, 456909.8853950997, 4602082.14362973],
130
+ "resolution": 4.656975911940399,
131
+ "scale": "1:17600"
132
+ }
133
+ ```
105
134
 
106
135
  ##### geomAdded
107
136
 
@@ -288,6 +317,18 @@ If is no hover any feature event is dispatched with `feature:null`
288
317
  {type: "hover", feature: {'property':'somevalue',...}
289
318
  ```
290
319
 
320
+ ##### screenshot <a id="screenshot-event"></a>
321
+
322
+ This feature provides screenshot data, encoded as a PNG in Base64 format.
323
+
324
+
325
+ > E.G
326
+
327
+ ```
328
+
329
+ {type: "screenshot", content: 'png in base64'
330
+ ```
331
+
291
332
  ## Methods
292
333
 
293
334
  ##### ZoomIn()
@@ -346,6 +387,35 @@ center map to given coordinates
346
387
  CenterMap(419006.12985785044, 4576698.8136144625,18);
347
388
 
348
389
  ```
390
+ ##### zoomToScale(scale)
391
+
392
+ Sets the zoom level to a specified scale.
393
+
394
+
395
+
396
+ > **Allowed Scales:**
397
+
398
+ - `1:100`
399
+ - `1:200`
400
+ - `1:400`
401
+ - `1:500`
402
+ - `1:1000`
403
+ - `1:2000`
404
+ - `1:5000`
405
+ - `1:10000`
406
+ - `1:50000`
407
+
408
+ > Params
409
+
410
+ - **`scale`** `<string>` - The scale to set the zoom level.
411
+
412
+
413
+ E.G:
414
+
415
+ ```javascript
416
+ zoomToScale('1:100');
417
+ ```
418
+
349
419
 
350
420
  ##### AddGeom(string)
351
421
 
@@ -1045,6 +1115,13 @@ Stop measure tools
1045
1115
  cancelMeasure();
1046
1116
  ```
1047
1117
 
1118
+ ##### screenshot
1119
+
1120
+ Will do an screenshot of the current map encoded as a PNG in Base64 format. Result will be encapsulated [`screenshot`](#screenshot-event)
1121
+
1122
+ ```
1123
+ screenshot({});
1124
+ ```
1048
1125
  ### Multiple iframes
1049
1126
 
1050
1127
  Is possible to use multiple iframe on a single page, follow this steps.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vidro/map-handler",
3
- "version": "1.2.176",
3
+ "version": "1.2.177",
4
4
  "description": "Tool to achieve the easiest way of communication with the map",
5
5
  "homepage": "https://github.com/Vidro-Software-SL/maphandler",
6
6
  "repository": {
package/src/index.js CHANGED
@@ -403,12 +403,43 @@ class Communicator extends EventEmitter {
403
403
  };
404
404
 
405
405
  zoomToExtent = () => {
406
+ const allowedScales = [
407
+ "1:100",
408
+ "1:200",
409
+ "1:400",
410
+ "1:500",
411
+ "1:1000",
412
+ "1:2000",
413
+ "1:5000",
414
+ "1:10000",
415
+ "1:50000",
416
+ ];
417
+
418
+ if (!allowedScales.includes(scale)) {
419
+ console.error(
420
+ `Invalid scale: ${scale}. Allowed values are: ${allowedScales.join(
421
+ ", "
422
+ )}`
423
+ );
424
+ this.emit("error", {
425
+ type: "error",
426
+ error: `Invalid scale: ${scale}`,
427
+ });
428
+ return;
429
+ }
406
430
  this.com.sendMessageToMap({
407
431
  type: "zoomToExtent",
408
432
  sessionToken: this.sessionToken,
409
433
  });
410
434
  };
411
435
 
436
+ zoomToScale = (scale) => {
437
+ this.com.sendMessageToMap({
438
+ type: "zoomToScale",
439
+ sessionToken: this.sessionToken,
440
+ scale: scale,
441
+ });
442
+ };
412
443
  zoomToCoordinates = (lat, lon, zoomLevel) => {
413
444
  if (!isNaN(parseInt(zoomLevel))) {
414
445
  this.com.sendMessageToMap({