-
Notifications
You must be signed in to change notification settings - Fork 1
/
API.Map.js
1737 lines (1436 loc) · 54.4 KB
/
API.Map.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
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.
*/
"use strict";
var Cache = function Cache(size) {
this._data = {};
this._maxSize = size;
this._nextElement = 0;
this.get = function(key) {
if (this._data[key] != null)
return this._data[key].value;
};
this.add = function(key, value) {
//If is full, remove the oldest
if (this._nextElement >= this._maxSize) {
var toBeRemoved = this._nextElement - this._maxSize;
for (var key in this._data) {
if (this._data[key].order == toBeRemoved) {
delete this._data[key];
break;
}
}
this._nextElement++;
}
this._data[key] = {
value : value,
order : this._nextElement
};
};
};
/**
* Map API.
* @class
* @memberof API
*/
var Map = ( function() {
var _self = {
Map : require('ti.map')
}, mapsId = 0, mapsList = {}, cache = new Cache(20);
var freeElements = {
"polygons" : {},
"layers" : {},
"routes" : {},
"annotations" : {}
};
//Start event listener for the bridge
var handlers = {};
var eventHandler = function(event, elementType, elementId, e) {
for (var key in e) {
if (e[key].getId != null) {
e[key] = e[key].getId();
}
}
Ti.App.fireEvent("API_MAP_EVENT", {
event : event,
elementId : elementId,
data : e,
elementType : elementType
});
};
Ti.App.addEventListener("API_MAP_EDIT_EVENT", function(data) {
//TODO: check events?
var element = getElement(data.elementType, data.elementId);
if (element == null)
return;
if (data.action === "add") {
if (handlers[data.elementId] == null || handlers[data.elementId][data.event] == null) {
if(handlers[data.elementId] == null){
handlers[data.elementId] = {};
}
handlers[data.elementId][data.event] = {
count : 1,
handler : eventHandler.bind(null, data.event, data.elementType, data.elementId)
};
element.addEventListener(data.event, handlers[data.elementId][data.event].handler);
} else
handlers[data.elementId][data.event].count++;
} else if (data.action === "remove") {
if (handlers[data.elementId] != null && handlers[data.elementId][data.event] != null) {
if (--handlers[data.elementId][data.event].count <= 0) {
element.removeEventListener(data.event, handlers[data.elementId][data.event].handler);
handlers[data.elementId][data.event].handler = null;
delete handlers[data.elementId][data.event];
var count = 0;
for(var a in handlers[data.elementId])
count++;
if(count === 0)
delete handlers[data.elementId];
}
}
}
});
/*
* ------------------------ PRIVATE UTILS -------------------------------
*/
var getSetProperty = function(elementType, elementId, propertyName, propertyValue) {
var element = getElement(elementType, elementId);
// Check if the element was found
if (element != null) {
//Capitalize the first letter
propertyName = propertyName.charAt(0).toUpperCase() + propertyName.slice(1);
if (propertyValue === undefined) {//Getter
// Check if the getter method exists
if (element["get" + propertyName] != null) {
//Call the getter
return element["get"+ propertyName]();
} else {
throw "Getter method not found";
}
} else {//Setter
// Check if the getter method exists
if (element["set" + propertyName] != null) {
//Call the setter
element["set"+ propertyName](propertyValue);
//If the value has not changed, an error happened
if(element["get"+ propertyName]() != propertyValue)
throw "Exception while setting value for " + propertyName;
} else {
throw "Setter method not found";
}
}
} else {
throw "Unknown Element Id (" + elementId + ")";
}
};
/**
* ElementType: map | annotation | layer | polygon | route
*/
var getElement = function(elementType, elementId) {
//If it is a map, it does not need search, just return it
if (elementType === "map")
return mapsList[elementId];
var element = null;
//First search in the cache
element = cache.get(elementId);
//If found, return it; otherwise, find it and add it to the cache
if (element != null)
return element;
// Search in the maps
for (var mapId in mapsList) {
if (elementType === "annotation") {
element = mapsList[mapId].getAnnotations()[elementId];
} else if (elementType === "layer") {
element = mapsList[mapId].getLayers()[elementId];
} else if (elementType === "polygon") {
element = mapsList[mapId].getPolygons()[elementId];
} else if (elementType === "route") {
element = mapsList[mapId].getRoutes()[elementId];
} else {
//TODO: Error Unknown element type
return;
}
if (element != null)
break;
}
// If not found, get it from the not added elements
if (element == null) {
if (elementType === "annotation") {
element = freeElements["annotations"][elementId];
} else if (elementType === "layer") {
element = freeElements["layers"][elementId];
} else if (elementType === "polygon") {
element = freeElements["polygons"][elementId];
} else if (elementType === "route") {
element = freeElements["routes"][elementId];
}
}
// If not found and is an annotation, search between the polygon annotations
if (element == null && elementType === "annotation") {
element = getAnnotationFromPolygons(elementId);
}
// Add it to the cache
if (element != null)
cache.add(elementId, element);
return element;
};
var getProperty = function(elementType, elementId, propertyName) {
getSetProperty(elementType, elementId, propertyName);
};
var setProperty = function(elementType, elementId, propertyName, propertyValue) {
getSetProperty(elementType, elementId, propertyName, propertyValue);
};
var getAnnotationFromPolygons = function(annoId) {
var annotation = null;
//Search now between the polygon annotations added to the maps
for (var mapId in mapsList) {
var polygons = mapsList[mapId].getPolygons();
for (var polyId in polygons) {
var poly = polygons[polyId];
if (poly.annotation != null && poly.annotation.getId() == annoId) {
return poly.annotation;
}
}
}
return annotation;
};
var handleParserResult = function(obj) {
if (obj == null)
return obj;
var result = {
"polygons" : [],
"routes" : [],
"annotations": []
};
for (var x in obj.polygons) {
var id = obj.polygons[x].getId();
freeElements["polygons"][id] = obj.polygons[x];
result.polygons.push(id);
}
for (var x in obj.routes) {
var id = obj.routes[x].getId();
freeElements["routes"][id] = obj.routes[x];
result.routes.push(id);
}
for (var x in obj.annotations) {
var id = obj.annotations[x].getId();
freeElements["annotations"][id] = obj.annotations[x];
result.annotations.push(id);
}
return result;
};
/*
* ------------------------ MAP -------------------------------
*/
/*
* 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 API.Map
* @alias PRIORITY_BALANCED_POWER_ACCURACY
*/
_self.PRIORITY_BALANCED_POWER_ACCURACY = _self.Map.PRIORITY_BALANCED_POWER_ACCURACY;
/**
* Request the most accurate locations available. This will return the finest location available.
* @constant
* @memberof API.Map
* @alias PRIORITY_HIGH_ACCURACY
*/
_self.PRIORITY_HIGH_ACCURACY = _self.Map.PRIORITY_HIGH_ACCURACY;
/**
* 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 API.Map
* @alias PRIORITY_LOW_POWER
*/
_self.PRIORITY_LOW_POWER = _self.Map.PRIORITY_LOW_POWER;
/**
* 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 API.Map
* @alias PRIORITY_NO_POWER
*/
_self.PRIORITY_NO_POWER = _self.Map.PRIORITY_NO_POWER;
/**
* Use the default accuracy.
* @constant
* @memberof API.Map
* @alias PRIORITY_UNDEFINED
*/
_self.PRIORITY_UNDEFINED = -1;
/**
* Normal layer.
* @constant
* @memberof API.Map
* @alias NORMAL_TYPE
*/
_self.NORMAL_TYPE = _self.Map.NORMAL_TYPE;
/**
* Terrain layer.
* @constant
* @memberof API.Map
* @alias TERRAIN_TYPE
*/
_self.TERRAIN_TYPE = _self.Map.TERRAIN_TYPE;
/**
* Satellite layer.
* @constant
* @memberof API.Map
* @alias SATELLITE_TYPE
*/
_self.SATELLITE_TYPE = _self.Map.SATELLITE_TYPE;
/**
* Hybrid layer.
* @constant
* @memberof API.Map
* @alias HYBRID_TYPE
*/
_self.HYBRID_TYPE = _self.Map.HYBRID_TYPE;
/**
* Predefined HUE azure color for the annotation.
* @constant
* @memberof API.Map
* @alias ANNOTATION_AZURE
*/
_self.ANNOTATION_AZURE = _self.Map.ANNOTATION_AZURE;
/**
* Predefined HUE blue color for the annotation.
* @constant
* @memberof API.Map
* @alias ANNOTATION_BLUE
*/
_self.ANNOTATION_BLUE = _self.Map.ANNOTATION_BLUE;
/**
* Predefined HUE cyan color for the annotation.
* @constant
* @memberof API.Map
* @alias ANNOTATION_CYAN
*/
_self.ANNOTATION_CYAN = _self.Map.ANNOTATION_CYAN;
/**
* Predefined HUE green color for the annotation.
* @constant
* @memberof API.Map
* @alias ANNOTATION_GREEN
*/
_self.ANNOTATION_GREEN = _self.Map.ANNOTATION_GREEN;
/**
* Predefined HUE magenta color for the annotation.
* @constant
* @memberof API.Map
* @alias ANNOTATION_MAGENTA
*/
_self.ANNOTATION_MAGENTA = _self.Map.ANNOTATION_MAGENTA;
/**
* Predefined HUE orange color for the annotation.
* @constant
* @memberof API.Map
* @alias ANNOTATION_ORANGE
*/
_self.ANNOTATION_ORANGE = _self.Map.ANNOTATION_ORANGE;
/**
* Predefined HUE red color for the annotation.
* @constant
* @memberof API.Map
* @alias ANNOTATION_RED
*/
_self.ANNOTATION_RED = _self.Map.ANNOTATION_RED;
/**
* Predefined HUE rose color for the annotation.
* @constant
* @memberof API.Map
* @alias ANNOTATION_ROSE
*/
_self.ANNOTATION_ROSE = _self.Map.ANNOTATION_ROSE;
/**
* Predefined HUE violet color for the annotation.
* @constant
* @memberof API.Map
* @alias ANNOTATION_VIOLET
*/
_self.ANNOTATION_VIOLET = _self.Map.ANNOTATION_VIOLET;
/**
* Predefined HUE yellow color for the annotation.
* @constant
* @memberof API.Map
* @alias ANNOTATION_YELLOW
*/
_self.ANNOTATION_YELLOW = _self.Map.ANNOTATION_YELLOW;
/**
* WMS 1.1.1 layer type.
* @constant
* @memberof API.Map
* @alias LAYER_TYPE_WMS_1_1_1
*/
_self.LAYER_TYPE_WMS_1_1_1 = _self.Map.LAYER_TYPE_WMS_1_1_1;
/**
* WMS 1.3.0 layer type.
* @constant
* @memberof API.Map
* @alias LAYER_TYPE_WMS_1_3_0
*/
_self.LAYER_TYPE_WMS_1_3_0 = _self.Map.LAYER_TYPE_WMS_1_3_0;
/**
* WMTS 1.0.0 layer type. Currently not supported.
* @constant
* @memberof API.Map
* @alias LAYER_TYPE_WMTS_1_0_0
*/
_self.LAYER_TYPE_WMTS_1_0_0 = _self.Map.LAYER_TYPE_WMTS_1_0_0;
/**
* PNG image format.
* @constant
* @memberof API.Map
* @alias FORMAT_PNG
*/
_self.FORMAT_PNG = _self.Map.FORMAT_PNG;
/**
* JPEG image format.
* @constant
* @memberof API.Map
* @alias FORMAT_JPEG
*/
_self.FORMAT_JPEG = _self.Map.FORMAT_JPEG;
/**
* Check if there is support for the map.
* @memberof API.Map
* @alias isMapAvailable
* @return {Boolean} True if it can be used.
*/
_self.isMapAvailable = function isMapAvailable(){
return _self.Map.isGooglePlayServicesAvailable() == 0; //0 for Android
};
/**
* Creates a new map view.
* @memberof API.Map
* @alias createMap
* @param {object} options See {@link http://docs.appcelerator.com/titanium/3.0/#!/api/Modules.Map.View}
* @return {string} Id of the Map to be used in the methods of this API.
*/
_self.createMap = function createMap(options) {
delete options.width;
delete options.height;
delete options.top;
delete options.left;
mapsId++;
mapsList[mapsId] = _self.Map.createView(options);
return mapsId;
};
/**
* Creates an Annotation.
* @memberof API.Map
* @alias createAnnotation
* @param {object} options See {@link http://docs.appcelerator.com/titanium/3.0/#!/api/Modules.Map.Annotation}
* @return {string} Id of the annotation to be used in the methods of this API.
*/
_self.createAnnotation = function createAnnotation(options) {
//If the ID is set, check that it does not exist
if (options.id != null) {
if (getElement("annotation", options.id) != null) {
Ti.API.info('[API.Map.createAnnotation] Annotation ID already in use(' + options.id + ')');
return;
}
} else
delete options.id;
var anon = _self.Map.createAnnotation(options);
var id = anon.getId();
freeElements["annotations"][id] = anon;
return id;
};
/**
* Creates a Route.
* @memberof API.Map
* @alias createRoute
* @param {object} options See {@link http://docs.appcelerator.com/titanium/3.0/#!/api/Modules.Map.Route}
* @return {string} Id of the route to be used in the methods of this API.
*/
_self.createRoute = function createRoute(options) {
//If the ID is set, check that it does not exist
if (options.id != null) {
if (getElement("route", options.id) != null) {
Ti.API.info('[API.Map.createRoute] Route ID already in use(' + options.id + ')');
return;
}
} else
delete options.id;
var route = _self.Map.createRoute(options);
var id = route.getId();
freeElements["routes"][id] = route;
return id;
};
/**
* Creates a Polygon.
* @memberof API.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: String Id of an Annotation.<br>
*
* @return {string} Id of the polygon to be used in the methods of this API.
*/
_self.createPolygon = function createPolygon(options) {
//If the ID is set, check that it does not exist
if (options.id != null) {
if (getElement("polygon", options.id) != null) {
Ti.API.info('[API.Map.createPolygon] Polygon ID already in use(' + options.id + ')');
return;
}
} else
delete options.id;
if(options.annotation != null){
var annotation = getElement("annotation", options.annotation);
if(annotation != null){
options.annotation = annotation;
}
}
var polygon = _self.Map.createPolygon(options);
var id = polygon.getId();
freeElements["polygons"][id] = polygon;
return id;
};
/**
* Creates a Layer.
* @memberof API.Map
* @alias createLayer
* @param {object} options
* - id: optional. Must be unique.<br>
* - baseUrl: String with the url of the service<br>
* - type: Type of service ({@link API.Map.LAYER_TYPE_WMS_1_1_1} | {@link API.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 API.Map.FORMAT_PNG} | {@link API.Map.FORMAT_JPEG})<br>
*
* @return {string} Id of the layer to be used in the methods of this API.
*/
_self.createLayer = function createLayer(options) {
//If the ID is set, check that it does not exist
if (options.id != null) {
if (getElement("layer", options.id) != null) {
Ti.API.info('[API.Map.createLayer] Layer ID already in use(' + options.id + ')');
return;
}
} else
delete options.id;
var layer = _self.Map.createLayer(options);
var id = layer.getId();
freeElements["layers"][id] = layer;
return id;
};
/**
* Parses a given KML file or string and returns an object with the polygons and routes of the file.
* @memberof API.Map
* @alias getShapesFromKml
* @param {(fileObj|string)} data The KML file or string to parse
* @return {object} An object {polygons: array, routes: array, annotations: array}. Null if there was an exception while parsing the KML file or string .
*/
_self.getShapesFromKml = function getShapesFromKml(data) {
return handleParserResult(_self.Map.getShapesFromKml(data));
};
/**
* Parses a given GeoJson file or string and returns an object with the polygons and routes of the file.
* @memberof API.Map
* @alias getShapesFromGeoJson
* @param {(fileObj|string)} data The GeoJson file or string to parse
* @return {object} An object {polygons: array, routes: array, annotations: array}. Null if there was an exception while parsing the GeoJson file or string .
*/
_self.getShapesFromGeoJson = function getShapesFromGeoJson(data) {
return handleParserResult(_self.Map.getShapesFromGeoJson(data));
};
/**
* Parses a given WKT file or string and returns an object with the polygons and routes of the file.
* @memberof API.Map
* @alias getShapesFromWkt
* @param {(fileObj|string)} data The WKT file or string to parse
* @return {object} An object {polygons: array, routes: array, annotations: array}. Null if there was an exception while parsing the WKT file or string .
*/
_self.getShapesFromWkt = function getShapesFromWkt(data) {
return handleParserResult(_self.Map.getShapesFromWkt(data));
};
/*
* ----------------------------------- MAP VIEW -----------------------------------------------------------------
*/
/**
* Adds the map view to a view.
* @memberof API.Map
* @alias addBound
* @param {string} mapId The id of the map.
* @param {string} viewId The id of the view.
* @param {object} options Top, left, right, bottom, height, width.
*/
_self.addBound = function addBound(mapId, viewId, options) {
if (mapsList[mapId] == null) {
//TODO: error. Unknown Video Player ID
Ti.API.info('[API.Map.setBound] Unknown Map id: ' + mapId);
return false;
}
Yaast.Sandbox.tabView.add(mapsList[mapsId]);
_self.setBound(mapId, viewId, options);
};
/**
* Sets the bounds of the map view.
* @memberof API.Map
* @alias setBound
* @param {string} mapIdThe id of the map.
* @param {string} viewId The id of the view.
* @param {object} options Top, left, right, bottom, height, width.
*/
_self.setBound = function setBound(mapId, viewId, options) {
if (mapsList[mapId] == null) {
//TODO: error. Unknown Video Player ID
Ti.API.info('[API.Map.setBound] Unknown Map id: ' + mapId);
return false;
}
if ( typeof options.width === 'undefined' || typeof options.height === 'undefined') {
options.width = parseInt(Yaast.Sandbox.tabView.rect.width * 0.7);
options.height = parseInt(Yaast.Sandbox.tabView.rect.height * 0.5);
options.top = 'undefined';
options.left = 'undefined';
} else {
// Position
if ( typeof options.top !== 'undefined' || typeof options.bottom !== 'undefined') {
if ( typeof options.bottom === 'undefined') {
options.top = parseInt(options.top + Yaast.Sandbox.componentPos[viewId].top);
} else {
options.top = parseInt(Yaast.Sandbox.componentPos[viewId].top + (Yaast.Sandbox.componentPos[viewId].height - options.bottom));
}
}
if ( typeof options.left !== 'undefined' || typeof options.right !== 'undefined') {
if ( typeof options.right === 'undefined') {
options.left = parseInt(options.left + Yaast.Sandbox.componentPos[viewId].left);
} else {
options.left = parseInt(Yaast.Sandbox.componentPos[viewId].left + (Yaast.Sandbox.componentPos[viewId].width - options.right));
}
}
}
mapsList[mapId].height = options.height;
mapsList[mapId].width = options.width;
mapsList[mapId].top = options.top;
mapsList[mapId].left = options.left;
return true;
};
/**
* Removes the map from the view that contains it
* @memberof API.Map
* @alias removeBound
* @param {string} mapId Map in which execute the action.
*/
_self.removeBound = function removeBound(mapId) {
Yaast.Sandbox.tabView.remove(mapsList[mapId]);
};
/**
* Zooms in or out by specifying a relative zoom level.
* @memberof API.Map
* @alias zoom
* @param {string} mapId Map in which execute the action.
* @param {number} delta A positive value increases the current zoom level and a negative value decreases the zoom level.
*/
_self.zoom = function zoom(mapId, delta) {
if ( typeof mapsList[mapId] === 'undefined') {
//TODO: Error Unknown Map Id
return;
}
mapsList[mapId].zoom(delta);
};
/**
* Set how the map should follow the location of the device.
* @memberof API.Map
* @alias followLocation
* @param {string} mapId Map
* @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 API.Map.PRIORITY_BALANCED_POWER_ACCURACY}, {@link API.Map.PRIORITY_HIGH_ACCURACY},
* {@link API.Map.PRIORITY_LOW_POWER}, {@link API.Map.PRIORITY_NO_POWER}, {@link API.Map.PRIORITY_UNDEFINED}).
*/
_self.followLocation = function followLocation(mapId, followLocation, followBearing, options) {
if ( typeof mapsList[mapId] === 'undefined') {
//TODO: Error Unknown Map Id
return;
}
var interval, priority;
if (options != null) {
interval = options.interval;
priority = options.priority;
}
if (interval == null)
interval = 1000;
if (priority == null)
priority = _self.PRIORITY_UNDEFINED;
mapsList[mapId].followLocation(interval, priority, followLocation, followBearing);
};
/**
* Gets the value of a property of the map.
* @memberof API.Map
* @alias getMapProperty
* @param {string} mapId The map.
* @param {string} propertyName String with the name of the property or array with a list of properties.
* @return {object} The value of the property or an object with the properties and values requested in the property list.
*/
_self.getMapProperty = function(mapId, propertyName) {
if(propertyName instanceof Array){
var result = {};
for(var x = 0; x < propertyName.length; x++){
var val = _self.getMapProperty(mapId, propertyName[x]);
if(typeof(val) !== 'undefined'){
result[propertyName[x]] = val;
}
}
return result;
} else {
var validProperties = ["userLocation", "userLocationButton", "mapType", "region", "animate", "traffic", "enableZoomControls", "rect", "region", "zoom"];
var onlyIdProperties = ["annotations", "polygons", "layers", "routes"];
if (validProperties.indexOf(propertyName) >= 0) {
return getSetProperty("map", mapId, propertyName);
} else if (onlyIdProperties.indexOf(propertyName) >= 0) {
var values = getSetProperty("map", mapId, propertyName);
var ids = [];
for (var id in values)
ids.push(id);
return ids;
} else {
Ti.API.info("[API.Map.getMapProperty] Error Getter method not found");
return;
}
}
};
/**
* Sets the value of a property of the map.
* @memberof API.Map
* @alias setMapProperty
* @param {string} mapId The map id.
* @param {string} propertyName String with the name of the property.
* @param {*} propertyValue The value to be set for the property.
*/
_self.setMapProperty = function(mapId, propertyName, propertyValue) {
var validProperties = ["userLocation", "userLocationButton", "mapType", "region", "animate", "traffic", "enableZoomControls", "rect"];
if (validProperties.indexOf(propertyName) >= 0) {
return getSetProperty("map", mapId, propertyName, propertyValue);
} else {
//TODO: Error Setter method not found
return;
}
};
/**
* Adds a view to the map view.
* @memberof API.Map
* @alias add
* @param {string} mapId The map id where the view should be added.
* @param {object} view View to be added.
*/
_self.add = function(mapId, view) {
if ( typeof mapsList[mapId] === 'undefined') {
//TODO: Error Unknown Map Id
return;
}
mapsList[mapId].add(view);
};
/**
* Removes a view from the map view.
* @memberof API.Map
* @alias remove
* @param {string} mapId The map id where the view should be remove.
* @param {object} view View to be removed.
*/
_self.remove = function(mapId, view) {
if ( typeof mapsList[mapId] === 'undefined') {
//TODO: Error Unknown Map Id
return;
}
mapsList[mapId].remove(view);
};
/**
* Adds the map view into another view.
* @memberof API.Map
* @alias addToView
* @param {string} mapId The map id whose view should be added to another.
* @param {object} view View to be added to.
*/
_self.addToView = function(mapId, view) {
if ( typeof mapsList[mapId] === 'undefined') {
//TODO: Error Unknown Map Id
return;
}
view.add(mapsList[mapId]);
};
/**
* Removes the map view from another view.
* @memberof API.Map
* @alias removeFromView
* @param {string} mapId The map id whose view should be removed from another one.
* @param {object} view View to be removed from.
*/
_self.removeFromView = function(mapId, view) {
if ( typeof mapsList[mapId] === 'undefined') {
//TODO: Error Unknown Map Id
return;
}
view.remove(mapsList[mapId]);
};
/**
* Adds the specified callback as an event listener for the named event.
* @memberof API.Map
* @alias addEventListener
* @param {string} mapId The map id.
* @param {string} event Name of the event.
* @param {function} func Callback function to invoke when the event is fired.
*/
_self.addEventListener = function(mapId, event, func) {
if ( typeof mapsList[mapId] === 'undefined') {
//TODO: Error Unknown Map Id
return;
}
mapsList[mapId].addEventListener(event, func);
};
/**
* Removes the specified callback as an event listener for the named event.
* Multiple listeners can be registered for the same event, so the callback parameter is used to determine which listener to remove.
* @memberof API.Map
* @alias removeEventListener
* @param {string} mapId The map id.
* @param {string} event Name of the event.
* @param {function} func Callback function to invoke when the event is fired.
*/
_self.removeEventListener = function(mapId, event, func) {
if ( typeof mapsList[mapId] === 'undefined') {
//TODO: Error Unknown Map Id
return;
}
mapsList[mapId].removeEventListener(event, func);
};
/*
* -------------------- ANNOTATIONS -------------------------------
*/
/**
* Add an annotation to a map.
* @memberof API.Map
* @alias addAnnotation
* @param {string} mapId The id of the map.
* @param {string} annotationId The id of the annotation.
*/
_self.addAnnotation = function addAnnotation(mapId, annonId) {
if ( typeof mapsList[mapId] === 'undefined') {
//TODO: Error Unknown Map Id
return;