|
@@ -2,6 +2,7 @@ import L from 'leaflet'; |
|
@@ -2,6 +2,7 @@ import L from 'leaflet'; |
2
|
import { createTooltip } from './maps-utils';
|
2
|
import { createTooltip } from './maps-utils';
|
3
|
import { MarkerSettings } from './map-models';
|
3
|
import { MarkerSettings } from './map-models';
|
4
|
import { Observable } from 'rxjs';
|
4
|
import { Observable } from 'rxjs';
|
|
|
5
|
+import { aspectCache } from '@app/core/utils';
|
5
|
|
6
|
|
6
|
export class Marker {
|
7
|
export class Marker {
|
7
|
|
8
|
|
|
@@ -11,21 +12,22 @@ export class Marker { |
|
@@ -11,21 +12,22 @@ export class Marker { |
11
|
tooltipOffset;
|
12
|
tooltipOffset;
|
12
|
tooltip;
|
13
|
tooltip;
|
13
|
|
14
|
|
14
|
- constructor(private map$: Observable<L.Map>, location: L.LatLngExpression, settings: MarkerSettings, onClickListener?, markerArgs?, onDragendListener?) {
|
15
|
+ constructor(private map: L.Map, location: L.LatLngExpression, settings: MarkerSettings, onClickListener?, markerArgs?, onDragendListener?) {
|
15
|
//this.map = map;
|
16
|
//this.map = map;
|
16
|
this.leafletMarker = L.marker(location, {
|
17
|
this.leafletMarker = L.marker(location, {
|
17
|
draggable: settings.draggable
|
18
|
draggable: settings.draggable
|
18
|
});
|
19
|
});
|
19
|
|
20
|
|
20
|
- this.createMarkerIcon(this.leafletMarker, settings, (iconInfo) => {
|
21
|
+ this.createMarkerIcon(settings, (iconInfo) => {
|
21
|
this.leafletMarker.setIcon(iconInfo.icon);
|
22
|
this.leafletMarker.setIcon(iconInfo.icon);
|
22
|
if (settings.showLabel) {
|
23
|
if (settings.showLabel) {
|
23
|
this.tooltipOffset = [0, -iconInfo.size[1] + 10];
|
24
|
this.tooltipOffset = [0, -iconInfo.size[1] + 10];
|
24
|
this.updateMarkerLabel(settings)
|
25
|
this.updateMarkerLabel(settings)
|
25
|
}
|
26
|
}
|
26
|
- map$.subscribe(map =>
|
|
|
27
|
- this.leafletMarker.addTo(map))
|
|
|
28
|
- });
|
27
|
+
|
|
|
28
|
+ this.leafletMarker.addTo(map)
|
|
|
29
|
+ }
|
|
|
30
|
+ );
|
29
|
|
31
|
|
30
|
if (settings.displayTooltip) {
|
32
|
if (settings.displayTooltip) {
|
31
|
this.tooltip = createTooltip(this.leafletMarker, settings, markerArgs);
|
33
|
this.tooltip = createTooltip(this.leafletMarker, settings, markerArgs);
|
|
@@ -48,14 +50,14 @@ export class Marker { |
|
@@ -48,14 +50,14 @@ export class Marker { |
48
|
{ className: 'tb-marker-label', permanent: true, direction: 'top', offset: this.tooltipOffset });
|
50
|
{ className: 'tb-marker-label', permanent: true, direction: 'top', offset: this.tooltipOffset });
|
49
|
}
|
51
|
}
|
50
|
|
52
|
|
51
|
- updateMarkerColor(marker, color) {
|
53
|
+ updateMarkerColor(color) {
|
52
|
this.createDefaultMarkerIcon(color, (iconInfo) => {
|
54
|
this.createDefaultMarkerIcon(color, (iconInfo) => {
|
53
|
this.leafletMarker.setIcon(iconInfo.icon);
|
55
|
this.leafletMarker.setIcon(iconInfo.icon);
|
54
|
});
|
56
|
});
|
55
|
}
|
57
|
}
|
56
|
|
58
|
|
57
|
- updateMarkerIcon(marker, settings) {
|
|
|
58
|
- this.createMarkerIcon(marker, settings, (iconInfo) => {
|
59
|
+ updateMarkerIcon( settings) {
|
|
|
60
|
+ this.createMarkerIcon(settings, (iconInfo) => {
|
59
|
this.leafletMarker.setIcon(iconInfo.icon);
|
61
|
this.leafletMarker.setIcon(iconInfo.icon);
|
60
|
if (settings.showLabel) {
|
62
|
if (settings.showLabel) {
|
61
|
this.tooltipOffset = [0, -iconInfo.size[1] + 10];
|
63
|
this.tooltipOffset = [0, -iconInfo.size[1] + 10];
|
|
@@ -66,41 +68,41 @@ export class Marker { |
|
@@ -66,41 +68,41 @@ export class Marker { |
66
|
|
68
|
|
67
|
|
69
|
|
68
|
|
70
|
|
69
|
- createMarkerIcon(marker, settings, onMarkerIconReady) {
|
71
|
+ createMarkerIcon(settings, onMarkerIconReady) {
|
70
|
var currentImage = settings.currentImage;
|
72
|
var currentImage = settings.currentImage;
|
71
|
// var opMap = this;
|
73
|
// var opMap = this;
|
72
|
- /* if (currentImage && currentImage.url) {
|
|
|
73
|
- this.utils.loadImageAspect(currentImage.url).then(
|
|
|
74
|
- (aspect) => {
|
|
|
75
|
- if (aspect) {
|
|
|
76
|
- var width;
|
|
|
77
|
- var height;
|
|
|
78
|
- if (aspect > 1) {
|
|
|
79
|
- width = currentImage.size;
|
|
|
80
|
- height = currentImage.size / aspect;
|
|
|
81
|
- } else {
|
|
|
82
|
- width = currentImage.size * aspect;
|
|
|
83
|
- height = currentImage.size;
|
|
|
84
|
- }
|
|
|
85
|
- var icon = L.icon({
|
|
|
86
|
- iconUrl: currentImage.url,
|
|
|
87
|
- iconSize: [width, height],
|
|
|
88
|
- iconAnchor: [width / 2, height],
|
|
|
89
|
- popupAnchor: [0, -height]
|
|
|
90
|
- });
|
|
|
91
|
- var iconInfo = {
|
|
|
92
|
- size: [width, height],
|
|
|
93
|
- icon: icon
|
|
|
94
|
- };
|
|
|
95
|
- onMarkerIconReady(iconInfo);
|
|
|
96
|
- } else {
|
|
|
97
|
- opMap.createDefaultMarkerIcon(settings.color, onMarkerIconReady);
|
|
|
98
|
- }
|
|
|
99
|
- }
|
|
|
100
|
- );
|
|
|
101
|
- } else {
|
|
|
102
|
- this.createDefaultMarkerIcon(settings.color, onMarkerIconReady);
|
|
|
103
|
- }*/
|
74
|
+ if (currentImage && currentImage.url) {
|
|
|
75
|
+ aspectCache(currentImage.url).subscribe(
|
|
|
76
|
+ (aspect) => {
|
|
|
77
|
+ if (aspect) {
|
|
|
78
|
+ var width;
|
|
|
79
|
+ var height;
|
|
|
80
|
+ if (aspect > 1) {
|
|
|
81
|
+ width = currentImage.size;
|
|
|
82
|
+ height = currentImage.size / aspect;
|
|
|
83
|
+ } else {
|
|
|
84
|
+ width = currentImage.size * aspect;
|
|
|
85
|
+ height = currentImage.size;
|
|
|
86
|
+ }
|
|
|
87
|
+ var icon = L.icon({
|
|
|
88
|
+ iconUrl: currentImage.url,
|
|
|
89
|
+ iconSize: [width, height],
|
|
|
90
|
+ iconAnchor: [width / 2, height],
|
|
|
91
|
+ popupAnchor: [0, -height]
|
|
|
92
|
+ });
|
|
|
93
|
+ var iconInfo = {
|
|
|
94
|
+ size: [width, height],
|
|
|
95
|
+ icon: icon
|
|
|
96
|
+ };
|
|
|
97
|
+ onMarkerIconReady(iconInfo);
|
|
|
98
|
+ } else {
|
|
|
99
|
+ this.createDefaultMarkerIcon(settings.color, onMarkerIconReady);
|
|
|
100
|
+ }
|
|
|
101
|
+ }
|
|
|
102
|
+ );
|
|
|
103
|
+ } else {
|
|
|
104
|
+ this.createDefaultMarkerIcon(settings.color, onMarkerIconReady);
|
|
|
105
|
+ }
|
104
|
}
|
106
|
}
|
105
|
|
107
|
|
106
|
createDefaultMarkerIcon(color, onMarkerIconReady) {
|
108
|
createDefaultMarkerIcon(color, onMarkerIconReady) {
|
|
@@ -124,8 +126,8 @@ export class Marker { |
|
@@ -124,8 +126,8 @@ export class Marker { |
124
|
|
126
|
|
125
|
|
127
|
|
126
|
removeMarker() {
|
128
|
removeMarker() {
|
127
|
- this.map$.subscribe(map =>
|
|
|
128
|
- this.leafletMarker.addTo(map))
|
129
|
+ /* this.map$.subscribe(map =>
|
|
|
130
|
+ this.leafletMarker.addTo(map))*/
|
129
|
}
|
131
|
}
|
130
|
|
132
|
|
131
|
extendBoundsWithMarker(bounds) {
|
133
|
extendBoundsWithMarker(bounds) {
|