Created
October 20, 2011 11:40
-
-
Save mchristie/1300940 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
z.returnCollectionsMapAnnotations = function(args) { | |
var data = []; | |
var collections = args.collections; | |
// Make sure these will be higher / lower than any actual lat / lngs | |
max_lat = -999; | |
max_lng = -999; | |
min_lat = 9999; | |
min_lng = 9999; | |
for (c = 0; c < collections.length; c++) | |
{ | |
if ((collections[c].lat && collections[c]['long']) || | |
(collections[c].properties.lat && collections[c].properties['long'])) | |
{ | |
var marker = Ti.Map.createAnnotation({ | |
latitude: z.showPublicCollections ? collections[c].lat : collections[c].properties.lat, | |
longitude: z.showPublicCollections ? collections[c]['long'] : collections[c].properties['long'], | |
title: collections[c].title, | |
pincolor: Titanium.Map.ANNOTATION_RED, | |
animate: true, | |
slug: collections[c].slug, | |
username: collections[c].username, | |
rightButton: Titanium.UI.iPhone.SystemButton.DISCLOSURE | |
}); | |
data.push(marker); | |
if (z.showPublicCollections) | |
{ | |
if (parseFloat(collections[c].lat) > max_lat) { max_lat = parseFloat(collections[c].lat); } | |
if (parseFloat(collections[c].lat) < min_lat) { min_lat = parseFloat(collections[c].lat); } | |
if (parseFloat(collections[c]['long']) > max_lng) { max_lng = parseFloat(collections[c]['long']); } | |
if (parseFloat(collections[c]['long']) < min_lng) { min_lng = parseFloat(collections[c]['long']); } | |
} | |
else | |
{ | |
if (parseFloat(collections[c].properties.lat) > max_lat) | |
{ max_lat = parseFloat(collections[c].properties.lat); } | |
if (parseFloat(collections[c].properties.lat) < min_lat) | |
{ min_lat = parseFloat(collections[c].properties.lat); } | |
if (parseFloat(collections[c].properties['long']) > max_lng) | |
{ max_lng = parseFloat(collections[c].properties['long']); } | |
if (parseFloat(collections[c].properties['long']) < min_lng) | |
{ min_lng = parseFloat(collections[c].properties['long']); } | |
} | |
} | |
} | |
// If we got no markers, we'll need to fallback to a useful location | |
if (data.length == 0 && z.location.avaialble) | |
{ | |
max_lat = parseFloat(z.location.lat); | |
max_lng = parseFloat(z.location.lng); | |
min_lat = parseFloat(z.location.lat); | |
min_lng = parseFloat(z.location.lng); | |
} | |
else if (data.length == 0) | |
{ | |
max_lat = 90; | |
max_lng = 180; | |
min_lat = -90; | |
min_lng = -180; | |
} | |
z.mapCenterLat = parseFloat((max_lat - min_lat) / 2 + min_lat); | |
z.mapCenterLng = parseFloat((max_lng - min_lng) / 2 + min_lng); | |
z.mapDeltaLat = (max_lat - min_lat) + 0.03; | |
z.mapDeltaLng = (max_lng - min_lng) + 0.03; | |
//Ti.API.info('z.mapCenterLat: '+z.mapCenterLat+', z.mapCenterLng: '+z.mapCenterLng); | |
Ti.API.info('z.mapCenterLat: '+z.mapCenterLat+', z.mapCenterLng: '+z.mapCenterLng); | |
return data; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment