forked from Yermo/nativescript-mapbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmapbox-common.js
executable file
·210 lines (184 loc) · 5.22 KB
/
mapbox-common.js
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
var view = require("ui/core/view");
var mapbox = {};
mapbox.MapStyle = {
DARK: "dark",
EMERALD: "emerald",
HYBRID: "hybrid",
LIGHT: "light",
SATELLITE: "satellite",
STREETS: "streets"
};
mapbox.defaults = {
style: 'streets',
margins: {
left: 0,
right: 0,
top: 0,
bottom: 0
},
zoomLevel: 0, // 0 (a big part of the world) to 20 (streetlevel)
showUserLocation: false, // true requires adding `NSLocationWhenInUseUsageDescription` or `NSLocationAlwaysUsageDescription` in the .plist
hideLogo: false, // required for the 'starter' plan
hideAttribution: true,
hideCompass: false,
disableRotation: false,
disableScroll: false,
disableZoom: false,
disableTilt: false
};
mapbox.merge = function merge(obj1, obj2){ // Our merge function
var result = {}; // return result
for(var i in obj1){ // for every property in obj1
if((i in obj2) && (typeof obj1[i] === "object") && (i !== null)){
result[i] = merge(obj1[i],obj2[i]); // if it's an object, merge
}else{
result[i] = obj1[i]; // add it to result
}
}
for(i in obj2){ // add the remaining properties from object 2
if(i in result){ //conflict
continue;
}
result[i] = obj2[i];
}
return result;
};
mapbox.requestFineLocationPermission = function () {
return new Promise(function (resolve) {
resolve(true);
});
};
mapbox.hasFineLocationPermission = function () {
return new Promise(function (resolve) {
resolve(true);
});
};
/*************** XML definition START ****************/
var Mapbox = (function (_super) {
global.__extends(Mapbox, _super);
function Mapbox() {
_super.call(this);
}
Mapbox.mapReadyEvent = "mapReady";
Mapbox.prototype.notifyMapReady = function () {
this.notify({
eventName: Mapbox.mapReadyEvent,
map: this,
native: this.native
});
};
// functions that can be called from the XML map's "mapReady" event
Mapbox.prototype.addMarkers = function (args) {
mapbox.addMarkers(args, this.native);
};
Mapbox.prototype.removeMarkers = function (args) {
mapbox.removeMarkers(args, this.native);
};
Mapbox.prototype.setCenter = function (args) {
mapbox.setCenter(args, this.native);
};
Mapbox.prototype.setZoomLevel = function (args) {
mapbox.setZoomLevel(args, this.native);
};
Mapbox.prototype.setViewport = function (args) {
mapbox.setViewport(args, this.native);
};
Mapbox.prototype.setOnMapClickListener = function (args) {
mapbox.setOnMapClickListener(args, this.native);
};
Mapbox.prototype.setTilt = function (args) {
mapbox.setTilt(args, this.native);
};
Mapbox.prototype.animateCamera = function (args) {
mapbox.animateCamera(args, this.native);
};
Mapbox.prototype.addPolygon = function (args) {
mapbox.addPolygon(args, this.native);
};
Mapbox.prototype.addPolyline = function (args) {
mapbox.addPolyline(args, this.native);
};
Mapbox.prototype.removePolylines = function (args) {
mapbox.removePolylines(args, this.native);
};
Mapbox.prototype.setMapStyle = function (args) {
mapbox.setMapStyle(args, this.native);
};
// properties that can be set from XML
Object.defineProperty(Mapbox.prototype, "accessToken", {
set: function (value) {
this.config.accessToken = value;
}
});
Object.defineProperty(Mapbox.prototype, "delay", {
set: function (value) {
this.config.delay = parseInt(value) || 0;
}
});
Object.defineProperty(Mapbox.prototype, "mapStyle", {
set: function (value) {
this.config.style = value;
}
});
Object.defineProperty(Mapbox.prototype, "zoomLevel", {
set: function (value) {
this.config.zoomLevel = value;
}
});
Object.defineProperty(Mapbox.prototype, "disableZoom", {
set: function (value) {
this.config.disableZoom = value;
}
});
Object.defineProperty(Mapbox.prototype, "hideAttribution", {
set: function (value) {
this.config.hideAttribution = value;
}
});
Object.defineProperty(Mapbox.prototype, "latitude", {
set: function (value) {
this.config.center = this.config.center || {};
this.config.center.lat = value;
}
});
Object.defineProperty(Mapbox.prototype, "longitude", {
set: function (value) {
this.config.center = this.config.center || {};
this.config.center.lng = value;
}
});
Object.defineProperty(Mapbox.prototype, "hideLogo", {
set: function (value) {
this.config.hideLogo = value;
}
});
Object.defineProperty(Mapbox.prototype, "showUserLocation", {
set: function (value) {
this.config.showUserLocation = value;
}
});
Object.defineProperty(Mapbox.prototype, "hideCompass", {
set: function (value) {
this.config.hideCompass = value;
}
});
Object.defineProperty(Mapbox.prototype, "disableRotation", {
set: function (value) {
this.config.disableRotation = value;
}
});
Object.defineProperty(Mapbox.prototype, "disableScroll", {
set: function (value) {
this.config.disableScroll = value;
}
});
Object.defineProperty(Mapbox.prototype, "disableTilt", {
set: function (value) {
this.config.disableTilt = value;
}
});
return Mapbox;
}(view.View));
mapbox.Mapbox = Mapbox;
/*************** XML definition END ****************/
module.exports = mapbox;