leaflet-map.ts
3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import * as L from 'leaflet';
import 'leaflet-providers';
import 'leaflet.markercluster/dist/MarkerCluster.css'
import 'leaflet.markercluster/dist/MarkerCluster.Default.css'
import 'leaflet.markercluster/dist/leaflet.markercluster'
import { MapOptions } from './map-models';
export default class LeafletMap {
markers = [];
tooltips = [];
map: L.Map;
options: MapOptions;
isMarketCluster;
constructor($container: HTMLElement, options: MapOptions) {
this.options = options;
}
public initSettings(options: MapOptions) {
const { initCallback,
defaultZoomLevel,
dontFitMapBounds,
disableScrollZooming,
minZoomLevel,
mapProvider,
credentials,
defaultCenterPosition,
markerClusteringSetting }: MapOptions = options;
if (disableScrollZooming) {
this.map.scrollWheelZoom.disable();
}
if (initCallback) {
setTimeout(options.initCallback, 0);
}
}
inited() {
return !!this.map;
}
public setMap(map: L.Map) {
this.map = map;
}
getContainer() {
return /* this.isMarketCluster ? this.markersCluster :*/ this.map;
}
/*
fitBounds(bounds, useDefaultZoom) {
if (bounds.isValid()) {
if ((this.dontFitMapBounds || useDefaultZoom) && this.defaultZoomLevel) {
this.map.setZoom(this.defaultZoomLevel, { animate: false });
this.map.panTo(bounds.getCenter(), { animate: false });
} else {
this.map.once('zoomend', () => {
if (!this.defaultZoomLevel && this.map.getZoom() > this.minZoomLevel) {
this.map.setZoom(this.minZoomLevel, { animate: false });
}
});
this.map.fitBounds(bounds, { padding: [50, 50], animate: false });
}
}
}*/
createLatLng(lat, lng) {
return L.latLng(lat, lng);
}
createBounds() {
return this.map.getBounds();
}
extendBounds(bounds, polyline) {
if (polyline && polyline.getLatLngs() && polyline.getBounds()) {
bounds.extend(polyline.getBounds());
}
}
invalidateSize() {
this.map.invalidateSize(true);
}
createTooltip(marker, dsIndex, settings, markerArgs) {
var popup = L.popup();
popup.setContent('');
marker.bindPopup(popup, { autoClose: settings.autocloseTooltip, closeOnClick: false });
if (settings.displayTooltipAction == 'hover') {
marker.off('click');
marker.on('mouseover', function () {
this.openPopup();
});
marker.on('mouseout', function () {
this.closePopup();
});
}
return {
markerArgs: markerArgs,
popup: popup,
locationSettings: settings,
dsIndex: dsIndex
}
}
onResize(){
}
getTooltips() {
return this.tooltips;//rewrite
}
getCenter() {
return this.map.getCenter();
}
}