diff --git a/3.0/modules/exif_gps/controllers/exif_gps.php b/3.0/modules/exif_gps/controllers/exif_gps.php
index 190a31ad..23ae186b 100644
--- a/3.0/modules/exif_gps/controllers/exif_gps.php
+++ b/3.0/modules/exif_gps/controllers/exif_gps.php
@@ -18,6 +18,8 @@
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class EXIF_GPS_Controller extends Controller {
+ public static $xml_records_limit = 1000;
+
public function item($item_id) {
// Make sure the context callback is set to album when linking to photos from map pages.
$item = ORM::factory("item", $item_id);
@@ -26,7 +28,7 @@ class EXIF_GPS_Controller extends Controller {
url::redirect($item->abs_url());
}
- public function xml($query_type, $query_id) {
+ public function xml($query_type, $query_id, $offset) {
// Generate an xml output of the photos to be mapped.
// $query_type can be either "album" or "user", $query_id is the id# of the album or user to map.
@@ -42,13 +44,13 @@ class EXIF_GPS_Controller extends Controller {
->where("items.owner_id", "=", $query_id)
->viewable()
->order_by("exif_coordinates.latitude", "ASC")
- ->find_all();
+ ->find_all(EXIF_GPS_Controller::$xml_records_limit, $offset);
} elseif ($query_type == "album") {
$items = ORM::factory("item", $query_id)
->join("exif_coordinates", "items.id", "exif_coordinates.item_id")
->viewable()
->order_by("exif_coordinates.latitude", "ASC")
- ->descendants();
+ ->descendants(EXIF_GPS_Controller::$xml_records_limit, $offset);
}
$v = new View("exif_gps_coordinates_xml.html");
@@ -67,14 +69,26 @@ class EXIF_GPS_Controller extends Controller {
throw new Kohana_404_Exception();
}
- // Figure out what to display for the page title.
+ // Figure out what to display for the page title and how many items to display.
$map_title = "";
+ $items_count = 0;
if ($map_type == "album") {
$curr_album = ORM::factory("item")->where("id", "=", $type_id)->find_all();
$map_title = $curr_album[0]->title;
+ $items_count = ORM::factory("item", $type_id)
+ ->join("exif_coordinates", "items.id", "exif_coordinates.item_id")
+ ->viewable()
+ ->order_by("exif_coordinates.latitude", "ASC")
+ ->descendants_count();
} elseif ($map_type == "user") {
$curr_user = ORM::factory("user")->where("id", "=", $type_id)->find_all();
$map_title = $curr_user[0]->full_name . "'s " . t("Photos");
+ $items_count = ORM::factory("item")
+ ->join("exif_coordinates", "items.id", "exif_coordinates.item_id")
+ ->where("items.owner_id", "=", $type_id)
+ ->viewable()
+ ->order_by("exif_coordinates.latitude", "ASC")
+ ->count_all();
}
// Set up breadcrumbs.
@@ -105,6 +119,7 @@ class EXIF_GPS_Controller extends Controller {
} else {
$template->content->title = t("Map of") . " " . $map_title;
}
+
// Figure out default map type.
$int_map_type = module::get_var("exif_gps", "largemap_maptype");
if ($int_map_type == 0) $map_display_type = "ROADMAP";
@@ -116,6 +131,7 @@ class EXIF_GPS_Controller extends Controller {
// These are used to set up the URL to the xml file.
$template->content->query_type = $map_type;
$template->content->query_id = $type_id;
+ $template->content->items_count = $items_count;
// Load in module preferences.
$template->content->google_map_key = module::get_var("exif_gps", "googlemap_api_key");
diff --git a/3.0/modules/exif_gps/helpers/exif_gps_block.php b/3.0/modules/exif_gps/helpers/exif_gps_block.php
index 6d03223a..7b44af34 100644
--- a/3.0/modules/exif_gps/helpers/exif_gps_block.php
+++ b/3.0/modules/exif_gps/helpers/exif_gps_block.php
@@ -123,6 +123,7 @@ class exif_gps_block_Core {
if (module::get_var("exif_gps", "sidebar_maptype") == 1) $block->content->sidebar_map_type = "SATELLITE";
if (module::get_var("exif_gps", "sidebar_maptype") == 2) $block->content->sidebar_map_type = "HYBRID";
if (module::get_var("exif_gps", "sidebar_maptype") == 3) $block->content->sidebar_map_type = "TERRAIN";
+ $block->content->items_count = 1;
} else {
$block->content = new View("exif_gps_static_sidebar.html");
if (module::get_var("exif_gps", "sidebar_maptype") == 0) $block->content->sidebar_map_type = "roadmap";
@@ -134,12 +135,12 @@ class exif_gps_block_Core {
$block->content->longitude = $longitude;
} elseif (($theme->item()) && ($theme->item->is_album() && (module::get_var("exif_gps", "sidebar_mapformat") == 1))) {
// If coordinates were NOT found, and this is an album with a dynamic map, then map the contents of the album.
- $items = ORM::factory("item", $theme->item->id)
+ $items_count = ORM::factory("item", $theme->item->id)
->join("exif_coordinates", "items.id", "exif_coordinates.item_id")
->viewable()
->order_by("exif_coordinates.latitude", "ASC")
- ->descendants(1);
- if (count($items) > 0) {
+ ->descendants_count();
+ if ($items_count > 0) {
$block = new Block();
$block->css_id = "g-exif-gps-location";
$block->title = t("Location");
@@ -151,6 +152,7 @@ class exif_gps_block_Core {
$block->content->album_id = $theme->item->id;
$block->content->latitude = 0;
$block->content->longitude = 0;
+ $block->content->items_count = $items_count;
$block->content->google_map_key = module::get_var("exif_gps", "googlemap_api_key");
}
}
diff --git a/3.0/modules/exif_gps/helpers/exif_gps_event.php b/3.0/modules/exif_gps/helpers/exif_gps_event.php
index 3b383203..1c19a941 100644
--- a/3.0/modules/exif_gps/helpers/exif_gps_event.php
+++ b/3.0/modules/exif_gps/helpers/exif_gps_event.php
@@ -191,7 +191,7 @@ class exif_gps_event_Core {
->css_id("g-exif-gps-user-link"));
}
}
-
+
static function album_menu($menu, $theme) {
// Adds album and user map icons to album pages.
@@ -248,12 +248,13 @@ class exif_gps_event_Core {
}
// If there's nothing to map, hide the map.
- $items = ORM::factory("item")
- ->join("exif_coordinates", "items.id", "exif_coordinates.item_id")
- ->where("items.owner_id", "=", $data->user->id)
- ->viewable()
- ->find_all(1);
- if (count($items) == 0) {
+ $items_count = ORM::factory("item")
+ ->join("exif_coordinates", "items.id", "exif_coordinates.item_id")
+ ->where("items.owner_id", "=", $data->user->id)
+ ->viewable()
+ ->order_by("exif_coordinates.latitude", "ASC")
+ ->count_all();
+ if ($items_count == 0) {
return;
}
@@ -266,6 +267,7 @@ class exif_gps_event_Core {
if ($int_map_type == 3) $map_type = "TERRAIN";
$v->map_type = $map_type;
$v->user_id = $data->user->id;
+ $v->items_count = $items_count;
$v->google_map_key = module::get_var("exif_gps", "googlemap_api_key");
$data->content[] = (object) array("title" => t("Photo Map"), "view" => $v);
}
diff --git a/3.0/modules/exif_gps/views/exif_gps_dynamic_sidebar.html.php b/3.0/modules/exif_gps/views/exif_gps_dynamic_sidebar.html.php
index 4f085919..d8465d4a 100644
--- a/3.0/modules/exif_gps/views/exif_gps_dynamic_sidebar.html.php
+++ b/3.0/modules/exif_gps/views/exif_gps_dynamic_sidebar.html.php
@@ -8,9 +8,6 @@
print "google.load(\"maps\", \"3\", {other_params:\"sensor=false\"});";
}
?>
-
- var google_zoom_hack = false;
- var map = null;
if (isset($album_id)) {
print " var album_id = " . $album_id . ";\n";
@@ -19,14 +16,18 @@
}
?>
+ var google_zoom_hack = false;
+ var map = null;
+
$.ajaxSetup({
error: function(xhr, status, error) {
- var status_text = document.getElementById('exif-gps-status');
- status_text.innerHTML = "An AJAX error occured: " + status + "
\nError: " + error + "";
+ $('p.exif-gps-status').html("An AJAX error occured: " +
+ status + "
\nError: " + error + "");
}
});
function initialize() {
+ // Set up some initial variables and make a new map.
var myLatlng = new google.maps.LatLng(=$latitude; ?>,=$longitude; ?>);
var myOptions = {
zoom: 1,
@@ -35,32 +36,25 @@
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
- var glatlngbounds = new google.maps.LatLngBounds( ); // This is so we can auto center the map.
+ // This is so we can auto-center and zoom the map.
+ // We will grow this each time a new set of coordinates is added onto the map
+ var glatlngbounds = new google.maps.LatLngBounds( );
+
+ // Set up some initial variables for looping through the coordinates in the xml files.
+ var map_markers = []; // Array of all unique coordinates.
+ var current_latlng = null; // Current coordinates. Used for merging duplicate coordinates together.
+ var item_counter = 0; // Current number of XML records that have been processed.
+ var int_max_items = = $items_count; ?>; // Total number of XML records to process.
+ var int_offset = 0; // Number of XML records to skip. Sent as a URL parameter when retrieving XML data.
- var map_markers = [];
- var current_latlng = null;
if (album_id > 0) {
- jQuery.get("=url::abs_site("exif_gps/xml/album/{$album_id}"); ?>", {}, function(data) {
- jQuery(data).find("marker").each(function() {
- var xmlmarker = jQuery(this);
- var latlng = new google.maps.LatLng(parseFloat(xmlmarker.attr("lat")),
- parseFloat(xmlmarker.attr("lng")));
-
- if (!latlng.equals(current_latlng)) {
- current_latlng = latlng;
- glatlngbounds.extend(latlng);
- var marker = new google.maps.Marker({position: latlng});
- map_markers.push(marker);
- }
- });
-
- var mcOptions = { gridSize: = module::get_var("exif_gps", "markercluster_gridsize"); ?>, maxZoom: = module::get_var("exif_gps", "markercluster_maxzoom"); ?>};
- var markerCluster = new MarkerClusterer(map, map_markers, mcOptions);
- google_zoom_hack = true;
- map.fitBounds(glatlngbounds);
- document.getElementById('over_map').style.display = 'none';
- });
+ // Retrieve the first batch of XML records.
+ // This function runs recursively until item_counter equals int_max_items.
+ // We're using recursion instead of a normal looping control, because normal
+ // loops would prevent the web browser from responding until the loop is finished.
+ get_xml();
} else {
+ // Only display a single marker.
var latlng = new google.maps.LatLng(=$latitude; ?>,=$longitude; ?>);
var marker = new google.maps.Marker({
position: latlng,
@@ -70,6 +64,61 @@
document.getElementById('over_map').style.display = 'none';
}
+ function get_xml() {
+ // This function uses ajax requests to download and process a chunck of records, in XML format.
+ jQuery.ajax({
+ url: '=url::abs_site("exif_gps/xml/album/{$album_id}/"); ?>/' + int_offset,
+ success: function(data) {
+ jQuery(data).find("marker").each(function() {
+ // Loop through the retrieved records and add each one to the map.
+
+ // Process the current record.
+ item_counter++;
+ var xmlmarker = jQuery(this);
+ var latlng = new google.maps.LatLng(parseFloat(xmlmarker.attr("lat")),
+ parseFloat(xmlmarker.attr("lng")));
+
+ // Group multiple records with the same lat and lng coordinates together into
+ // the same marker.
+ if (!latlng.equals(current_latlng)) {
+
+ // ... then set up a new marker for this record.
+ current_latlng = latlng;
+ glatlngbounds.extend(latlng);
+ var marker = new google.maps.Marker({position: latlng});
+ map_markers.push(marker);
+ }
+ });
+
+ // Display a status message telling the user what percentage of records have been processed.
+ $('p.exif-gps-status').html("= t("Loading..."); ?> " +
+ parseInt((item_counter / int_max_items) * 100) + "%" +
+ "
\"" +
+ " style=\"vertical-align: middle;\">");
+
+ // If item counter is less then max items, get the next batch of records.
+ // If item counter is equal to max items, then finish setting up the map and exit.
+ if (item_counter < int_max_items) {
+ int_offset += = EXIF_GPS_Controller::$xml_records_limit; ?>;
+ get_xml();
+ } else {
+ // Add the coordinates to the map, grouping clusters of similar coordinates together.
+ var mcOptions = { gridSize: = module::get_var("exif_gps", "markercluster_gridsize"); ?>, maxZoom: = module::get_var("exif_gps", "markercluster_maxzoom"); ?>};
+ var markerCluster = new MarkerClusterer(map, map_markers, mcOptions);
+
+ // Auto zoom and center the map around the coordinates.
+ // Set google_zoom_hack to true, to when the zoom changed function triggers
+ // we can re-zoom to the admin specified auto-zoom value, if necessary.
+ google_zoom_hack = true;
+ map.fitBounds(glatlngbounds);
+
+ // Hide the loading message and exit.
+ document.getElementById('over_map').style.display = 'none';
+ }
+ }
+ });
+ }
+
if (($max_autozoom = module::get_var("exif_gps", "googlemap_max_autozoom")) != "") : ?>
// If there is a maximum auto-zoom value, then set up an event to check the zoom
// level the first time it is changed, and adjust it if necessary.
@@ -84,6 +133,23 @@
endif ?>
}
+ // Set up an info window at the specified coordinates
+ // to display the specified html.
+ markerClickFunction = function(str_thumb_html, latlng) {
+ return function(e) {
+ e.cancelBubble = true;
+ e.returnValue = false;
+ if (e.stopPropagation) {
+ e.stopPropagation();
+ e.preventDefault();
+ }
+
+ infoWindow.setContent(str_thumb_html);
+ infoWindow.setPosition(latlng);
+ infoWindow.open(map);
+ };
+ };
+
google.setOnLoadCallback(initialize);
@@ -95,7 +161,7 @@
+
= t("Loading..."); ?>
" style="vertical-align: middle;">
+
= t("Loading..."); ?>
" style="vertical-align: middle;">
+
= t("Loading..."); ?>
" style="vertical-align: middle;">