Repository navigation
Expand file tree
/
Copy pathmap-view-common.js
More file actions
401 lines (401 loc) · 13.5 KB
/
Copy pathmap-view-common.js
File metadata and controls
401 lines (401 loc) · 13.5 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
import { Style } from "./map-view";
import { View } from "tns-core-modules/ui/core/view";
import { Image } from "tns-core-modules/ui/image";
import { LayoutBase } from "tns-core-modules/ui/layouts/layout-base";
import { Property } from "tns-core-modules/ui/core/properties";
import { Color } from "tns-core-modules/color";
import { parseMultipleTemplates, parse } from "tns-core-modules/ui/builder";
import { eachDescendant } from "tns-core-modules/ui/core/view-base";
import { ProxyViewContainer } from "tns-core-modules/ui/proxy-view-container";
import { StackLayout } from "tns-core-modules/ui/layouts/stack-layout";
function onInfoWindowTemplatesChanged(mapView) {
let _infoWindowTemplates = new Array();
if (mapView.infoWindowTemplates && typeof mapView.infoWindowTemplates === "string") {
_infoWindowTemplates = _infoWindowTemplates.concat(parseMultipleTemplates(mapView.infoWindowTemplates));
}
else if (mapView.infoWindowTemplates) {
_infoWindowTemplates = _infoWindowTemplates.concat(mapView.infoWindowTemplates);
}
mapView._infoWindowTemplates = _infoWindowTemplates;
}
function onMapPropertyChanged(mapView) {
if (!mapView.processingCameraEvent)
mapView.updateCamera();
}
function onSetMinZoomMaxZoom(mapView) {
mapView.setMinZoomMaxZoom();
}
function onPaddingPropertyChanged(mapView) {
mapView.updatePadding();
}
function paddingValueConverter(value) {
if (!Array.isArray(value)) {
value = String(value).split(',');
}
value = value.map((v) => parseInt(v, 10));
if (value.length >= 4) {
return value;
}
else if (value.length === 3) {
return [value[0], value[1], value[2], value[2]];
}
else if (value.length === 2) {
return [value[0], value[0], value[1], value[1]];
}
else if (value.length === 1) {
return [value[0], value[0], value[0], value[0]];
}
else {
return [0, 0, 0, 0];
}
}
function onDescendantsLoaded(view, callback) {
if (!view)
return callback();
let loadingCount = 1;
let loadedCount = 0;
const watchLoaded = (view, event) => {
const onLoaded = () => {
view.off(event, onLoaded);
loadedCount++;
if (view instanceof Image && view.isLoading) {
loadingCount++;
watchLoaded(view, 'isLoadingChange');
if (view.nativeView.onAttachedToWindow) {
view.nativeView.onAttachedToWindow();
}
}
if (loadedCount === loadingCount)
callback();
};
view.on(event, onLoaded);
};
eachDescendant(view, (descendant) => {
loadingCount++;
watchLoaded(descendant, View.loadedEvent);
return true;
});
watchLoaded(view, View.loadedEvent);
}
export { Style as StyleBase };
export var knownTemplates;
(function (knownTemplates) {
knownTemplates.infoWindowTemplate = "infoWindowTemplate";
})(knownTemplates || (knownTemplates = {}));
export var knownMultiTemplates;
(function (knownMultiTemplates) {
knownMultiTemplates.infoWindowTemplates = "infoWindowTemplates";
})(knownMultiTemplates || (knownMultiTemplates = {}));
export function getColorHue(color) {
if (typeof color === 'number') {
while (color < 0) {
color += 360;
}
return color % 360;
}
if (typeof color === 'string')
color = new Color(color);
if (!(color instanceof Color))
return color;
let min, max, delta, hue;
const r = Math.max(0, Math.min(1, color.r / 255));
const g = Math.max(0, Math.min(1, color.g / 255));
const b = Math.max(0, Math.min(1, color.b / 255));
min = Math.min(r, g, b);
max = Math.max(r, g, b);
delta = max - min;
if (delta == 0) {
hue = 0;
}
else if (r == max) {
hue = (g - b) / delta;
}
else if (g == max) {
hue = 2 + (b - r) / delta;
}
else {
hue = 4 + (r - g) / delta;
}
hue = ((hue * 60) + 360) % 360;
return hue;
}
export class MapViewBase extends View {
constructor() {
super(...arguments);
this._markers = new Array();
this._shapes = new Array();
this._defaultInfoWindowTemplate = {
key: "",
createView: () => {
if (this.infoWindowTemplate) {
return parse(this.infoWindowTemplate, this);
}
return undefined;
}
};
this._infoWindowTemplates = new Array();
}
get gMap() {
return this._gMap;
}
get processingCameraEvent() {
return this._processingCameraEvent;
}
_getMarkerInfoWindowContent(marker) {
var view;
if (marker && marker._infoWindowView) {
view = marker._infoWindowView;
return view;
}
const template = this._getInfoWindowTemplate(marker);
if (template)
view = template.createView();
if (!view)
return null;
if (!(view instanceof LayoutBase) ||
view instanceof ProxyViewContainer) {
let sp = new StackLayout();
sp.addChild(view);
view = sp;
}
marker._infoWindowView = view;
view.bindingContext = marker;
onDescendantsLoaded(view, () => {
marker.hideInfoWindow();
marker.showInfoWindow();
});
this._addView(view);
view.onLoaded();
return view;
}
_unloadInfoWindowContent(marker) {
if (marker._infoWindowView) {
marker._infoWindowView.onUnloaded();
marker._infoWindowView = null;
}
}
_getInfoWindowTemplate(marker) {
if (marker) {
const templateKey = marker.infoWindowTemplate;
for (let i = 0, length = this._infoWindowTemplates.length; i < length; i++) {
if (this._infoWindowTemplates[i].key === templateKey) {
return this._infoWindowTemplates[i];
}
}
}
return this._defaultInfoWindowTemplate;
}
removeAllPolylines() {
if (!this._shapes)
return null;
this._shapes.forEach(shape => {
if (shape.shape === 'polyline') {
this.removeShape(shape);
}
});
}
removeAllPolygons() {
if (!this._shapes)
return null;
this._shapes.forEach(shape => {
if (shape.shape === 'polygon') {
this.removeShape(shape);
}
});
}
removeAllCircles() {
if (!this._shapes)
return null;
this._shapes.forEach(shape => {
if (shape.shape === 'circle') {
this.removeShape(shape);
}
});
}
notifyMapReady() {
this.notify({ eventName: MapViewBase.mapReadyEvent, object: this, gMap: this.gMap });
}
notifyMarkerEvent(eventName, marker) {
let args = { eventName: eventName, object: this, marker: marker };
this.notify(args);
}
notifyShapeEvent(eventName, shape) {
let args = { eventName: eventName, object: this, shape: shape };
this.notify(args);
}
notifyMarkerTapped(marker) {
this.notifyMarkerEvent(MapViewBase.markerSelectEvent, marker);
}
notifyMarkerInfoWindowTapped(marker) {
this.notifyMarkerEvent(MapViewBase.markerInfoWindowTappedEvent, marker);
}
notifyMarkerInfoWindowClosed(marker) {
this.notifyMarkerEvent(MapViewBase.markerInfoWindowClosedEvent, marker);
}
notifyShapeTapped(shape) {
this.notifyShapeEvent(MapViewBase.shapeSelectEvent, shape);
}
notifyMarkerBeginDragging(marker) {
this.notifyMarkerEvent(MapViewBase.markerBeginDraggingEvent, marker);
}
notifyMarkerEndDragging(marker) {
this.notifyMarkerEvent(MapViewBase.markerEndDraggingEvent, marker);
}
notifyMarkerDrag(marker) {
this.notifyMarkerEvent(MapViewBase.markerDragEvent, marker);
}
notifyPositionEvent(eventName, position) {
let args = { eventName: eventName, object: this, position: position };
this.notify(args);
}
notifyCameraEvent(eventName, camera) {
let args = { eventName: eventName, object: this, camera: camera };
this.notify(args);
}
notifyMyLocationTapped() {
this.notify({ eventName: MapViewBase.myLocationTappedEvent, object: this });
}
notifyBuildingFocusedEvent(indoorBuilding) {
let args = { eventName: MapViewBase.indoorBuildingFocusedEvent, object: this, indoorBuilding: indoorBuilding };
this.notify(args);
}
notifyIndoorLevelActivatedEvent(activateLevel) {
let args = { eventName: MapViewBase.indoorLevelActivatedEvent, object: this, activateLevel: activateLevel };
this.notify(args);
}
}
MapViewBase.mapReadyEvent = "mapReady";
MapViewBase.markerSelectEvent = "markerSelect";
MapViewBase.markerInfoWindowTappedEvent = "markerInfoWindowTapped";
MapViewBase.markerInfoWindowClosedEvent = "markerInfoWindowClosed";
MapViewBase.shapeSelectEvent = "shapeSelect";
MapViewBase.markerBeginDraggingEvent = "markerBeginDragging";
MapViewBase.markerEndDraggingEvent = "markerEndDragging";
MapViewBase.markerDragEvent = "markerDrag";
MapViewBase.coordinateTappedEvent = "coordinateTapped";
MapViewBase.coordinateLongPressEvent = "coordinateLongPress";
MapViewBase.cameraChangedEvent = "cameraChanged";
MapViewBase.cameraMoveEvent = "cameraMove";
MapViewBase.myLocationTappedEvent = "myLocationTapped";
MapViewBase.indoorBuildingFocusedEvent = "indoorBuildingFocused";
MapViewBase.indoorLevelActivatedEvent = "indoorLevelActivated";
export const infoWindowTemplateProperty = new Property({ name: "infoWindowTemplate" });
infoWindowTemplateProperty.register(MapViewBase);
export const infoWindowTemplatesProperty = new Property({ name: "infoWindowTemplates", valueChanged: onInfoWindowTemplatesChanged });
infoWindowTemplatesProperty.register(MapViewBase);
export const latitudeProperty = new Property({ name: 'latitude', defaultValue: 0, valueChanged: onMapPropertyChanged });
latitudeProperty.register(MapViewBase);
export const longitudeProperty = new Property({ name: 'longitude', defaultValue: 0, valueChanged: onMapPropertyChanged });
longitudeProperty.register(MapViewBase);
export const bearingProperty = new Property({ name: 'bearing', defaultValue: 0, valueChanged: onMapPropertyChanged });
bearingProperty.register(MapViewBase);
export const zoomProperty = new Property({ name: 'zoom', defaultValue: 0, valueChanged: onMapPropertyChanged });
zoomProperty.register(MapViewBase);
export const minZoomProperty = new Property({ name: 'minZoom', defaultValue: 0, valueChanged: onSetMinZoomMaxZoom });
minZoomProperty.register(MapViewBase);
export const maxZoomProperty = new Property({ name: 'maxZoom', defaultValue: 22, valueChanged: onSetMinZoomMaxZoom });
maxZoomProperty.register(MapViewBase);
export const tiltProperty = new Property({ name: 'tilt', defaultValue: 0, valueChanged: onMapPropertyChanged });
tiltProperty.register(MapViewBase);
export const paddingProperty = new Property({ name: 'padding', valueChanged: onPaddingPropertyChanged, valueConverter: paddingValueConverter });
paddingProperty.register(MapViewBase);
export const mapAnimationsEnabledProperty = new Property({ name: 'mapAnimationsEnabled', defaultValue: true });
mapAnimationsEnabledProperty.register(MapViewBase);
export class UISettingsBase {
}
export class ProjectionBase {
}
export class VisibleRegionBase {
}
export class PositionBase {
}
export class BoundsBase {
}
export class MarkerBase {
}
export class ShapeBase {
}
export class PolylineBase extends ShapeBase {
constructor() {
super(...arguments);
this.shape = 'polyline';
}
addPoint(point) {
this._points.push(point);
this.reloadPoints();
}
addPoints(points) {
this._points = this._points.concat(points);
this.reloadPoints();
}
removePoint(point) {
var index = this._points.indexOf(point);
if (index > -1) {
this._points.splice(index, 1);
this.reloadPoints();
}
}
removeAllPoints() {
this._points.length = 0;
this.reloadPoints();
}
getPoints() {
return this._points.slice();
}
}
export class PolygonBase extends ShapeBase {
constructor() {
super(...arguments);
this.shape = 'polygon';
}
addPoint(point) {
this._points.push(point);
this.reloadPoints();
}
addPoints(points) {
this._points = this._points.concat(points);
this.reloadPoints();
}
removePoint(point) {
var index = this._points.indexOf(point);
if (index > -1) {
this._points.splice(index, 1);
this.reloadPoints();
}
}
removeAllPoints() {
this._points.length = 0;
this.reloadPoints();
}
getPoints() {
return this._points.slice();
}
addHole(hole) {
this._holes.push(hole);
this.reloadHoles();
}
addHoles(holes) {
this._holes = this._holes.concat(holes);
this.reloadHoles();
}
removeHole(hole) {
var index = this._holes.indexOf(hole);
if (index > -1) {
this._holes.splice(index, 1);
this.reloadHoles();
}
}
removeAllHoles() {
this._holes.length = 0;
this.reloadHoles();
}
getHoles() {
return this._holes.slice();
}
}
export class CircleBase extends ShapeBase {
constructor() {
super(...arguments);
this.shape = 'circle';
}
}