forked from dapriett/nativescript-google-maps-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
map-view-common.ts
233 lines (182 loc) · 7.43 KB
/
map-view-common.ts
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
import { MapView as IMapView, Position as IPosition, Marker as IMarker, Shape as IShape, Polyline as IPolyline, Polygon as IPolygon, Circle as ICircle, Camera, MarkerEventData, ShapeEventData, CameraEventData, PositionEventData } from ".";
import { View } from "ui/core/view";
import { Image } from "ui/image";
import { Property, PropertyChangeData, PropertyMetadata, PropertyMetadataSettings } from "ui/core/dependency-observable";
//let CAMERA_PROPERTIES : String[] = ["latitude", "longitude", "bearing", "zoom", "tilt", "padding"];
let MAP_VIEW: string = "MapView";
function onMapPropertyChanged(data: PropertyChangeData) {
let mapView = <MapView>data.object;
if (!mapView._processingCameraEvent) mapView.updateCamera();
}
function onPaddingPropertyChanged(data: PropertyChangeData) {
let mapView = <MapView>data.object;
mapView.updatePadding();
}
export abstract class MapView extends View implements IMapView {
public gMap: any;
public static mapReadyEvent: string = "mapReady";
public static markerSelectEvent: string = "markerSelect";
public static markerInfoWindowTappedEvent:string = "markerInfoWindowTapped";
public static shapeSelectEvent: string = "shapeSelect";
public static markerBeginDraggingEvent: string = "markerBeginDragging";
public static markerEndDraggingEvent: string = "markerEndDragging";
public static markerDragEvent: string = "markerDrag";
public static coordinateTappedEvent: string = "coordinateTapped";
public static coordinateLongPressEvent: string = "coordinateLongPress";
public static cameraChangedEvent: string = "cameraChanged";
public static latitudeProperty = new Property("latitude", MAP_VIEW, new PropertyMetadata(0, PropertyMetadataSettings.None, onMapPropertyChanged));
public static longitudeProperty = new Property("longitude", MAP_VIEW, new PropertyMetadata(0, PropertyMetadataSettings.None, onMapPropertyChanged));
public static bearingProperty = new Property("bearing", MAP_VIEW, new PropertyMetadata(0, PropertyMetadataSettings.None, onMapPropertyChanged));
public static zoomProperty = new Property("zoom", MAP_VIEW, new PropertyMetadata(0, PropertyMetadataSettings.None, onMapPropertyChanged));
public static tiltProperty = new Property("tilt", MAP_VIEW, new PropertyMetadata(0, PropertyMetadataSettings.None, onMapPropertyChanged));
public static paddingProperty = new Property("padding", MAP_VIEW, new PropertyMetadata(0, PropertyMetadataSettings.None, onPaddingPropertyChanged));
get latitude() {
return this._getValue(MapView.latitudeProperty);
}
set latitude(value: any) {
this._setValue(MapView.latitudeProperty, parseFloat(value));
}
get longitude() {
return this._getValue(MapView.longitudeProperty);
}
set longitude(value: any) {
this._setValue(MapView.longitudeProperty, parseFloat(value));
}
get bearing() {
return this._getValue(MapView.bearingProperty);
}
set bearing(value: any) {
this._setValue(MapView.bearingProperty, parseFloat(value));
}
get zoom() {
return this._getValue(MapView.zoomProperty);
}
set zoom(value: any) {
this._setValue(MapView.zoomProperty, parseFloat(value));
}
get tilt() {
return this._getValue(MapView.tiltProperty);
}
set tilt(value: any) {
this._setValue(MapView.tiltProperty, parseFloat(value));
}
get padding() {
return this._getValue(MapView.paddingProperty);
}
set padding(value: any) {
this._setValue(MapView.paddingProperty, this._transformPadding(value));
}
private _transformPadding(value) {
if (!Array.isArray(value)) {
value = String(value).split(',').map(function(v) {
return parseInt(v, 10);
});
}
if (value.length === 4) {
return value;
} else {
return [0, 0, 0, 0];
}
}
public abstract updateCamera(): void;
public abstract updatePadding(): void;
notifyMapReady() {
this.notify({ eventName: MapView.mapReadyEvent, object: this, gMap: this.gMap });
}
public abstract addMarker(marker: IMarker): void;
public abstract removeMarker(marker: IMarker): void;
public abstract removeAllMarkers(): void;
public abstract addPolyline(shape: Polyline): void;
public abstract addPolygon(shape: Polygon): void;
public abstract addCircle(shape: Circle): void;
public abstract removeShape(shape: Shape): void;
public abstract removeAllShapes(): void;
protected _shapes: Array<IShape>;
public removeAllPolylines() {
this._shapes.forEach(shape => {
if (shape.shape === 'polyline') {
this.removeShape(shape);
}
});
}
public removeAllPolygons() {
this._shapes.forEach(shape => {
if (shape.shape === 'polygon') {
this.removeShape(shape);
}
});
}
public removeAllCircles() {
this._shapes.forEach(shape => {
if (shape.shape === 'circle') {
this.removeShape(shape);
}
});
}
public abstract clear(): void;
public abstract setStyle(): void;
notifyMarkerEvent(eventName: string, marker: IMarker) {
let args: MarkerEventData = { eventName: eventName, object: this, marker: marker };
this.notify(args);
}
notifyShapeEvent(eventName: string, shape: IShape) {
let args: ShapeEventData = { eventName: eventName, object: this, shape: shape };
this.notify(args);
}
notifyMarkerTapped(marker: Marker) {
this.notifyMarkerEvent(MapView.markerSelectEvent, marker);
}
notifyMarkerInfoWindowTapped(marker: Marker) {
this.notifyMarkerEvent(MapView.markerInfoWindowTappedEvent, marker);
}
notifyShapeTapped(shape: Shape) {
this.notifyShapeEvent(MapView.shapeSelectEvent, shape);
}
notifyMarkerBeginDragging(marker: Marker) {
this.notifyMarkerEvent(MapView.markerBeginDraggingEvent, marker);
}
notifyMarkerEndDragging(marker: Marker) {
this.notifyMarkerEvent(MapView.markerEndDraggingEvent, marker);
}
notifyMarkerDrag(marker: Marker) {
this.notifyMarkerEvent(MapView.markerDragEvent, marker);
}
notifyPositionEvent(eventName: string, position: IPosition) {
let args: PositionEventData = { eventName: eventName, object: this, position: position };
this.notify(args);
}
notifyCameraEvent(eventName: string, camera: Camera) {
let args: CameraEventData = { eventName: eventName, object: this, camera: camera };
this.notify(args);
}
}
export class Position implements IPosition {
public latitude: number;
public longitude: number;
}
export class Marker implements IMarker {
public position: IPosition;
public snippet: string;
public title: string;
public icon: Image;
public userData: any;
public _map: any;
}
export class Shape implements IShape {
public shape: string;
public userData: any;
public clickable: boolean;
}
export class Polyline extends Shape implements IPolyline {
public shape: string = 'polyline';
public _map: any;
}
export class Polygon extends Shape implements IPolygon {
public shape: string = 'polygon';
public _map: any;
}
export class Circle extends Shape implements ICircle {
public shape: string = 'circle';
public center: IPosition;
public _map: any;
}