@artstesh/maps 4.0.8 → 4.0.9

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.
Files changed (37) hide show
  1. package/dist/esm2020/map/helpers/index.mjs +2 -1
  2. package/dist/esm2020/map/helpers/stringify-feature.helper.mjs +58 -0
  3. package/dist/esm2020/map/map-plate/map-plate.component.mjs +4 -1
  4. package/dist/esm2020/map/messages/queries/generate-draw.query.mjs +14 -0
  5. package/dist/esm2020/map/models/drawing-type.enum.mjs +2 -1
  6. package/dist/esm2020/map/services/drawing/drawing-generation.service.mjs +28 -0
  7. package/dist/esm2020/map/services/drawing/drawing.service.mjs +13 -13
  8. package/dist/esm2020/map/services/message-registrator.service.mjs +8 -5
  9. package/dist/esm2020/src/map/helpers/index.mjs +2 -1
  10. package/dist/esm2020/src/map/helpers/stringify-feature.helper.mjs +58 -0
  11. package/dist/esm2020/src/map/map-plate/map-plate.component.mjs +4 -1
  12. package/dist/esm2020/src/map/messages/queries/generate-draw.query.mjs +14 -0
  13. package/dist/esm2020/src/map/models/drawing-type.enum.mjs +2 -1
  14. package/dist/esm2020/src/map/services/drawing/drawing-generation.service.mjs +28 -0
  15. package/dist/esm2020/src/map/services/drawing/drawing.service.mjs +13 -13
  16. package/dist/esm2020/src/map/services/message-registrator.service.mjs +8 -5
  17. package/dist/fesm2015/maps-components-src-map.mjs +110 -18
  18. package/dist/fesm2015/maps-components-src-map.mjs.map +1 -1
  19. package/dist/fesm2015/maps-components.mjs +110 -18
  20. package/dist/fesm2015/maps-components.mjs.map +1 -1
  21. package/dist/fesm2020/maps-components-src-map.mjs +109 -18
  22. package/dist/fesm2020/maps-components-src-map.mjs.map +1 -1
  23. package/dist/fesm2020/maps-components.mjs +109 -18
  24. package/dist/fesm2020/maps-components.mjs.map +1 -1
  25. package/dist/map/helpers/index.d.ts +1 -0
  26. package/dist/map/helpers/stringify-feature.helper.d.ts +8 -0
  27. package/dist/map/messages/queries/generate-draw.query.d.ts +14 -0
  28. package/dist/map/models/drawing-type.enum.d.ts +2 -1
  29. package/dist/map/services/drawing/drawing-generation.service.d.ts +10 -0
  30. package/dist/map/services/message-registrator.service.d.ts +2 -1
  31. package/dist/src/map/helpers/index.d.ts +1 -0
  32. package/dist/src/map/helpers/stringify-feature.helper.d.ts +8 -0
  33. package/dist/src/map/messages/queries/generate-draw.query.d.ts +14 -0
  34. package/dist/src/map/models/drawing-type.enum.d.ts +2 -1
  35. package/dist/src/map/services/drawing/drawing-generation.service.d.ts +10 -0
  36. package/dist/src/map/services/message-registrator.service.d.ts +2 -1
  37. package/package.json +1 -1
@@ -3,19 +3,20 @@ import { Component, Injectable, ChangeDetectionStrategy, Input, ViewChild, NgMod
3
3
  import * as i4 from '@angular/common';
4
4
  import { CommonModule } from '@angular/common';
5
5
  import { Feature } from 'ol';
6
- import { Point } from 'ol/geom';
6
+ import { Point, LineString } from 'ol/geom';
7
7
  import { GeoJSON, WKT } from 'ol/format';
8
8
  import { getCenter, createEmpty, extend } from 'ol/extent';
9
- import { get, useGeographic } from 'ol/proj';
9
+ import { get, useGeographic, transform } from 'ol/proj';
10
10
  import { PostboyGenericMessage, PostboyCallbackMessage, PostboyService, PostboyAbstractRegistrator } from '@artstesh/postboy';
11
11
  import { first, filter, auditTime } from 'rxjs/operators';
12
12
  import { Vector, XYZ } from 'ol/source';
13
13
  import { Draw } from 'ol/interaction';
14
+ import { createRegularPolygon } from 'ol/interaction/Draw';
14
15
  import TileLayer from 'ol/layer/Tile';
15
16
  import OSM from 'ol/source/OSM';
16
17
  import { Vector as Vector$1 } from 'ol/layer';
17
18
  import { bbox } from 'ol/loadingstrategy';
18
- import { fromExtent } from 'ol/geom/Polygon';
19
+ import Polygon, { fromExtent } from 'ol/geom/Polygon';
19
20
  import Cluster from 'ol/source/Cluster';
20
21
  import { combineLatest } from 'rxjs';
21
22
  import Map from 'ol/Map';
@@ -23,6 +24,7 @@ import View from 'ol/View';
23
24
  import Overlay from 'ol/Overlay';
24
25
  import Style from 'ol/style/Style';
25
26
  import { Icon, Circle, Fill, Stroke, Text } from 'ol/style';
27
+ import { METERS_PER_UNIT } from 'ol/proj/epsg4326';
26
28
 
27
29
  class DestructibleComponent {
28
30
  constructor() {
@@ -176,6 +178,7 @@ class PolygonModel {
176
178
  var DrawingType;
177
179
  (function (DrawingType) {
178
180
  DrawingType[DrawingType["Polygon"] = 1] = "Polygon";
181
+ DrawingType[DrawingType["Circle"] = 2] = "Circle";
179
182
  })(DrawingType || (DrawingType = {}));
180
183
 
181
184
  var FeatureOutputFormat;
@@ -340,6 +343,19 @@ class DrawingFinishedEvent extends PostboyGenericMessage {
340
343
  }
341
344
  DrawingFinishedEvent.ID = 'c724b68e-b4eb-4783-90f1-a8e31973fd36';
342
345
 
346
+ class GenerateDrawQuery extends PostboyCallbackMessage {
347
+ constructor(layer, style, type) {
348
+ super();
349
+ this.layer = layer;
350
+ this.style = style;
351
+ this.type = type;
352
+ }
353
+ get id() {
354
+ return GenerateDrawQuery.ID;
355
+ }
356
+ }
357
+ GenerateDrawQuery.ID = 'f01c99ba-0953-4ab5-82f9-04e6fbb678c1';
358
+
343
359
  class MapPostboyService extends PostboyService {
344
360
  constructor() {
345
361
  super();
@@ -534,17 +550,17 @@ class DrawingService {
534
550
  this.clearInteraction(l);
535
551
  return;
536
552
  }
537
- const cancelSub = this.observeCancelation(ev, l);
538
- this.drawInteraction = new Draw({
539
- source: l.getSource(),
540
- type: DrawingType[ev.type],
541
- style: ev.style,
542
- });
543
- this.map.addInteraction(this.drawInteraction);
544
- this.drawInteraction.on('drawend', (evt) => {
545
- cancelSub.unsubscribe();
546
- this.onEnd(evt, ev, l);
553
+ const drawQuery = new GenerateDrawQuery(l, ev.style, ev.type);
554
+ drawQuery.result.subscribe((draw) => {
555
+ const cancelSub = this.observeCancelation(ev, l);
556
+ this.drawInteraction = draw;
557
+ this.map?.addInteraction(this.drawInteraction);
558
+ this.drawInteraction.on('drawend', (evt) => {
559
+ cancelSub.unsubscribe();
560
+ this.onEnd(evt, ev, l);
561
+ });
547
562
  });
563
+ this.postboy.fire(drawQuery);
548
564
  });
549
565
  });
550
566
  this.observeMapRender();
@@ -588,10 +604,31 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImpo
588
604
  type: Injectable
589
605
  }], ctorParameters: function () { return [{ type: MapPostboyService }]; } });
590
606
 
607
+ class DrawingGenerationService {
608
+ constructor(postboy) {
609
+ this.postboy = postboy;
610
+ }
611
+ up() {
612
+ this.postboy.subscribe(GenerateDrawQuery.ID).subscribe((ev) => {
613
+ ev.finish(new Draw({
614
+ source: ev.layer.getSource(),
615
+ type: DrawingType[ev.type],
616
+ style: ev.style,
617
+ geometryFunction: ev.type !== DrawingType.Circle ? undefined : createRegularPolygon(32),
618
+ }));
619
+ });
620
+ }
621
+ }
622
+ DrawingGenerationService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: DrawingGenerationService, deps: [{ token: MapPostboyService }], target: i0.ɵɵFactoryTarget.Injectable });
623
+ DrawingGenerationService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: DrawingGenerationService });
624
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: DrawingGenerationService, decorators: [{
625
+ type: Injectable
626
+ }], ctorParameters: function () { return [{ type: MapPostboyService }]; } });
627
+
591
628
  class MessageRegistratorService extends PostboyAbstractRegistrator {
592
- constructor(service, management, state, feature, interaction, drawing) {
629
+ constructor(service, management, state, feature, interaction, drawing, drawGenerator) {
593
630
  super(service);
594
- this.registerServices([management, state, interaction, feature, drawing]);
631
+ this.registerServices([management, state, interaction, feature, drawing, drawGenerator]);
595
632
  }
596
633
  _up() {
597
634
  this.registerReplay(MapRenderedEvent.ID);
@@ -608,13 +645,14 @@ class MessageRegistratorService extends PostboyAbstractRegistrator {
608
645
  this.registerSubject(StartDrawingCommand.ID);
609
646
  this.registerSubject(GetLayerQuery.ID);
610
647
  this.registerSubject(DrawingFinishedEvent.ID);
648
+ this.registerSubject(GenerateDrawQuery.ID);
611
649
  }
612
650
  }
613
- MessageRegistratorService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: MessageRegistratorService, deps: [{ token: MapPostboyService }, { token: MapManagementService }, { token: MapStateService }, { token: MapFeatureService }, { token: MapClickService }, { token: DrawingService }], target: i0.ɵɵFactoryTarget.Injectable });
651
+ MessageRegistratorService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: MessageRegistratorService, deps: [{ token: MapPostboyService }, { token: MapManagementService }, { token: MapStateService }, { token: MapFeatureService }, { token: MapClickService }, { token: DrawingService }, { token: DrawingGenerationService }], target: i0.ɵɵFactoryTarget.Injectable });
614
652
  MessageRegistratorService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: MessageRegistratorService });
615
653
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: MessageRegistratorService, decorators: [{
616
654
  type: Injectable
617
- }], ctorParameters: function () { return [{ type: MapPostboyService }, { type: MapManagementService }, { type: MapStateService }, { type: MapFeatureService }, { type: MapClickService }, { type: DrawingService }]; } });
655
+ }], ctorParameters: function () { return [{ type: MapPostboyService }, { type: MapManagementService }, { type: MapStateService }, { type: MapFeatureService }, { type: MapClickService }, { type: DrawingService }, { type: DrawingGenerationService }]; } });
618
656
 
619
657
  class TileLayerSettings {
620
658
  constructor() {
@@ -1166,6 +1204,7 @@ MapPlateComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", vers
1166
1204
  MapClickService,
1167
1205
  MapFeatureService,
1168
1206
  DrawingService,
1207
+ DrawingGenerationService,
1169
1208
  ], usesInheritance: true, ngImport: i0, template: "<ng-content></ng-content>\r\n<lib-osm-tile-layer *ngIf=\"osmUrl && map\" [map]=\"map\" [url]=\"osmUrl\"></lib-osm-tile-layer>\r\n<lib-feature-layer *ngIf=\"map\" [settings]=\"drawingLayerSettings\"></lib-feature-layer>\r\n", styles: ["lib-map-plate{position:relative;display:flex;flex-direction:column;height:100%}\n"], dependencies: [{ kind: "directive", type: i4.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: OsmTileLayerComponent, selector: "lib-osm-tile-layer", inputs: ["url", "map"] }, { kind: "component", type: FeatureLayerComponent, selector: "lib-feature-layer", inputs: ["settings"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
1170
1209
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: MapPlateComponent, decorators: [{
1171
1210
  type: Component,
@@ -1176,6 +1215,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImpo
1176
1215
  MapClickService,
1177
1216
  MapFeatureService,
1178
1217
  DrawingService,
1218
+ DrawingGenerationService,
1179
1219
  ], template: "<ng-content></ng-content>\r\n<lib-osm-tile-layer *ngIf=\"osmUrl && map\" [map]=\"map\" [url]=\"osmUrl\"></lib-osm-tile-layer>\r\n<lib-feature-layer *ngIf=\"map\" [settings]=\"drawingLayerSettings\"></lib-feature-layer>\r\n", styles: ["lib-map-plate{position:relative;display:flex;flex-direction:column;height:100%}\n"] }]
1180
1220
  }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: MapPostboyService }, { type: MapPlateFactory }, { type: MessageRegistratorService }, { type: i0.ChangeDetectorRef }]; }, propDecorators: { settings: [{
1181
1221
  type: Input
@@ -1445,6 +1485,57 @@ class TextStyleHelper {
1445
1485
  }
1446
1486
  }
1447
1487
 
1488
+ class StringifyFeatureHelper {
1489
+ static polygon(feature, format = FeatureOutputFormat.GeoJson) {
1490
+ return format === FeatureOutputFormat.GeoJson
1491
+ ? new GeoJSON().writeFeature(feature)
1492
+ : new WKT().writeFeature(feature);
1493
+ }
1494
+ static circle(feature, format = FeatureOutputFormat.GeoJson) {
1495
+ // const clone = feature.clone();
1496
+ // clone.setGeometry(fromCircle(feature.getGeometry()! as Circle));
1497
+ const tetemp = feature.getGeometryName();
1498
+ const circle = feature.getGeometry();
1499
+ // const temp = StringifyFeatureHelper.drawCircle(circle.getCenter(), circle.getRadius());
1500
+ const ttt = feature.getGeometry().getExtent();
1501
+ const eastPoint = [ttt[2], (ttt[1] + ttt[3]) / 2];
1502
+ const aaa = [
1503
+ ...transform([ttt[0], ttt[1]], 'EPSG:4326', 'EPSG:3857'),
1504
+ ...transform([ttt[2], ttt[3]], 'EPSG:4326', 'EPSG:3857'),
1505
+ ];
1506
+ const radius = (aaa[2] - aaa[0]) / 2;
1507
+ const radius2 = new LineString([circle.getCenter(), eastPoint]).getLength();
1508
+ const polygonGeom = new Polygon(StringifyFeatureHelper.drawCircle(circle.getCenter(), radius));
1509
+ // var edgeCoordinate = [circle.getCenter()[0] + radius, circle.getCenter()[1]];
1510
+ // var wgs84Sphere = new Sphere(6378137);
1511
+ return StringifyFeatureHelper.polygon(new Feature(polygonGeom), format);
1512
+ // const rad = circle.getRadius();
1513
+ // const degrees = 180 / Math.PI; // radians to degrees
1514
+ // const radians = Math.PI / 180; // degrees to radians
1515
+ // const rlat = rad * degrees * 1000;
1516
+ // const rlng = rad * radians;
1517
+ // return StringifyFeatureHelper.polygon(new Feature<Geometry>(circular(circle.getCenter(),circle.getRadius() * METERS_PER_UNIT)), format);
1518
+ }
1519
+ static drawCircle(point, radius) {
1520
+ const tetetemp = transform(point, 'EPSG:4326', 'EPSG:3857');
1521
+ // const tetetemp = point;
1522
+ const radians = Math.PI / 180; // degrees to radians
1523
+ const degrees = 180 / Math.PI; // radians to degrees
1524
+ const earthsradius = 6378137.0;
1525
+ const rlat = (radius / earthsradius) * degrees;
1526
+ const rlng = rlat / Math.cos(tetetemp[1] * radians);
1527
+ const extp = [];
1528
+ for (let i = 0; i <= 32; i++) {
1529
+ const theta = Math.PI * (i / 16);
1530
+ extp.push([
1531
+ tetetemp[0] + rlng * Math.cos(theta) * METERS_PER_UNIT,
1532
+ tetetemp[1] + rlat * Math.sin(theta) * METERS_PER_UNIT,
1533
+ ]);
1534
+ }
1535
+ return [extp.map((e) => transform(e, 'EPSG:3857', 'EPSG:4326'))];
1536
+ }
1537
+ }
1538
+
1448
1539
  /*
1449
1540
  * Public API Surface of maps
1450
1541
  */
@@ -1453,5 +1544,5 @@ class TextStyleHelper {
1453
1544
  * Generated bundle index. Do not edit.
1454
1545
  */
1455
1546
 
1456
- export { CancelDrawingCommand, CloseTooltipCommand, ClusterLayerComponent, ClusterLayerSettings, DrawingType, FeatureLayerComponent, FeatureLayerSettings, FeatureOutputFormat, MapClickEvent, MapLyrs, MapLyrsLabel, MapModule, MapMoveEndEvent, MapPlateComponent, MapPostboyService, MapRenderedEvent, MapSettings, MarkerModel, MarkerStyleHelper, MarkersComponent, MessageRegistratorService, OsmTileLayerComponent, PolygonModel, PolygonStyleHelper, PolygonsComponent, StartDrawingCommand, TextStyleHelper, TileLayerComponent, TileLayerSettings, TooltipComponent, TooltipSettings };
1547
+ export { CancelDrawingCommand, CloseTooltipCommand, ClusterLayerComponent, ClusterLayerSettings, DrawingType, FeatureLayerComponent, FeatureLayerSettings, FeatureOutputFormat, MapClickEvent, MapLyrs, MapLyrsLabel, MapModule, MapMoveEndEvent, MapPlateComponent, MapPostboyService, MapRenderedEvent, MapSettings, MarkerModel, MarkerStyleHelper, MarkersComponent, MessageRegistratorService, OsmTileLayerComponent, PolygonModel, PolygonStyleHelper, PolygonsComponent, StartDrawingCommand, StringifyFeatureHelper, TextStyleHelper, TileLayerComponent, TileLayerSettings, TooltipComponent, TooltipSettings };
1457
1548
  //# sourceMappingURL=maps-components-src-map.mjs.map