forked from benbahrenburg/benCoding.Map
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtile_overlay_sample.js
More file actions
112 lines (90 loc) · 2.71 KB
/
tile_overlay_sample.js
File metadata and controls
112 lines (90 loc) · 2.71 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
var win = Titanium.UI.currentWindow;
var flexSpace = Ti.UI.createButton({ systemButton:Ti.UI.iPhone.SystemButton.FLEXIBLE_SPACE });
//Bring the module into the example
var map = require('bencoding.map');
//Create mapView
//We support all of the same functions the native Ti.Map.View does
var mapView = map.createView({
mapType: Ti.Map.STANDARD_TYPE,
region: {
latitude : -37.819955,
longitude : 144.983397,
latitudeDelta : 0.005,
longitudeDelta : 0.005
},
animate:true,
userLocation:true
});
//Add to Window
win.add(mapView);
var bZoomIn = Ti.UI.createButton({
title:'+', style:Ti.UI.iPhone.SystemButtonStyle.BORDERED
});
var bZoomOut = Ti.UI.createButton({
title:'-', style:Ti.UI.iPhone.SystemButtonStyle.BORDERED
});
bZoomIn.addEventListener('click',function() {
mapView.zoom(1);
});
bZoomOut.addEventListener('click',function() {
mapView.zoom(-1);
});
var zoomControl = Ti.UI.iOS.createToolbar({
items:[bZoomIn,bZoomOut],
top:0,width:Ti.UI.FILL
});
win.add(zoomControl);
var levels = ["1", "2" , "3" , "4"];
var currentLevel = 0;
var bShowTile = Ti.UI.createButton({
title:'Level+', style:Ti.UI.iPhone.SystemButtonStyle.BORDERED
});
bShowTile.addEventListener('click',function() {
currentLevel++;
if( currentLevel == levels.length){
currentLevel = 0;
}
//Remove in case they already exist
mapView.removeTileOverlayDirectory({tag:currentLevel});
mapView.addTileOverlayDirectory({
tag:currentLevel,
directory:'/tiles/Level' + levels[currentLevel]
});
});
var bHideTile = Ti.UI.createButton({
title:'Hide', style:Ti.UI.iPhone.SystemButtonStyle.BORDERED
});
bHideTile.addEventListener('click',function() {
mapView.removeAllAnnotations();
mapView.removeAllTileOverlayDirectory();
});
var bShowAnnotations = Ti.UI.createButton({
title:'Show Pins', style:Ti.UI.iPhone.SystemButtonStyle.BORDERED
});
bShowAnnotations.addEventListener('click',function() {
var points = [
{ latitude : -37.818891,
longitude : 144.983343 },
{ latitude : -37.818717,
longitude : 144.983515 },
{ latitude : -37.818925,
longitude : 144.983665 }];
var annotations = [];
for( var i = 0; i < points.length; i++ ){
annotations.push( Ti.Map.createAnnotation(points[i]));
}
mapView.setAnnotations( annotations );
});
var bHideAnnotations = Ti.UI.createButton({
title:'Hide Pins', style:Ti.UI.iPhone.SystemButtonStyle.BORDERED
});
bHideAnnotations.addEventListener('click',function() {
mapView.removeAllAnnotations();
});
win.addEventListener('open', function(){
mapView.addTileOverlayDirectory({
tag:currentLevel,
directory:'/tiles/Level' + levels[currentLevel]
});
});
win.setToolbar([bShowTile, bHideTile, bShowAnnotations, bHideAnnotations]);