-
Notifications
You must be signed in to change notification settings - Fork 1
/
APIBridgeJS.lib
2365 lines (2062 loc) · 91.4 KB
/
APIBridgeJS.lib
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
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* Copyright (c) 2014 by Center Open Middleware. All Rights Reserved.
* Titanium Appcelerator 3.3.0GA
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/
/**
* @namespace Yaast
*/
(function () {
"use strict";
var eventHandlers = {};
var methodHandlers = {};
var appleOS;
var id;
var prefs = null;
var inputs = {};
var callCounter = 0;
var _genericMethodHandler = function _genericMethodHandler(callback, methName, params, options, isAsync) {
var methodInfo, data;
if (methodHandlers[methName] == null) {
methodHandlers[methName] = {};
}
callCounter = callCounter + 1;
methodHandlers[methName][callCounter] = callback;
methodInfo = methName.split('.');
Ti.API.info('[APIBridge] Adding method listener: ' + methName + '_' + id + '_' + callCounter);
Ti.App.addEventListener(methName + '_' + id + '_' + callCounter, _sendMethodResult.bind(this, methName, callCounter));
data = {
'method': {
type: methodInfo[1],
subapi: methodInfo[2],
name: methodInfo[3],
eventName: methName
},
'params': params,
'options': options,
'viewId': id,
'callId': callCounter
};
if (!isAsync) {
Ti.API.info('[APIBridge] Fire Event "APIMethod". data: ' + JSON.stringify(data));
Ti.App.fireEvent('APIMethod', data);
} else {
Ti.API.info('[APIBridge] Fire Event "APIMethodAsync". data: ' + JSON.stringify(data));
Ti.App.fireEvent('APIMethodAsync', data);
}
};
var _sendMethodResult = function (methName, callCounter, data) {
Ti.API.info('++++++++++++[APIBridge]+++++++++++++ HTML!!!');
Ti.API.info('[APIBridge] Method result recived: ' + JSON.stringify(data.returnedData));
//Ti.API.info('parseados?: ' + JSON.parse(data));
if (methodHandlers[methName] == null || methodHandlers[methName][callCounter] == null) {
// TODO Error. Callback not found
Ti.API.info('[APIBridge] error in _sendMethodResult Callback not found');
} else {
// This solve iOs problem and i dont know why this run in Android without this fixed
if (data.returnedData === undefined) {
data.returnedData = null;
}
// Execute callback
Ti.API.info('[APIBridge] invocando callback html...');
methodHandlers[methName][callCounter](data.returnedData);
}
};
// APIBridge definition
/**
* @namespace Yaast.API
* @memberof Yaast
*/
Object.defineProperty(window, 'API', {value: {
/**
* @namespace Yaast.API.SW
* @memberof Yaast.API
*/
SW : {
/**
* @classdesc Contacts API.
* @class
* @alias Contacts
* @memberof Yaast.API.SW
*/
Contacts : {
/** Get Authorization Property
* Condition AUTHORIZATION_UNKNOWN -> RequestAuthorization
* @memberof Yaast.API.SW.Contacts
* @alias getAuthorization
* @param {function} Callback
* @return {Number} AUTHORIZATION_AUTHORIZED or AUTHORIZATION_RESTRICTED
*/
getAuthorization: function(callback) {
_genericMethodHandler.call(this, callback, 'API.SW.Contacts.getAuthorization', [], null, true);
},
/** Get Contact List
* @memberof Yaast.API.SW.Contacts
* @alias getContactList
* @param {function} Callback
* @param {Object} options The following options:<br>
* - name: {String} (optional)
* @return {Array} Array of contacts
*/
getContactList: function(callback, options) {
if (!(options instanceof Object) || options.value == null) {
options = null;
}
_genericMethodHandler.call(this, callback, 'API.SW.Contacts.getContactList', [], options);
},
/** Create Contact.
* @memberof Yaast.API.SW.Contacts
* @alias createContact
* @param {function} Callback
* @param {Object} options
* @return {Object}
*/
createContact: function(callback, options) {
if (!(options instanceof Object)) {
options = null;
}
_genericMethodHandler.call(this, callback, 'API.SW.Contacts.createContact', [], options);
},
/** Save Changes
* @memberof Yaast.API.SW.Contacts
* @alias saveChanges
* @param {function} Callback
*/
saveChanges: function(callback) {
_genericMethodHandler.call(this, callback, 'API.SW.Contacts.saveChanges');
},
/** Revert Changes from last save
* @memberof Yaast.API.SW.Contacts
* @alias revertChanges
* @param {function} Callback
*/
revertChanges: function(callback) {
_genericMethodHandler.call(this, callback, 'API.SW.Contacts.revertChanges');
},
/** Delete Contact
* @memberof Yaast.API.SW.Contacts
* @alias deleteContact
* @param {function} Callback
* @param {String} Contact Name
* @return {Number}
*/
deleteContact: function(callback, contactName) {
if (typeof contactName === "string") {
_genericMethodHandler.call(this, callback, 'API.SW.Contacts.deleteContact', [contactName]);
}
},
},
Calendar : {
},
FileSystem : {
},
DataBase : {
},
Log : {
},
Map :
(function () {
"use strict";
/**
* @classdesc Map API.
* @class
* @alias Map
* @memberof Yaast.API.SW
*/
var Map = function Map(){
var _allowedEventsData = {
"map": {
"click": {
"asIs": ["latitude", "longitude"],
"id": ["source"]
},
"complete": {
"asIs": [],
"id": []
},
"longclick": {
"asIs": ["latitude", "longitude"],
"id": []
},
"regionchanged": {
"asIs": ["animated", "latitude", "latitudeDelta", "longitude", "longitudeDelta"],
"id": []
},
"postlayout": {
"asIs": [],
"id": []
}
},
"polygon": {
"click": {
"asIs": ["latitude", "longitude", "type"],
"id": ["source"]
}
},
"annotation": {
"click": {
"asIs": ["latitude", "longitude", "type", "clicksource"],
"id": ["source"]
}
}
};
/*
* CONSTANTS
*/
/**
* Block level accuracy is considered to be about 100 meter accuracy. Using a coarse accuracy such as this often consumes less power.
* @constant
* @memberof Yaast.API.SW.Map
* @alias PRIORITY_BALANCED_POWER_ACCURACY
*/
this.PRIORITY_BALANCED_POWER_ACCURACY = 102;
/**
* Request the most accurate locations available. This will return the finest location available.
* @constant
* @memberof Yaast.API.SW.Map
* @alias PRIORITY_HIGH_ACCURACY
*/
this.PRIORITY_HIGH_ACCURACY = 100;
/**
* Used to request "city" level accuracy. City level accuracy is considered to be about 10km accuracy. Using a coarse accuracy such as this
* often consumes less power.
* @constant
* @memberof Yaast.API.SW.Map
* @alias PRIORITY_LOW_POWER
*/
this.PRIORITY_LOW_POWER = 104;
/**
* Used to request the best accuracy possible with zero additional power consumption. No locations will be returned unless a different client
* has requested location updates in which case this request will act as a passive listener to those locations.
* @constant
* @memberof Yaast.API.SW.Map
* @alias PRIORITY_NO_POWER
*/
this.PRIORITY_NO_POWER = 105;
/**
* Use the default accuracy.
* @constant
* @memberof Yaast.API.SW.Map
* @alias PRIORITY_UNDEFINED
*/
this.PRIORITY_UNDEFINED = -1;
/**
* Normal layer.
* @constant
* @memberof Yaast.API.SW.Map
* @alias NORMAL_TYPE
*/
this.NORMAL_TYPE = 1;
/**
* Terrain layer.
* @constant
* @memberof Yaast.API.SW.Map
* @alias TERRAIN_TYPE
*/
this.TERRAIN_TYPE = 3;
/**
* Satellite layer.
* @constant
* @memberof Yaast.API.SW.Map
* @alias SATELLITE_TYPE
*/
this.SATELLITE_TYPE = 2;
/**
* Hybrid layer.
* @constant
* @memberof Yaast.API.SW.Map
* @alias HYBRID_TYPE
*/
this.HYBRID_TYPE = 4;
/**
* Predefined HUE azure color for the annotation.
* @constant
* @memberof Yaast.API.SW.Map
* @alias ANNOTATION_AZURE
*/
this.ANNOTATION_AZURE = 210.0;
/**
* Predefined HUE blue color for the annotation.
* @constant
* @memberof Yaast.API.SW.Map
* @alias ANNOTATION_BLUE
*/
this.ANNOTATION_BLUE = 240.0;
/**
* Predefined HUE cyan color for the annotation.
* @constant
* @memberof Yaast.API.SW.Map
* @alias ANNOTATION_CYAN
*/
this.ANNOTATION_CYAN = 180.0;
/**
* Predefined HUE green color for the annotation.
* @constant
* @memberof Yaast.API.SW.Map
* @alias ANNOTATION_GREEN
*/
this.ANNOTATION_GREEN = 120.0;
/**
* Predefined HUE magenta color for the annotation.
* @constant
* @memberof Yaast.API.SW.Map
* @alias ANNOTATION_MAGENTA
*/
this.ANNOTATION_MAGENTA = 300.0;
/**
* Predefined HUE orange color for the annotation.
* @constant
* @memberof Yaast.API.SW.Map
* @alias ANNOTATION_ORANGE
*/
this.ANNOTATION_ORANGE = 30.0;
/**
* Predefined HUE red color for the annotation.
* @constant
* @memberof Yaast.API.SW.Map
* @alias ANNOTATION_RED
*/
this.ANNOTATION_RED = 0.0;
/**
* Predefined HUE rose color for the annotation.
* @constant
* @memberof Yaast.API.SW.Map
* @alias ANNOTATION_ROSE
*/
this.ANNOTATION_ROSE = 330.0;
/**
* Predefined HUE violet color for the annotation.
* @constant
* @memberof Yaast.API.SW.Map
* @alias ANNOTATION_VIOLET
*/
this.ANNOTATION_VIOLET = 270.0;
/**
* Predefined HUE yellow color for the annotation.
* @constant
* @memberof Yaast.API.SW.Map
* @alias ANNOTATION_YELLOW
*/
this.ANNOTATION_YELLOW = 60.0;
/**
* WMS 1.1.1 layer type.
* @constant
* @memberof Yaast.API.SW.Map
* @alias LAYER_TYPE_WMS_1_1_1
*/
this.LAYER_TYPE_WMS_1_1_1 = 1;
/**
* WMS 1.3.0 layer type.
* @constant
* @memberof Yaast.API.SW.Map
* @alias LAYER_TYPE_WMS_1_3_0
*/
this.LAYER_TYPE_WMS_1_3_0 = 2;
/**
* PNG image format.
* @constant
* @memberof Yaast.API.SW.Map
* @alias FORMAT_PNG
*/
this.FORMAT_PNG = 1;
/**
* JPEG image format.
* @constant
* @memberof Yaast.API.SW.Map
* @alias FORMAT_JPEG
*/
this.FORMAT_JPEG = 2;
/**
* Check if there is support for the map.
* @memberof Yaast.API.SW.Map
* @alias isMapAvailable
* @param {function} callback Function that receives a boolean. True if the map can be used.
*/
this.isMapAvailable = function(callback){
_genericMethodHandler.call(this, callback, 'API.SW.Map.isMapAvailable', [], null);
};
/**
* Creates a new map view.
* @memberof Yaast.API.SW.Map
* @alias createMap
* @param {object} options See {@link http://docs.appcelerator.com/titanium/3.0/#!/api/Modules.Map.View}
* @param {function} callback Function that receives a MapView object.
*/
this.createMap = function(options, callback){
var handleCreateMap = function(callback, mapId){
callback(new MapView(mapId));
}.bind(null, callback);
_genericMethodHandler.call(this, handleCreateMap, 'API.SW.Map.createMap', [], options);
};
/**
* Creates an Annotation.
* @memberof Yaast.API.SW.Map
* @alias createAnnotation
* @param {object} Options {@link See http://docs.appcelerator.com/titanium/3.0/#!/api/Modules.Map.Annotation}
* @param {function} callback Function that receives a Annotation object.
*/
this.createAnnotation = function(options, callback){
var handleCreateAnnotation = function(callback, annotationId){
if(annotationId != null)
callback(new Annotation(annotationId));
}.bind(null, callback);
_genericMethodHandler.call(this, handleCreateAnnotation, 'API.SW.Map.createAnnotation', [], options);
};
/**
* Creates a Route.
* @memberof Yaast.API.SW.Map
* @alias createRoute
* @param {object} options See {@link http://docs.appcelerator.com/titanium/3.0/#!/api/Modules.Map.Route}
* @param {function} callback Function that receives a Route object.
*/
this.createRoute = function(options, callback){
var handleCreateRoute = function(callback, routeId){
if(routeId != null)
callback(new Route(routeId));
}.bind(null, callback);
_genericMethodHandler.call(this, handleCreateRoute, 'API.SW.Map.createRoute', [], options);
};
/**
* Creates a Layer.
* @memberof Yaast.API.SW.Map
* @alias createLayer
* @param {options}
* - baseUrl: String with the url of the service<br>
* - type: Type of service ({@link Map.LAYER_TYPE_WMS_1_1_1} | {@link Map.LAYER_TYPE_WMS_1_3_0})<br>
* - name: String with the name of the layer.<br>
* - srs: String with the srs of the layer.<br>
* - visible: Boolean<br>
* - zIndex: Number ZIndex of the layer.<br>
* - opacity: Number Percentage of opacity [0 - 100].<br>
* - format: Type of image of the tiles ({@link Map.FORMAT_PNG} | {@link Map.FORMAT_JPEG})<br>
* @param {function} callback Function that receives a Layer object.
*/
this.createLayer = function(options, callback){
var handleCreateLayer = function(callback, layerId){
if(layerId != null)
callback(new Layer(layerId));
}.bind(null, callback);
_genericMethodHandler.call(this, handleCreateLayer, 'API.SW.Map.createLayer', [], options);
};
/**
* Creates a Polygon.
* @memberof Yaast.API.SW.Map
* @alias createPolygon
* @param {object} options
* - id: optional. Must be unique.<br>
* - points: Array of points [{latitude: Number, longitude: Number}, ...]<br>
* - holePoints: Array with holes. A hole is an array of points.<br>
* - fillColor: Color<br>
* - strokeColor: Color<br>
* - strokeWidth: Number<br>
* - annotation: Annotation object.<br>
*
* @param {function} callback Function that receives a Polygon object.
*/
this.createPolygon = function(options, callback){
var handleCreatePolygon = function(callback, polygonId){
if(polygonId != null)
callback(new Polygon(polygonId));
}.bind(null, callback);
_genericMethodHandler.call(this, handleCreatePolygon, 'API.SW.Map.createPolygon', [], options);
};
/**
* Parses a given KML string and returns an object with the polygons and routes of the file.
* @memberof Yaast.API.SW.Map
* @alias getShapesFromKml
* @param {String} data The KML string to parse
* @param {function} callback Called with an object with results.
* Object with the format {polygons: array, routes: array, annotations: array}. Null if there was an exception while parsing the KML string .
*/
this.getShapesFromKml = function(data, callback){
var handleGetShapes = function(callback, shapes){
callback(shapes);
}.bind(null, callback);
_genericMethodHandler.call(this, handleGetShapes, 'API.SW.Map.getShapesFromKml', [data], null);
};
/**
* Parses a given WKT string and returns an object with the polygons and routes.
* @memberof Yaast.API.SW.Map
* @alias getShapesFromWkt
* @param {string} data The WKT string to parse
* @param {function} callback Called with an object with results.
* Object with the format {polygons: array, routes: array, annotations: array}. Null if there was an exception while parsing the WKT string .
*/
this.getShapesFromWkt = function(data, callback){
var handleGetShapes = function(callback, shapes){
callback(shapes);
}.bind(null, callback);
_genericMethodHandler.call(this, handleGetShapes, 'API.SW.Map.getShapesFromWkt', [data], null);
};
/**
* Parses a given GeoJson string and returns an object with the polygons and routes of the file.
* @memberof Yaast.API.SW.Map
* @alias getShapesFromGeoJson
* @param {string} data The GeoJson string to parse
* @param {function} callback Called with an object with results.
* Object with the format {polygons: array, routes: array, annotations: array}. Null if there was an exception while parsing the GeoJSON string .
*/
this.getShapesFromGeoJson = function(data, callback){
var handleGetShapes = function(callback, shapes){
callback(shapes);
}.bind(null, callback);
_genericMethodHandler.call(this, handleGetShapes, 'API.SW.Map.getShapesFromGeoJson', [data], null);
};
var voidCallback = function(){ /*This callback is void*/};
var events = {};
//Create the event listener
Ti.App.addEventListener("API_MAP_EVENT", function(eventInfo){
var event = eventInfo.event;
var elementId = eventInfo.elementId;
var data = eventInfo.data;
var elementType = eventInfo.elementType;
if(events[elementType] != null && events[elementType][event] != null && events[elementType][event][elementId] != null){
for(var index in events[elementType][event][elementId]){
events[elementType][event][elementId][index](_filterEventData(elementType, event, data));
}
}
});
var _filterEventData = function(elementType, event, data){
var newData = {};
if(_allowedEventsData[elementType] != null && _allowedEventsData[elementType][event] != null){
var asIs = _allowedEventsData[elementType][event]["asIs"];
var id = _allowedEventsData[elementType][event]["id"];
if(asIs != null){
for(var x = 0; x < asIs.length; x++){
var propertyType = asIs[x];
newData[propertyType] = data[propertyType];
}
}
if(id != null){
for(var x = 0; x < id.length; x++){
var propertyType = id[x];
if(data[propertyType] != null){
newData[propertyType] = _convertToElement(data[propertyType], elementType);
}
}
}
}
return newData;
};
var _registerEventHandler = function(event, callback){
if(event != null && event != "" && this.type != null && this.type != ""){
var alreadyExists = false;
if(events[this.type] != null && events[this.type][event] != null && events[this.type][event][this.id] != null)
alreadyExists = true;
else{
if(events[this.type] == null)
events[this.type] = {};
if(events[this.type][event] == null)
events[this.type][event] = {};
events[this.type][event][this.id] = [];
}
events[this.type][event][this.id].push(callback);
if(!alreadyExists){
Ti.App.fireEvent("API_MAP_EDIT_EVENT", { action: "add", event: event, elementId: this.id, elementType: this.type });
}
}
};
var _removeEventHandler = function(event, callback){
if(event != null && event != "" && this.type != null && this.type != "" && events[this.type] != null && events[this.type][event] != null && events[this.type][event][this.id] != null){
var index = events[this.type][event][this.id].indexOf(callback);
if(index != -1){
events[this.type][event][this.id].splice(index, 1);
Ti.App.fireEvent("API_MAP_EDIT_EVENT", {action: "remove", event: event, elementId: this.id, elementType: this.type });
}
}
};
/**
* This class represents a map instance.
* @class
* @memberof Yaast.API.SW.Map
*/
var MapView = function MapView(id){
this.id = id;
this.type = "map";
/**
* Adds the map view to a view.
* @memberof Yaast.API.SW.Map.MapView
* @alias addBound
* @instance
* @public
* @param {object} Options Top, left, right, bottom, height, width.
*/
this.addBound = function(options){
_genericMethodHandler.call(this, voidCallback, 'API.SW.Map.addBound', [this.id, id], options);
};
/**
* Sets the bounds of the map view.
* @memberof Yaast.API.SW.Map.MapView
* @alias setBound
* @instance
* @public
* @param {string} viewId The id of the view.
* @param {object} Options Top, left, right, bottom, height, width.
*/
this.setBound = function(viewId, options){
_genericMethodHandler.call(this, voidCallback, 'API.SW.Map.setBound', [this.id, viewId], options);
};
/**
* Removes the map from the view that contains it.
* @memberof Yaast.API.SW.Map.MapView
* @alias removeBound
* @instance
* @public
*/
this.removeBound = function(){
_genericMethodHandler.call(this, voidCallback, 'API.SW.Map.removeBound', [this.id], null);
};
/**
* Zooms in or out by specifying a relative zoom level.
* @memberof Yaast.API.SW.Map.MapView
* @alias zoom
* @instance
* @public
* @param {Number} delta. A positive value increases the current zoom level and a negative value decreases the zoom level.
*/
this.zoom = function(delta){
_genericMethodHandler.call(this, voidCallback, 'API.SW.Map.getShapesFromGeoJson', [this.id, delta]);
};
/**
* Set how the map should follow the location of the device.
* @memberof Yaast.API.SW.Map.MapView
* @alias followLocation
* @instance
* @public
* @param {Boolean} followLocation True if the map camera must follow the location of the device.
* @param {Boolean} followBearing True if the map camera must follow the bearing of the device.
* @param {Object} options
* - interval: LocationRequest desired interval in milliseconds. Must be > 0; otherwise, default value is 1000.<br>
* - priority: LocationRequest priority ({@link Map.PRIORITY_BALANCED_POWER_ACCURACY}, {@link Map.PRIORITY_HIGH_ACCURACY},
* {@link Map.PRIORITY_LOW_POWER}, {@link Map.PRIORITY_NO_POWER}, {@link Map.PRIORITY_UNDEFINED}).
*/
this.followLocation = function(followLocation, followBearing, options){
_genericMethodHandler.call(this, voidCallback, 'API.SW.Map.followLocation', [this.id, followLocation, followBearing], options);
};
/**
* Gets the value of a property of the map.
* @memberof Yaast.API.SW.Map.MapView
* @alias getProperty
* @instance
* @public
* @param {String} propertyName String with the name of the property or array with a list of properties.
* @param {function} callback Callback function to invoke with the value of the property, or a hashmap of properties and values.
*/
this.getProperty = function(propertyName, callback){
var _callback = function(_res){
var _processProperty = function(_propValue){
var _newValue = null;
if(propertyName === "annotations")
return _convertToElementsArray(_propValue, 'annotation');
else if(propertyName === "polygons")
return _convertToElementsArray(_propValue, 'polygon');
else if(propertyName === "routes")
return _convertToElementsArray(_propValue, 'route');
else if(propertyName === "layers")
return _convertToElementsArray(_propValue, 'layer');
else
return _propValue;
};
if(propertyName instanceof Array){
var _newRes = {};
for(var _propName in _res){
var val = _processProperty(_res[_propName]);
if(typeof(val) !== 'undefined'){
_newRes[_propName] = val;
}
}
callback(_newRes);
} else {
callback(_processProperty(_res));
}
};
_genericMethodHandler.call(this, _callback, 'API.SW.Map.getMapProperty', [this.id, propertyName]);
};
/**
* Gets all the properties of the map.
* @memberof Yaast.API.SW.Map.MapView
* @alias getAllProperties
* @instance
* @public
* @param {function} callback Callback function to invoke with the hashmap of properties and values.
*/
this.getAllProperties = function(callback){
this.getProperty(["userLocation", "userLocationButton", "mapType", "region", "animate", "traffic", "enableZoomControls",
"rect", "region", "zoom", "annotations", "polygons", "layers", "routes"], callback);
};
/**
* Sets the value of a property of the map.
* @memberof Yaast.API.SW.Map.MapView
* @alias setProperty
* @instance
* @public
* @param {String} propertyName String with the name of the property.
* @param {*} propertyValue The value to be set for the property.
*/
this.setProperty = function(propertyName, propertyValue){
_genericMethodHandler.call(this, voidCallback, 'API.SW.Map.setMapProperty', [this.id, propertyName, propertyValue]);
};
/**
* Add an annotation to the map.
* @memberof Yaast.API.SW.Map.MapView
* @alias addAnnotation
* @instance
* @public
* @param {Object} annotation The Annotation object.
*/
this.addAnnotation = function(annotation){
_genericMethodHandler.call(this, voidCallback, 'API.SW.Map.addAnnotation', [this.id, annotation.id]);
};
/**
* Selects an annotation in the map.
* @memberof Yaast.API.SW.Map.MapView
* @alias selectAnnotation
* @instance
* @public
* @param {Object} annotation The Annotation object.
*/
this.selectAnnotation = function(annotation){
_genericMethodHandler.call(this, voidCallback, 'API.SW.Map.selectAnnotation', [this.id, annotation.id]);
};
/**
* Deselects an annotation in the map.
* @memberof Yaast.API.SW.Map.MapView
* @alias deselectAnnotation
* @instance
* @public
* @param {Object} annotation The Annotation object.
*/
this.deselectAnnotation = function(annotation){
_genericMethodHandler.call(this, voidCallback, 'API.SW.Map.deselectAnnotation', [this.id, annotation.id]);
};
/**
* Removes an annotation from the map.
* @memberof Yaast.API.SW.Map.MapView
* @alias removeAnnotation
* @instance
* @public
* @param {Object} annotation The Annotation object.
*/
this.removeAnnotation = function(annotation){
_genericMethodHandler.call(this, voidCallback, 'API.SW.Map.removeAnnotation', [this.id, annotation.id]);
};
/**
* Removes multiple annotations from the map.
* @memberof Yaast.API.SW.Map.MapView
* @alias removeAnnotations
* @instance
* @public
* @param {Object} annotation Array of Annotation objects.
*/
this.removeAnnotations = function(annotations){
var ids = [];
for(var i in annotations){
if(annotations[i].id != null)
ids.push(annotations[i].id);
}
_genericMethodHandler.call(this, voidCallback, 'API.SW.Map.removeAnnotations', [this.id, ids]);
};
/**
* Removes all the annotations from a map.
* @memberof Yaast.API.SW.Map.MapView
* @alias removeAllAnnotations
* @instance
* @public
*/
this.removeAllAnnotations = function(){
_genericMethodHandler.call(this, voidCallback, 'API.SW.Map.removeAllAnnotations', [this.id]);
};
/**
* Add a route to the map.
* @memberof Yaast.API.SW.Map.MapView
* @alias addRoute
* @instance
* @public
* @param {Object} route The Route object to add.
*/
this.addRoute = function(route){
_genericMethodHandler.call(this, voidCallback, 'API.SW.Map.addRoute', [this.id, route.id]);
};
/**
* Removes a route from the map.
* @memberof Yaast.API.SW.Map.MapView
* @alias removeRoute
* @instance
* @public
* @param {Object} route The Route object to add.
*/
this.removeRoute = function(route){
_genericMethodHandler.call(this, voidCallback, 'API.SW.Map.removeRoute', [this.id, route.id]);
};
/**
* Removes all the routes from the map.
* @memberof Yaast.API.SW.Map.MapView
* @alias removeAllRoutes
* @instance
* @public
*/
this.removeAllRoutes = function(){
_genericMethodHandler.call(this, voidCallback, 'API.SW.Map.removeAllRoutes', [this.id]);
};
/**
* Add a polygon to the map.
* @memberof Yaast.API.SW.Map.MapView
* @alias addPolygon
* @instance
* @public
* @param {Object} polygon The Polygon object.
*/
this.addPolygon = function(polygon){
_genericMethodHandler.call(this, voidCallback, 'API.SW.Map.addPolygon', [this.id, polygon.id]);
};
/**
* Removes a polygon from the map.
* @memberof Yaast.API.SW.Map.MapView
* @alias removePolygon
* @instance
* @public
* @param {Object} polygon The Polygon object.
*/
this.removePolygon = function(polygon){
_genericMethodHandler.call(this, voidCallback, 'API.SW.Map.removePolygon', [this.id, polygon.id]);
};
/**
* Removes all the polygons from the map.
* @memberof Yaast.API.SW.Map.MapView
* @alias removeAllPolygons
* @instance
* @public
*/
this.removeAllPolygons = function(){
_genericMethodHandler.call(this, voidCallback, 'API.SW.Map.removeAllPolygons', [this.id]);
};
/**
* Add a layer to the map.
* @memberof Yaast.API.SW.Map.MapView
* @alias addLayer
* @instance
* @public
* @param {Object} layer The Layer object.
*/
this.addLayer = function(layer){
_genericMethodHandler.call(this, voidCallback, 'API.SW.Map.addLayer', [this.id, layer.id]);
};
/**
* Removes a layer from the map.
* @memberof Yaast.API.SW.Map.MapView
* @alias removeLayer
* @instance
* @public
* @param {Object} layer The Layer object.