forked from benbahrenburg/benCoding.Map
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpolygon_sample.js
More file actions
executable file
·128 lines (101 loc) · 3.41 KB
/
polygon_sample.js
File metadata and controls
executable file
·128 lines (101 loc) · 3.41 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
var win = Titanium.UI.currentWindow;
//We load our state data, this is a big file...
var meta = require('poly_meta');
//Bring the module into the example
var map = require('bencoding.map');
var bClearMap = Ti.UI.createButton({
title:'Clear Map', style:Ti.UI.iPhone.SystemButtonStyle.BORDERED
});
win.setRightNavButton(bClearMap);
//Remove all polygons added
bClearMap.addEventListener('click', function(){
mapView.removeAllPolygons();
});
//Create mapView
//We support all of the same functions the native Ti.Map.View does
var mapView = map.createView({
mapType: Ti.Map.STANDARD_TYPE,
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 = Titanium.UI.iOS.createToolbar({
items:[bZoomIn,bZoomOut],
top:0,width:70,left:0, borderRadius:5,
borderTop:true, borderBottom:false, translucent:true
});
win.add(zoomControl);
var flexSpace = Ti.UI.createButton({ systemButton:Ti.UI.iPhone.SystemButton.FLEXIBLE_SPACE });
var bAddUK = Ti.UI.createButton({
title:'+ UK', style:Ti.UI.iPhone.SystemButtonStyle.BORDERED
});
var bRemoveUK = Ti.UI.createButton({
title:'- UK', style:Ti.UI.iPhone.SystemButtonStyle.BORDERED
});
bAddUK.addEventListener('click',function() {
var ukData = meta.ukPolygons();
var iLength = ukData.length; //Should be 50 unless something changed...
//Now we start looping...
for (var iLoop=0;iLoop<iLength;iLoop++){
mapView.addPolygon(ukData[iLoop]);
}
});
bRemoveUK.addEventListener('click',function() {
//UK is a multi part polygon
//But, since we use the title to delete the polygon
//We just need to pass in any part to remove the polygon from the map
var poly = { title:'United Kingdom' };
mapView.removePolygon(poly);
});
var bAddNY = Ti.UI.createButton({
title:'+ NY', style:Ti.UI.iPhone.SystemButtonStyle.BORDERED
});
bAddNY.addEventListener('click',function() {
var iLength = meta.statesPolygons.states.length; //Should be 50 unless something changed...
//Now we start looping...until we find NY
for (var iLoop=0;iLoop<iLength;iLoop++){
if(meta.statesPolygons.states[iLoop].title=='New York'){
mapView.addPolygon(meta.statesPolygons.states[iLoop]);
break;
}
}
});
var bRemoveNY = Ti.UI.createButton({
title:'- NY', style:Ti.UI.iPhone.SystemButtonStyle.BORDERED
});
bRemoveNY.addEventListener('click',function() {
//Provide title of the polygon to be deleted
var poly = { title:'New York' };
mapView.removePolygon(poly);
});
var bAddStates = Ti.UI.createButton({
title:'+ States', style:Ti.UI.iPhone.SystemButtonStyle.BORDERED
});
//Load each state as a polgyon
bAddStates.addEventListener('click', function(){
//This is just a demo, please don't try this in your production apps....
var iLength = meta.statesPolygons.states.length; //Should be 50 unless something changed...
//Now we start looping...
for (var iLoop=0;iLoop<iLength;iLoop++){
Ti.API.info("Adding State " + meta.statesPolygons.states[iLoop].title);
mapView.addPolygon(meta.statesPolygons.states[iLoop]);
}
});
var bottomToolbar = Ti.UI.iOS.createToolbar({
items:[bAddStates,bAddNY,bRemoveNY,bAddUK,bRemoveUK],
bottom:0
});
win.add(bottomToolbar);