@artstesh/maps 1.0.8 → 1.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/bundles/maps-components-src-map.umd.js +120 -18
  2. package/dist/bundles/maps-components-src-map.umd.js.map +1 -1
  3. package/dist/bundles/maps-components.umd.js +120 -18
  4. package/dist/bundles/maps-components.umd.js.map +1 -1
  5. package/dist/esm2015/map/helpers/index.js +2 -1
  6. package/dist/esm2015/map/helpers/stringify-feature.helper.js +58 -0
  7. package/dist/esm2015/map/map-plate/map-plate.component.js +4 -1
  8. package/dist/esm2015/map/messages/queries/generate-draw.query.js +14 -0
  9. package/dist/esm2015/map/models/drawing-type.enum.js +2 -1
  10. package/dist/esm2015/map/services/drawing/drawing-generation.service.js +28 -0
  11. package/dist/esm2015/map/services/drawing/drawing.service.js +14 -13
  12. package/dist/esm2015/map/services/message-registrator.service.js +8 -5
  13. package/dist/esm2015/src/map/helpers/index.js +2 -1
  14. package/dist/esm2015/src/map/helpers/stringify-feature.helper.js +58 -0
  15. package/dist/esm2015/src/map/map-plate/map-plate.component.js +4 -1
  16. package/dist/esm2015/src/map/messages/queries/generate-draw.query.js +14 -0
  17. package/dist/esm2015/src/map/models/drawing-type.enum.js +2 -1
  18. package/dist/esm2015/src/map/services/drawing/drawing-generation.service.js +28 -0
  19. package/dist/esm2015/src/map/services/drawing/drawing.service.js +14 -13
  20. package/dist/esm2015/src/map/services/message-registrator.service.js +8 -5
  21. package/dist/fesm2015/maps-components-src-map.js +110 -18
  22. package/dist/fesm2015/maps-components-src-map.js.map +1 -1
  23. package/dist/fesm2015/maps-components.js +110 -18
  24. package/dist/fesm2015/maps-components.js.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 i6 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() {
@@ -177,6 +179,7 @@ class PolygonModel {
177
179
  var DrawingType;
178
180
  (function (DrawingType) {
179
181
  DrawingType[DrawingType["Polygon"] = 1] = "Polygon";
182
+ DrawingType[DrawingType["Circle"] = 2] = "Circle";
180
183
  })(DrawingType || (DrawingType = {}));
181
184
 
182
185
  var FeatureOutputFormat;
@@ -341,6 +344,19 @@ class DrawingFinishedEvent extends PostboyGenericMessage {
341
344
  }
342
345
  DrawingFinishedEvent.ID = 'c724b68e-b4eb-4783-90f1-a8e31973fd36';
343
346
 
347
+ class GenerateDrawQuery extends PostboyCallbackMessage {
348
+ constructor(layer, style, type) {
349
+ super();
350
+ this.layer = layer;
351
+ this.style = style;
352
+ this.type = type;
353
+ }
354
+ get id() {
355
+ return GenerateDrawQuery.ID;
356
+ }
357
+ }
358
+ GenerateDrawQuery.ID = 'f01c99ba-0953-4ab5-82f9-04e6fbb678c1';
359
+
344
360
  class MapPostboyService extends PostboyService {
345
361
  constructor() {
346
362
  super();
@@ -540,17 +556,18 @@ class DrawingService {
540
556
  this.clearInteraction(l);
541
557
  return;
542
558
  }
543
- const cancelSub = this.observeCancelation(ev, l);
544
- this.drawInteraction = new Draw({
545
- source: l.getSource(),
546
- type: DrawingType[ev.type],
547
- style: ev.style,
548
- });
549
- this.map.addInteraction(this.drawInteraction);
550
- this.drawInteraction.on('drawend', (evt) => {
551
- cancelSub.unsubscribe();
552
- this.onEnd(evt, ev, l);
559
+ const drawQuery = new GenerateDrawQuery(l, ev.style, ev.type);
560
+ drawQuery.result.subscribe((draw) => {
561
+ var _a;
562
+ const cancelSub = this.observeCancelation(ev, l);
563
+ this.drawInteraction = draw;
564
+ (_a = this.map) === null || _a === void 0 ? void 0 : _a.addInteraction(this.drawInteraction);
565
+ this.drawInteraction.on('drawend', (evt) => {
566
+ cancelSub.unsubscribe();
567
+ this.onEnd(evt, ev, l);
568
+ });
553
569
  });
570
+ this.postboy.fire(drawQuery);
554
571
  });
555
572
  });
556
573
  this.observeMapRender();
@@ -595,10 +612,31 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImpo
595
612
  type: Injectable
596
613
  }], ctorParameters: function () { return [{ type: MapPostboyService }]; } });
597
614
 
615
+ class DrawingGenerationService {
616
+ constructor(postboy) {
617
+ this.postboy = postboy;
618
+ }
619
+ up() {
620
+ this.postboy.subscribe(GenerateDrawQuery.ID).subscribe((ev) => {
621
+ ev.finish(new Draw({
622
+ source: ev.layer.getSource(),
623
+ type: DrawingType[ev.type],
624
+ style: ev.style,
625
+ geometryFunction: ev.type !== DrawingType.Circle ? undefined : createRegularPolygon(32),
626
+ }));
627
+ });
628
+ }
629
+ }
630
+ DrawingGenerationService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: DrawingGenerationService, deps: [{ token: MapPostboyService }], target: i0.ɵɵFactoryTarget.Injectable });
631
+ DrawingGenerationService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: DrawingGenerationService });
632
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: DrawingGenerationService, decorators: [{
633
+ type: Injectable
634
+ }], ctorParameters: function () { return [{ type: MapPostboyService }]; } });
635
+
598
636
  class MessageRegistratorService extends PostboyAbstractRegistrator {
599
- constructor(service, management, state, feature, interaction, drawing) {
637
+ constructor(service, management, state, feature, interaction, drawing, drawGenerator) {
600
638
  super(service);
601
- this.registerServices([management, state, interaction, feature, drawing]);
639
+ this.registerServices([management, state, interaction, feature, drawing, drawGenerator]);
602
640
  }
603
641
  _up() {
604
642
  this.registerReplay(MapRenderedEvent.ID);
@@ -615,13 +653,14 @@ class MessageRegistratorService extends PostboyAbstractRegistrator {
615
653
  this.registerSubject(StartDrawingCommand.ID);
616
654
  this.registerSubject(GetLayerQuery.ID);
617
655
  this.registerSubject(DrawingFinishedEvent.ID);
656
+ this.registerSubject(GenerateDrawQuery.ID);
618
657
  }
619
658
  }
620
- MessageRegistratorService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: MessageRegistratorService, deps: [{ token: MapPostboyService }, { token: MapManagementService }, { token: MapStateService }, { token: MapFeatureService }, { token: MapClickService }, { token: DrawingService }], target: i0.ɵɵFactoryTarget.Injectable });
659
+ MessageRegistratorService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: MessageRegistratorService, deps: [{ token: MapPostboyService }, { token: MapManagementService }, { token: MapStateService }, { token: MapFeatureService }, { token: MapClickService }, { token: DrawingService }, { token: DrawingGenerationService }], target: i0.ɵɵFactoryTarget.Injectable });
621
660
  MessageRegistratorService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: MessageRegistratorService });
622
661
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: MessageRegistratorService, decorators: [{
623
662
  type: Injectable
624
- }], ctorParameters: function () { return [{ type: MapPostboyService }, { type: MapManagementService }, { type: MapStateService }, { type: MapFeatureService }, { type: MapClickService }, { type: DrawingService }]; } });
663
+ }], ctorParameters: function () { return [{ type: MapPostboyService }, { type: MapManagementService }, { type: MapStateService }, { type: MapFeatureService }, { type: MapClickService }, { type: DrawingService }, { type: DrawingGenerationService }]; } });
625
664
 
626
665
  class TileLayerSettings {
627
666
  constructor() {
@@ -1198,6 +1237,7 @@ MapPlateComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", vers
1198
1237
  MapClickService,
1199
1238
  MapFeatureService,
1200
1239
  DrawingService,
1240
+ DrawingGenerationService,
1201
1241
  ], 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"], components: [{ type: OsmTileLayerComponent, selector: "lib-osm-tile-layer", inputs: ["url", "map"] }, { type: FeatureLayerComponent, selector: "lib-feature-layer", inputs: ["settings"] }], directives: [{ type: i6.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
1202
1242
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: MapPlateComponent, decorators: [{
1203
1243
  type: Component,
@@ -1213,6 +1253,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImpo
1213
1253
  MapClickService,
1214
1254
  MapFeatureService,
1215
1255
  DrawingService,
1256
+ DrawingGenerationService,
1216
1257
  ],
1217
1258
  }]
1218
1259
  }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: MapPostboyService }, { type: MapPlateFactory }, { type: MessageRegistratorService }, { type: i0.ChangeDetectorRef }]; }, propDecorators: { settings: [{
@@ -1502,6 +1543,57 @@ class TextStyleHelper {
1502
1543
  }
1503
1544
  }
1504
1545
 
1546
+ class StringifyFeatureHelper {
1547
+ static polygon(feature, format = FeatureOutputFormat.GeoJson) {
1548
+ return format === FeatureOutputFormat.GeoJson
1549
+ ? new GeoJSON().writeFeature(feature)
1550
+ : new WKT().writeFeature(feature);
1551
+ }
1552
+ static circle(feature, format = FeatureOutputFormat.GeoJson) {
1553
+ // const clone = feature.clone();
1554
+ // clone.setGeometry(fromCircle(feature.getGeometry()! as Circle));
1555
+ const tetemp = feature.getGeometryName();
1556
+ const circle = feature.getGeometry();
1557
+ // const temp = StringifyFeatureHelper.drawCircle(circle.getCenter(), circle.getRadius());
1558
+ const ttt = feature.getGeometry().getExtent();
1559
+ const eastPoint = [ttt[2], (ttt[1] + ttt[3]) / 2];
1560
+ const aaa = [
1561
+ ...transform([ttt[0], ttt[1]], 'EPSG:4326', 'EPSG:3857'),
1562
+ ...transform([ttt[2], ttt[3]], 'EPSG:4326', 'EPSG:3857'),
1563
+ ];
1564
+ const radius = (aaa[2] - aaa[0]) / 2;
1565
+ const radius2 = new LineString([circle.getCenter(), eastPoint]).getLength();
1566
+ const polygonGeom = new Polygon(StringifyFeatureHelper.drawCircle(circle.getCenter(), radius));
1567
+ // var edgeCoordinate = [circle.getCenter()[0] + radius, circle.getCenter()[1]];
1568
+ // var wgs84Sphere = new Sphere(6378137);
1569
+ return StringifyFeatureHelper.polygon(new Feature(polygonGeom), format);
1570
+ // const rad = circle.getRadius();
1571
+ // const degrees = 180 / Math.PI; // radians to degrees
1572
+ // const radians = Math.PI / 180; // degrees to radians
1573
+ // const rlat = rad * degrees * 1000;
1574
+ // const rlng = rad * radians;
1575
+ // return StringifyFeatureHelper.polygon(new Feature<Geometry>(circular(circle.getCenter(),circle.getRadius() * METERS_PER_UNIT)), format);
1576
+ }
1577
+ static drawCircle(point, radius) {
1578
+ const tetetemp = transform(point, 'EPSG:4326', 'EPSG:3857');
1579
+ // const tetetemp = point;
1580
+ const radians = Math.PI / 180; // degrees to radians
1581
+ const degrees = 180 / Math.PI; // radians to degrees
1582
+ const earthsradius = 6378137.0;
1583
+ const rlat = (radius / earthsradius) * degrees;
1584
+ const rlng = rlat / Math.cos(tetetemp[1] * radians);
1585
+ const extp = [];
1586
+ for (let i = 0; i <= 32; i++) {
1587
+ const theta = Math.PI * (i / 16);
1588
+ extp.push([
1589
+ tetetemp[0] + rlng * Math.cos(theta) * METERS_PER_UNIT,
1590
+ tetetemp[1] + rlat * Math.sin(theta) * METERS_PER_UNIT,
1591
+ ]);
1592
+ }
1593
+ return [extp.map((e) => transform(e, 'EPSG:3857', 'EPSG:4326'))];
1594
+ }
1595
+ }
1596
+
1505
1597
  /*
1506
1598
  * Public API Surface of maps
1507
1599
  */
@@ -1514,5 +1606,5 @@ class TextStyleHelper {
1514
1606
  * Generated bundle index. Do not edit.
1515
1607
  */
1516
1608
 
1517
- 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 };
1609
+ 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 };
1518
1610
  //# sourceMappingURL=maps-components.js.map