var win = Ti.UI.createWindow({
backgroundColor: '#fff'
});
var mapContainer = Ti.UI.createView({
bottom: 50
});
var addBtn = Ti.UI.createButton({
title: 'Add Annotations',
bottom: 0,
left: 20
});
var removeBtn = Ti.UI.createButton({
title: 'Remove Annotations',
bottom: 0,
left: 150
});
var clusters = [];
var points = [];
var Map = require('ti.map');
var map = Map.createView();
map.addEventListener('clusterstart', cluster);
function add(e) {
map.removeAnnotations(points);
map.removeAnnotations(clusters);
clusters = [];
points = [];
var lat = 29.951318;
var long = -90.080998;
for(var x = 0; x<200; x++ ){
var point = Map.createAnnotation({
clusterIdentifier: 'a',
latitude: parseFloat(lat),
longitude: parseFloat(long),
title: x,
subtitle: lat +' - '+long,
index: x,
});
points.push(point);
console.warn(lat +' - '+long);
lat = lat+parseFloat( (Math.random() * .1));
long = long+parseFloat( (Math.random() * .1));
}
console.log('ADD ANNOTATIONS');
map.addAnnotations(points);
}
function remove(){
map.removeAllAnnotations();
// $.map.removeAnnotations(points);
// $.map.removeAnnotations(clusters);
}
function cluster(e) {
Ti.API.info('clustering started');
var clusterAnnotation = Map.createAnnotation({
showAsMarker: true,
markerText: e.memberAnnotations.length.toString() + '+',
});
clusters.push(clusterAnnotation);
map.setClusterAnnotation({
annotation: clusterAnnotation,
memberAnnotations: e.memberAnnotations
});
}
addBtn.addEventListener('click', function(e) {
add();
});
removeBtn.addEventListener('click', function(e) {
remove();
});
mapContainer.add(map);
win.add(addBtn);
win.add(removeBtn);
win.add(mapContainer);
win.open();