Skip to content
This repository has been archived by the owner on Jul 5, 2018. It is now read-only.

update map with monuments as user explores (bug 38346) #64

Merged
merged 1 commit into from
Jul 24, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 31 additions & 8 deletions assets/www/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,23 +197,46 @@ require( [ 'jquery', 'l10n', 'geo', 'api', 'templates', 'monument',
$("#monuments-list").show();
}

function showMonumentsMap(monuments, center, zoom) {
geo.init();
function showMonumentsMap( monumentList, center, zoom ) {
var searchTimeout, lastRequest;
function addMonuments( monuments ) {
$.each( monuments, function( i, monument ) {
if ( monument.lat && monument.lon ) {
geo.addMonument( monument, showMonumentDetail );
}
} );
}
function ping( ev ) {
console.log( 'update map with new monuments' );
var pos = ev.target.getBounds(),
nw = pos.getNorthWest(),
se = pos.getSouthEast();
if( lastRequest ) {
lastRequest.abort();
}
window.clearTimeout( searchTimeout );
searchTimeout = window.setTimeout( function() {
lastRequest = monuments.getInBoundingBox( nw.lng, se.lat, se.lng, nw.lat ).done( function( monuments ) {
if ( monuments.length > 0 ) {
geo.clear();
addMonuments( monuments );
$( '#results' ).data( 'monuments', monuments );
}
}, 500 ); // delaying search to prevent stressing out server
} );
}
geo.init( ping );
geo.clear();
if( mapFocusNeeded && typeof center === 'undefined' && typeof zoom === 'undefined' ) {
var centerAndZoom = geo.calculateCenterAndZoom(monuments);
var centerAndZoom = geo.calculateCenterAndZoom( monumentList );
center = centerAndZoom.center;
zoom = centerAndZoom.zoom;
mapFocusNeeded = false;
}
if( center && zoom ) {
geo.setCenterAndZoom( center, zoom );
}
$.each(monuments, function(i, monument) {
if(monument.lat && monument.lon) {
geo.addMonument(monument, showMonumentDetail);
}
});
addMonuments( monumentList );
}

function displayError( heading, text ) {
Expand Down
6 changes: 5 additions & 1 deletion assets/www/js/geo.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ define(['jquery', '../leaflet/leaflet-src', 'leafclusterer'], function() {
return location;
}

function init() {
function init( onmapchange ) {
if (!map) {
// Disable webkit 3d CSS transformations for tile positioning
// Causes lots of flicker in PhoneGap for some reason...
Expand Down Expand Up @@ -87,6 +87,10 @@ define(['jquery', '../leaflet/leaflet-src', 'leafclusterer'], function() {
// Since clusterer needs to have a default view setup
map.setView( new L.LatLng( 0, 0 ), 3 );
clusterer = new LeafClusterer(map);

if ( onmapchange ) {
map.on( 'moveend', onmapchange );
}
}
}

Expand Down