Load GPS coordinates 1000 at a time instead of all at once.
This commit is contained in:
parent
e38f3f3bc7
commit
38362c15b8
@ -18,6 +18,8 @@
|
|||||||
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
class EXIF_GPS_Controller extends Controller {
|
class EXIF_GPS_Controller extends Controller {
|
||||||
|
public static $xml_records_limit = 1000;
|
||||||
|
|
||||||
public function item($item_id) {
|
public function item($item_id) {
|
||||||
// Make sure the context callback is set to album when linking to photos from map pages.
|
// Make sure the context callback is set to album when linking to photos from map pages.
|
||||||
$item = ORM::factory("item", $item_id);
|
$item = ORM::factory("item", $item_id);
|
||||||
@ -26,7 +28,7 @@ class EXIF_GPS_Controller extends Controller {
|
|||||||
url::redirect($item->abs_url());
|
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.
|
// 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.
|
// $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)
|
->where("items.owner_id", "=", $query_id)
|
||||||
->viewable()
|
->viewable()
|
||||||
->order_by("exif_coordinates.latitude", "ASC")
|
->order_by("exif_coordinates.latitude", "ASC")
|
||||||
->find_all();
|
->find_all(EXIF_GPS_Controller::$xml_records_limit, $offset);
|
||||||
} elseif ($query_type == "album") {
|
} elseif ($query_type == "album") {
|
||||||
$items = ORM::factory("item", $query_id)
|
$items = ORM::factory("item", $query_id)
|
||||||
->join("exif_coordinates", "items.id", "exif_coordinates.item_id")
|
->join("exif_coordinates", "items.id", "exif_coordinates.item_id")
|
||||||
->viewable()
|
->viewable()
|
||||||
->order_by("exif_coordinates.latitude", "ASC")
|
->order_by("exif_coordinates.latitude", "ASC")
|
||||||
->descendants();
|
->descendants(EXIF_GPS_Controller::$xml_records_limit, $offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
$v = new View("exif_gps_coordinates_xml.html");
|
$v = new View("exif_gps_coordinates_xml.html");
|
||||||
@ -67,14 +69,26 @@ class EXIF_GPS_Controller extends Controller {
|
|||||||
throw new Kohana_404_Exception();
|
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 = "";
|
$map_title = "";
|
||||||
|
$items_count = 0;
|
||||||
if ($map_type == "album") {
|
if ($map_type == "album") {
|
||||||
$curr_album = ORM::factory("item")->where("id", "=", $type_id)->find_all();
|
$curr_album = ORM::factory("item")->where("id", "=", $type_id)->find_all();
|
||||||
$map_title = $curr_album[0]->title;
|
$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") {
|
} elseif ($map_type == "user") {
|
||||||
$curr_user = ORM::factory("user")->where("id", "=", $type_id)->find_all();
|
$curr_user = ORM::factory("user")->where("id", "=", $type_id)->find_all();
|
||||||
$map_title = $curr_user[0]->full_name . "'s " . t("Photos");
|
$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.
|
// Set up breadcrumbs.
|
||||||
@ -105,6 +119,7 @@ class EXIF_GPS_Controller extends Controller {
|
|||||||
} else {
|
} else {
|
||||||
$template->content->title = t("Map of") . " " . $map_title;
|
$template->content->title = t("Map of") . " " . $map_title;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Figure out default map type.
|
// Figure out default map type.
|
||||||
$int_map_type = module::get_var("exif_gps", "largemap_maptype");
|
$int_map_type = module::get_var("exif_gps", "largemap_maptype");
|
||||||
if ($int_map_type == 0) $map_display_type = "ROADMAP";
|
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.
|
// These are used to set up the URL to the xml file.
|
||||||
$template->content->query_type = $map_type;
|
$template->content->query_type = $map_type;
|
||||||
$template->content->query_id = $type_id;
|
$template->content->query_id = $type_id;
|
||||||
|
$template->content->items_count = $items_count;
|
||||||
|
|
||||||
// Load in module preferences.
|
// Load in module preferences.
|
||||||
$template->content->google_map_key = module::get_var("exif_gps", "googlemap_api_key");
|
$template->content->google_map_key = module::get_var("exif_gps", "googlemap_api_key");
|
||||||
|
@ -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") == 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") == 2) $block->content->sidebar_map_type = "HYBRID";
|
||||||
if (module::get_var("exif_gps", "sidebar_maptype") == 3) $block->content->sidebar_map_type = "TERRAIN";
|
if (module::get_var("exif_gps", "sidebar_maptype") == 3) $block->content->sidebar_map_type = "TERRAIN";
|
||||||
|
$block->content->items_count = 1;
|
||||||
} else {
|
} else {
|
||||||
$block->content = new View("exif_gps_static_sidebar.html");
|
$block->content = new View("exif_gps_static_sidebar.html");
|
||||||
if (module::get_var("exif_gps", "sidebar_maptype") == 0) $block->content->sidebar_map_type = "roadmap";
|
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;
|
$block->content->longitude = $longitude;
|
||||||
} elseif (($theme->item()) && ($theme->item->is_album() && (module::get_var("exif_gps", "sidebar_mapformat") == 1))) {
|
} 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.
|
// 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")
|
->join("exif_coordinates", "items.id", "exif_coordinates.item_id")
|
||||||
->viewable()
|
->viewable()
|
||||||
->order_by("exif_coordinates.latitude", "ASC")
|
->order_by("exif_coordinates.latitude", "ASC")
|
||||||
->descendants(1);
|
->descendants_count();
|
||||||
if (count($items) > 0) {
|
if ($items_count > 0) {
|
||||||
$block = new Block();
|
$block = new Block();
|
||||||
$block->css_id = "g-exif-gps-location";
|
$block->css_id = "g-exif-gps-location";
|
||||||
$block->title = t("Location");
|
$block->title = t("Location");
|
||||||
@ -151,6 +152,7 @@ class exif_gps_block_Core {
|
|||||||
$block->content->album_id = $theme->item->id;
|
$block->content->album_id = $theme->item->id;
|
||||||
$block->content->latitude = 0;
|
$block->content->latitude = 0;
|
||||||
$block->content->longitude = 0;
|
$block->content->longitude = 0;
|
||||||
|
$block->content->items_count = $items_count;
|
||||||
$block->content->google_map_key = module::get_var("exif_gps", "googlemap_api_key");
|
$block->content->google_map_key = module::get_var("exif_gps", "googlemap_api_key");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -248,12 +248,13 @@ class exif_gps_event_Core {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If there's nothing to map, hide the map.
|
// If there's nothing to map, hide the map.
|
||||||
$items = ORM::factory("item")
|
$items_count = ORM::factory("item")
|
||||||
->join("exif_coordinates", "items.id", "exif_coordinates.item_id")
|
->join("exif_coordinates", "items.id", "exif_coordinates.item_id")
|
||||||
->where("items.owner_id", "=", $data->user->id)
|
->where("items.owner_id", "=", $data->user->id)
|
||||||
->viewable()
|
->viewable()
|
||||||
->find_all(1);
|
->order_by("exif_coordinates.latitude", "ASC")
|
||||||
if (count($items) == 0) {
|
->count_all();
|
||||||
|
if ($items_count == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -266,6 +267,7 @@ class exif_gps_event_Core {
|
|||||||
if ($int_map_type == 3) $map_type = "TERRAIN";
|
if ($int_map_type == 3) $map_type = "TERRAIN";
|
||||||
$v->map_type = $map_type;
|
$v->map_type = $map_type;
|
||||||
$v->user_id = $data->user->id;
|
$v->user_id = $data->user->id;
|
||||||
|
$v->items_count = $items_count;
|
||||||
$v->google_map_key = module::get_var("exif_gps", "googlemap_api_key");
|
$v->google_map_key = module::get_var("exif_gps", "googlemap_api_key");
|
||||||
$data->content[] = (object) array("title" => t("Photo Map"), "view" => $v);
|
$data->content[] = (object) array("title" => t("Photo Map"), "view" => $v);
|
||||||
}
|
}
|
||||||
|
@ -8,9 +8,6 @@
|
|||||||
print "google.load(\"maps\", \"3\", {other_params:\"sensor=false\"});";
|
print "google.load(\"maps\", \"3\", {other_params:\"sensor=false\"});";
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
||||||
var google_zoom_hack = false;
|
|
||||||
var map = null;
|
|
||||||
<?
|
<?
|
||||||
if (isset($album_id)) {
|
if (isset($album_id)) {
|
||||||
print " var album_id = " . $album_id . ";\n";
|
print " var album_id = " . $album_id . ";\n";
|
||||||
@ -19,14 +16,18 @@
|
|||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
var google_zoom_hack = false;
|
||||||
|
var map = null;
|
||||||
|
|
||||||
$.ajaxSetup({
|
$.ajaxSetup({
|
||||||
error: function(xhr, status, error) {
|
error: function(xhr, status, error) {
|
||||||
var status_text = document.getElementById('exif-gps-status');
|
$('p.exif-gps-status').html("<font size=\"4\" color=\"white\"><strong>An AJAX error occured: " +
|
||||||
status_text.innerHTML = "<font size=\"4\" color=\"white\"><strong>An AJAX error occured: " + status + "<br />\nError: " + error + "</strong></font>";
|
status + "<br />\nError: " + error + "</strong></font>");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function initialize() {
|
function initialize() {
|
||||||
|
// Set up some initial variables and make a new map.
|
||||||
var myLatlng = new google.maps.LatLng(<?=$latitude; ?>,<?=$longitude; ?>);
|
var myLatlng = new google.maps.LatLng(<?=$latitude; ?>,<?=$longitude; ?>);
|
||||||
var myOptions = {
|
var myOptions = {
|
||||||
zoom: 1,
|
zoom: 1,
|
||||||
@ -35,32 +36,25 @@
|
|||||||
}
|
}
|
||||||
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
|
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) {
|
if (album_id > 0) {
|
||||||
jQuery.get("<?=url::abs_site("exif_gps/xml/album/{$album_id}"); ?>", {}, function(data) {
|
// Retrieve the first batch of XML records.
|
||||||
jQuery(data).find("marker").each(function() {
|
// This function runs recursively until item_counter equals int_max_items.
|
||||||
var xmlmarker = jQuery(this);
|
// We're using recursion instead of a normal looping control, because normal
|
||||||
var latlng = new google.maps.LatLng(parseFloat(xmlmarker.attr("lat")),
|
// loops would prevent the web browser from responding until the loop is finished.
|
||||||
parseFloat(xmlmarker.attr("lng")));
|
get_xml();
|
||||||
|
|
||||||
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';
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
|
// Only display a single marker.
|
||||||
var latlng = new google.maps.LatLng(<?=$latitude; ?>,<?=$longitude; ?>);
|
var latlng = new google.maps.LatLng(<?=$latitude; ?>,<?=$longitude; ?>);
|
||||||
var marker = new google.maps.Marker({
|
var marker = new google.maps.Marker({
|
||||||
position: latlng,
|
position: latlng,
|
||||||
@ -70,6 +64,61 @@
|
|||||||
document.getElementById('over_map').style.display = 'none';
|
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("<font size=\"4\" color=\"white\"><strong><?= t("Loading..."); ?> " +
|
||||||
|
parseInt((item_counter / int_max_items) * 100) + "%</strong></font>" +
|
||||||
|
"<br /><br /><img src=\"<?= url::file("modules/exif_gps/images/exif_gps-loading-map-large.gif"); ?>\"" +
|
||||||
|
" style=\"vertical-align: middle;\"></img>");
|
||||||
|
|
||||||
|
// 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 (($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
|
// 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.
|
// level the first time it is changed, and adjust it if necessary.
|
||||||
@ -84,6 +133,23 @@
|
|||||||
<? endif ?>
|
<? 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);
|
google.setOnLoadCallback(initialize);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@ -95,7 +161,7 @@
|
|||||||
<div id="wrapper">
|
<div id="wrapper">
|
||||||
<div id="map_canvas" style="width:205px; height:214px"></div>
|
<div id="map_canvas" style="width:205px; height:214px"></div>
|
||||||
<div id="over_map" style="width:205px; height:214px">
|
<div id="over_map" style="width:205px; height:214px">
|
||||||
<p id="exif-gps-status" style="text-align: center; display: table-cell; vertical-align: middle; width:205px; height:214px">
|
<p id="exif-gps-status" class="exif-gps-status" style="text-align: center; display: table-cell; vertical-align: middle; width:205px; height:214px">
|
||||||
<font size="4" color="white"><strong><?= t("Loading..."); ?></strong></font><br /><br />
|
<font size="4" color="white"><strong><?= t("Loading..."); ?></strong></font><br /><br />
|
||||||
<img src="<?= url::file("modules/exif_gps/images/exif_gps-loading-map-large.gif"); ?>" style="vertical-align: middle;"></img>
|
<img src="<?= url::file("modules/exif_gps/images/exif_gps-loading-map-large.gif"); ?>" style="vertical-align: middle;"></img>
|
||||||
</p>
|
</p>
|
||||||
|
@ -15,12 +15,13 @@
|
|||||||
|
|
||||||
$.ajaxSetup({
|
$.ajaxSetup({
|
||||||
error: function(xhr, status, error) {
|
error: function(xhr, status, error) {
|
||||||
var status_text = document.getElementById('exif-gps-status');
|
$('p.exif-gps-status').html("<font size=\"6\" color=\"white\"><strong>An AJAX error occured: " +
|
||||||
status_text.innerHTML = "<font size=\"6\" color=\"white\"><strong>An AJAX error occured: " + status + "<br />\nError: " + error + "</strong></font>";
|
status + "<br />\nError: " + error + "</strong></font>");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function initialize() {
|
function initialize() {
|
||||||
|
// Set up some initial variables and make a new map.
|
||||||
var myLatlng = new google.maps.LatLng(0, 0);
|
var myLatlng = new google.maps.LatLng(0, 0);
|
||||||
var myOptions = {
|
var myOptions = {
|
||||||
zoom: 1,
|
zoom: 1,
|
||||||
@ -29,25 +30,53 @@
|
|||||||
}
|
}
|
||||||
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
|
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( );
|
||||||
|
|
||||||
|
// Initialize the infoWindow.
|
||||||
infoWindow = new google.maps.InfoWindow();
|
infoWindow = new google.maps.InfoWindow();
|
||||||
|
|
||||||
var map_markers = [];
|
// Set up some initial variables for looping through the coordinates in the xml files.
|
||||||
var str_marker_html = "";
|
var map_markers = []; // Array of all unique coordinates.
|
||||||
var current_latlng = null;
|
var str_marker_html = ""; // infoWindow HTML for the current set of 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.
|
||||||
|
|
||||||
jQuery.get("<?=url::abs_site("exif_gps/xml/{$query_type}/{$query_id}"); ?>", {}, function(data) {
|
// 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();
|
||||||
|
|
||||||
|
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/{$query_type}/{$query_id}/"); ?>/' + int_offset,
|
||||||
|
success: function(data) {
|
||||||
jQuery(data).find("marker").each(function() {
|
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 xmlmarker = jQuery(this);
|
||||||
var latlng = new google.maps.LatLng(parseFloat(xmlmarker.attr("lat")),
|
var latlng = new google.maps.LatLng(parseFloat(xmlmarker.attr("lat")),
|
||||||
parseFloat(xmlmarker.attr("lng")));
|
parseFloat(xmlmarker.attr("lng")));
|
||||||
|
|
||||||
|
// Group multiple records with the same lat and lng coordinates together into
|
||||||
|
// the same marker and info window.
|
||||||
if (!latlng.equals(current_latlng)) {
|
if (!latlng.equals(current_latlng)) {
|
||||||
|
// If the latest record has different coordinates then the previous record
|
||||||
|
// and this is not the first record (!=null) then set up the click function
|
||||||
|
// for the previous marker...
|
||||||
if (current_latlng != null) {
|
if (current_latlng != null) {
|
||||||
var fn = markerClickFunction(str_marker_html, current_latlng);
|
var fn = markerClickFunction(str_marker_html, current_latlng);
|
||||||
google.maps.event.addListener(map_markers[map_markers.length-1], 'click', fn);
|
google.maps.event.addListener(map_markers[map_markers.length-1], 'click', fn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ... then set up a new marker for this record.
|
||||||
current_latlng = latlng;
|
current_latlng = latlng;
|
||||||
str_marker_html = "";
|
str_marker_html = "";
|
||||||
glatlngbounds.extend(latlng);
|
glatlngbounds.extend(latlng);
|
||||||
@ -55,6 +84,7 @@
|
|||||||
map_markers.push(marker);
|
map_markers.push(marker);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Convert any XML escape characters in this record to regular text.
|
||||||
var str_thumb_html = String(xmlmarker.attr("thumb"));
|
var str_thumb_html = String(xmlmarker.attr("thumb"));
|
||||||
str_thumb_html = str_thumb_html.replace("<", "<");
|
str_thumb_html = str_thumb_html.replace("<", "<");
|
||||||
str_thumb_html = str_thumb_html.replace(">", ">");
|
str_thumb_html = str_thumb_html.replace(">", ">");
|
||||||
@ -62,21 +92,44 @@
|
|||||||
str_thumb_html = str_thumb_html.replace(""", "\"");
|
str_thumb_html = str_thumb_html.replace(""", "\"");
|
||||||
str_thumb_html = str_thumb_html.replace("&", "&");
|
str_thumb_html = str_thumb_html.replace("&", "&");
|
||||||
|
|
||||||
|
// Set up the HTML for this record and append it to the bottom of the info window.
|
||||||
str_thumb_html = "<div class=\"g-exif-gps-thumb\"><a href=\"" +
|
str_thumb_html = "<div class=\"g-exif-gps-thumb\"><a href=\"" +
|
||||||
String(xmlmarker.attr("url")) + "\">" + str_thumb_html + "</a></div>";
|
String(xmlmarker.attr("url")) + "\">" + str_thumb_html + "</a></div>";
|
||||||
str_marker_html += str_thumb_html;
|
str_marker_html += str_thumb_html;
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Display a status message telling the user what percentage of records have been processed.
|
||||||
|
$('p.exif-gps-status').html("<font size=\"6\" color=\"white\"><strong><?= t("Loading..."); ?> " +
|
||||||
|
parseInt((item_counter / int_max_items) * 100) + "%</strong></font>" +
|
||||||
|
"<br /><br /><img src=\"<?= url::file("modules/exif_gps/images/exif_gps-loading-map-large.gif"); ?>\"" +
|
||||||
|
" style=\"vertical-align: middle;\"></img>");
|
||||||
|
|
||||||
|
// 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 {
|
||||||
|
// Set up the click function for the last coordinate.
|
||||||
var fn = markerClickFunction(str_marker_html, current_latlng);
|
var fn = markerClickFunction(str_marker_html, current_latlng);
|
||||||
google.maps.event.addListener(map_markers[map_markers.length-1], 'click', fn);
|
google.maps.event.addListener(map_markers[map_markers.length-1], 'click', fn);
|
||||||
|
|
||||||
|
// 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 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);
|
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;
|
google_zoom_hack = true;
|
||||||
map.fitBounds(glatlngbounds);
|
map.fitBounds(glatlngbounds);
|
||||||
|
|
||||||
|
// Hide the loading message and exit.
|
||||||
document.getElementById('over_map').style.display = 'none';
|
document.getElementById('over_map').style.display = 'none';
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
<? if (($max_autozoom = module::get_var("exif_gps", "googlemap_max_autozoom")) != "") : ?>
|
<? 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
|
// If there is a maximum auto-zoom value, then set up an event to check the zoom
|
||||||
@ -92,6 +145,8 @@
|
|||||||
<? endif ?>
|
<? endif ?>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set up an info window at the specified coordinates
|
||||||
|
// to display the specified html.
|
||||||
markerClickFunction = function(str_thumb_html, latlng) {
|
markerClickFunction = function(str_thumb_html, latlng) {
|
||||||
return function(e) {
|
return function(e) {
|
||||||
e.cancelBubble = true;
|
e.cancelBubble = true;
|
||||||
@ -125,7 +180,7 @@
|
|||||||
<div id="wrapper">
|
<div id="wrapper">
|
||||||
<div id="map_canvas" style="width:690px; height:480px;"></div>
|
<div id="map_canvas" style="width:690px; height:480px;"></div>
|
||||||
<div id="over_map" style="width:690px; height:480px;">
|
<div id="over_map" style="width:690px; height:480px;">
|
||||||
<p id="exif-gps-status" style="text-align: center; display: table-cell; vertical-align: middle; width: 690px; height: 480px;">
|
<p id="exif-gps-status" class="exif-gps-status" style="text-align: center; display: table-cell; vertical-align: middle; width: 690px; height: 480px;">
|
||||||
<font size="6" color="white"><strong><?= t("Loading..."); ?></strong></font><br /><br />
|
<font size="6" color="white"><strong><?= t("Loading..."); ?></strong></font><br /><br />
|
||||||
<img src="<?= url::file("modules/exif_gps/images/exif_gps-loading-map-large.gif"); ?>" style="vertical-align: middle;"></img>
|
<img src="<?= url::file("modules/exif_gps/images/exif_gps-loading-map-large.gif"); ?>" style="vertical-align: middle;"></img>
|
||||||
</p>
|
</p>
|
||||||
|
@ -15,12 +15,13 @@
|
|||||||
|
|
||||||
$.ajaxSetup({
|
$.ajaxSetup({
|
||||||
error: function(xhr, status, error) {
|
error: function(xhr, status, error) {
|
||||||
var status_text = document.getElementById('exif-gps-status');
|
$('p.exif-gps-status').html("<font size=\"6\" color=\"white\"><strong>An AJAX error occured: " +
|
||||||
status_text.innerHTML = "<font size=\"6\" color=\"white\"><strong>An AJAX error occured: " + status + "<br />\nError: " + error + "</strong></font>";
|
status + "<br />\nError: " + error + "</strong></font>");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function initialize() {
|
function initialize() {
|
||||||
|
// Set up some initial variables and make a new map.
|
||||||
var myLatlng = new google.maps.LatLng(0, 0);
|
var myLatlng = new google.maps.LatLng(0, 0);
|
||||||
var myOptions = {
|
var myOptions = {
|
||||||
zoom: 1,
|
zoom: 1,
|
||||||
@ -29,25 +30,53 @@
|
|||||||
}
|
}
|
||||||
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
|
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( );
|
||||||
|
|
||||||
|
// Initialize the infoWindow.
|
||||||
infoWindow = new google.maps.InfoWindow();
|
infoWindow = new google.maps.InfoWindow();
|
||||||
|
|
||||||
var map_markers = [];
|
// Set up some initial variables for looping through the coordinates in the xml files.
|
||||||
var str_marker_html = "";
|
var map_markers = []; // Array of all unique coordinates.
|
||||||
var current_latlng = null;
|
var str_marker_html = ""; // infoWindow HTML for the current set of 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.
|
||||||
|
|
||||||
jQuery.get("<?=url::abs_site("exif_gps/xml/user/{$user_id}"); ?>", {}, function(data) {
|
// 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();
|
||||||
|
|
||||||
|
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/user/{$user_id}/"); ?>/' + int_offset,
|
||||||
|
success: function(data) {
|
||||||
jQuery(data).find("marker").each(function() {
|
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 xmlmarker = jQuery(this);
|
||||||
var latlng = new google.maps.LatLng(parseFloat(xmlmarker.attr("lat")),
|
var latlng = new google.maps.LatLng(parseFloat(xmlmarker.attr("lat")),
|
||||||
parseFloat(xmlmarker.attr("lng")));
|
parseFloat(xmlmarker.attr("lng")));
|
||||||
|
|
||||||
|
// Group multiple records with the same lat and lng coordinates together into
|
||||||
|
// the same marker and info window.
|
||||||
if (!latlng.equals(current_latlng)) {
|
if (!latlng.equals(current_latlng)) {
|
||||||
|
// If the latest record has different coordinates then the previous record
|
||||||
|
// and this is not the first record (!=null) then set up the click function
|
||||||
|
// for the previous marker...
|
||||||
if (current_latlng != null) {
|
if (current_latlng != null) {
|
||||||
var fn = markerClickFunction(str_marker_html, current_latlng);
|
var fn = markerClickFunction(str_marker_html, current_latlng);
|
||||||
google.maps.event.addListener(map_markers[map_markers.length-1], 'click', fn);
|
google.maps.event.addListener(map_markers[map_markers.length-1], 'click', fn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ... then set up a new marker for this record.
|
||||||
current_latlng = latlng;
|
current_latlng = latlng;
|
||||||
str_marker_html = "";
|
str_marker_html = "";
|
||||||
glatlngbounds.extend(latlng);
|
glatlngbounds.extend(latlng);
|
||||||
@ -55,6 +84,7 @@
|
|||||||
map_markers.push(marker);
|
map_markers.push(marker);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Convert any XML escape characters in this record to regular text.
|
||||||
var str_thumb_html = String(xmlmarker.attr("thumb"));
|
var str_thumb_html = String(xmlmarker.attr("thumb"));
|
||||||
str_thumb_html = str_thumb_html.replace("<", "<");
|
str_thumb_html = str_thumb_html.replace("<", "<");
|
||||||
str_thumb_html = str_thumb_html.replace(">", ">");
|
str_thumb_html = str_thumb_html.replace(">", ">");
|
||||||
@ -62,21 +92,44 @@
|
|||||||
str_thumb_html = str_thumb_html.replace(""", "\"");
|
str_thumb_html = str_thumb_html.replace(""", "\"");
|
||||||
str_thumb_html = str_thumb_html.replace("&", "&");
|
str_thumb_html = str_thumb_html.replace("&", "&");
|
||||||
|
|
||||||
|
// Set up the HTML for this record and append it to the bottom of the info window.
|
||||||
str_thumb_html = "<div class=\"g-exif-gps-thumb\"><a href=\"" +
|
str_thumb_html = "<div class=\"g-exif-gps-thumb\"><a href=\"" +
|
||||||
String(xmlmarker.attr("url")) + "\">" + str_thumb_html + "</a></div>";
|
String(xmlmarker.attr("url")) + "\">" + str_thumb_html + "</a></div>";
|
||||||
str_marker_html += str_thumb_html;
|
str_marker_html += str_thumb_html;
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Display a status message telling the user what percentage of records have been processed.
|
||||||
|
$('p.exif-gps-status').html("<font size=\"6\" color=\"white\"><strong><?= t("Loading..."); ?> " +
|
||||||
|
parseInt((item_counter / int_max_items) * 100) + "%</strong></font>" +
|
||||||
|
"<br /><br /><img src=\"<?= url::file("modules/exif_gps/images/exif_gps-loading-map-large.gif"); ?>\"" +
|
||||||
|
" style=\"vertical-align: middle;\"></img>");
|
||||||
|
|
||||||
|
// 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 {
|
||||||
|
// Set up the click function for the last coordinate.
|
||||||
var fn = markerClickFunction(str_marker_html, current_latlng);
|
var fn = markerClickFunction(str_marker_html, current_latlng);
|
||||||
google.maps.event.addListener(map_markers[map_markers.length-1], 'click', fn);
|
google.maps.event.addListener(map_markers[map_markers.length-1], 'click', fn);
|
||||||
|
|
||||||
|
// 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 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);
|
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;
|
google_zoom_hack = true;
|
||||||
map.fitBounds(glatlngbounds);
|
map.fitBounds(glatlngbounds);
|
||||||
|
|
||||||
|
// Hide the loading message and exit.
|
||||||
document.getElementById('over_map').style.display = 'none';
|
document.getElementById('over_map').style.display = 'none';
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
<? if (($max_autozoom = module::get_var("exif_gps", "googlemap_max_autozoom")) != "") : ?>
|
<? 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
|
// If there is a maximum auto-zoom value, then set up an event to check the zoom
|
||||||
@ -92,6 +145,8 @@
|
|||||||
<? endif ?>
|
<? endif ?>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set up an info window at the specified coordinates
|
||||||
|
// to display the specified html.
|
||||||
markerClickFunction = function(str_thumb_html, latlng) {
|
markerClickFunction = function(str_thumb_html, latlng) {
|
||||||
return function(e) {
|
return function(e) {
|
||||||
e.cancelBubble = true;
|
e.cancelBubble = true;
|
||||||
@ -118,7 +173,7 @@
|
|||||||
<div id="wrapper">
|
<div id="wrapper">
|
||||||
<div id="map_canvas" style="width:690px; height:480px;"></div>
|
<div id="map_canvas" style="width:690px; height:480px;"></div>
|
||||||
<div id="over_map" style="width:690px; height:480px;">
|
<div id="over_map" style="width:690px; height:480px;">
|
||||||
<p id="exif-gps-status" style="text-align: center; display: table-cell; vertical-align: middle; width: 690px; height: 480px;">
|
<p id="exif-gps-status" class="exif-gps-status" style="text-align: center; display: table-cell; vertical-align: middle; width: 690px; height: 480px;">
|
||||||
<font size="6" color="white"><strong><?= t("Loading..."); ?></strong></font><br /><br />
|
<font size="6" color="white"><strong><?= t("Loading..."); ?></strong></font><br /><br />
|
||||||
<img src="<?= url::file("modules/exif_gps/images/exif_gps-loading-map-large.gif"); ?>" style="vertical-align: middle;"></img>
|
<img src="<?= url::file("modules/exif_gps/images/exif_gps-loading-map-large.gif"); ?>" style="vertical-align: middle;"></img>
|
||||||
</p>
|
</p>
|
||||||
|
Reference in New Issue
Block a user