forked from benbahrenburg/benCoding.Map
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcircle_sample.js
More file actions
executable file
·131 lines (108 loc) · 3.79 KB
/
circle_sample.js
File metadata and controls
executable file
·131 lines (108 loc) · 3.79 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
129
var win = Titanium.UI.currentWindow;
var flexSpace = Ti.UI.createButton({ systemButton:Ti.UI.iPhone.SystemButton.FLEXIBLE_SPACE });
//We load our state data, this is a big file...
var meta = require('power_plants');
//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,
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 bAddPlants = Ti.UI.createButton({
title:'Add Plants', style:Ti.UI.iPhone.SystemButtonStyle.BORDERED
});
var bRemoveUSPlants = Ti.UI.createButton({
title:'Remove US Plants', style:Ti.UI.iPhone.SystemButtonStyle.BORDERED
});
var bClearMap = Ti.UI.createButton({
title:'Clear Map', style:Ti.UI.iPhone.SystemButtonStyle.BORDERED
});
bAddPlants.addEventListener('click',function() {
//Remove all circles so we are starting fresh
mapView.removeAllCircles();
//Remove all annotations so we are starting fresh
mapView.removeAllAnnotations();
var iLength = meta.powerPlantsList.length;
//Loop and add each plant
for (var iLoop=0;iLoop<iLength;iLoop++){
Ti.API.info("Adding Power Plant " + meta.powerPlantsList[iLoop].name);
//Add Yellow Zone
mapView.addCircle({
latitude:meta.powerPlantsList[iLoop].latitude,
longitude:meta.powerPlantsList[iLoop].longitude,
title:meta.powerPlantsList[iLoop].name,
tag:meta.powerPlantsList[iLoop].tag,
radius:80000,
color:'yellow'
});
//Add Red Zone
mapView.addCircle({
latitude:meta.powerPlantsList[iLoop].latitude,
longitude:meta.powerPlantsList[iLoop].longitude,
title:meta.powerPlantsList[iLoop].name,
tag:meta.powerPlantsList[iLoop].tag,
radius:16000,
color:'red'
});
//Add annotation
mapView.addAnnotation(Ti.Map.createAnnotation({
latitude:meta.powerPlantsList[iLoop].latitude,
longitude:meta.powerPlantsList[iLoop].longitude,
title:meta.powerPlantsList[iLoop].name,
tag:meta.powerPlantsList[iLoop].tag,
subtitle:meta.powerPlantsList[iLoop].country + '\nCapacity:' + meta.powerPlantsList[iLoop].capacity + ' MW',
pincolor:Ti.Map.ANNOTATION_PURPLE,
animate:true
}));
}
});
bRemoveUSPlants.addEventListener('click',function() {
var iLength = meta.powerPlantsList.length;
//Now we start looping...until we find circle data related to the US
for (var iLoop=0;iLoop<iLength;iLoop++){
if(meta.powerPlantsList[iLoop].country=="United States"){
Ti.API.info("Removing plant " + meta.powerPlantsList[iLoop].name);
//Remove all circles related to this title
mapView.removeCircle({tag:meta.powerPlantsList[iLoop].tag});
//Remove our annotation that is associated with this entry
mapView.removeAnnotation(meta.powerPlantsList[iLoop].name);
}
}
});
bClearMap.addEventListener('click',function() {
//Remove all circles
mapView.removeAllCircles();
//Remove all annotations
mapView.removeAllAnnotations();
});
win.setToolbar([bAddPlants,flexSpace,bRemoveUSPlants,flexSpace,bClearMap]);
setTimeout(function()
{
Ti.UI.createAlertDialog({
title:'Information',
message:"This demonstration shows how to use the MKCircle overlay with Titanium. Press the Add Plants button to circle each Nuclear Power Plant at a radius of 10 and 50 miles."
}).show();
},1000);