work-in-progress - committing to switch to other work

This commit is contained in:
Jon Atkins 2013-08-27 21:04:28 +01:00
parent 81d0cb0ed8
commit 571a17d84b
6 changed files with 101 additions and 74 deletions

View File

@ -193,14 +193,15 @@ window.setupMap = function() {
window.addResumeFunction(function() { window.startRefreshTimeout(ON_MOVE_REFRESH*1000); });
// create the map data requester
window.mapDataRequest = new MapDataRequest();
window.mapDataRequest.start();
// start the refresh process with a small timeout, so the first data request happens quickly
// (the code originally called the request function directly, and triggered a normal delay for the nxt refresh.
// however, the moveend/zoomend gets triggered on map load, causing a duplicate refresh. this helps prevent that
window.startRefreshTimeout(ON_MOVE_REFRESH*1000);
// create the map data requester
window.mapDataRequest = new MapDataRequest();
window.mapDataRequest.start();
};
//adds a base layer to the map. done separately from the above, so that plugins that add base layers can be the default
@ -478,7 +479,7 @@ function boot() {
try {
ref();
} catch(err) {
console.log("error starting plugin: index "+ind+", error: "+err);
console.error("error starting plugin: index "+ind+", error: "+err);
}
});
@ -488,7 +489,7 @@ function boot() {
window.runOnSmartphonesAfterBoot();
// workaround for #129. Not sure why this is required.
setTimeout('window.map.invalidateSize(false);', 500);
// setTimeout('window.map.invalidateSize(false);', 500);
window.iitcLoaded = true;
window.runHooks('iitcLoaded');

View File

@ -15,6 +15,8 @@
// required to successfully boot the plugin.
//
// Heres more specific information about each event:
// mapDataRefreshStart: called when we start refreshing map data
// mapDataRefreshEnd: called when we complete the map data load
// portalAdded: called when a portal has been received and is about to
// be added to its layer group. Note that this does NOT
// mean it is already visible or will be, shortly after.
@ -47,8 +49,10 @@
window._hooks = {}
window.VALID_HOOKS = ['portalAdded', 'portalDetailsUpdated',
'publicChatDataAvailable', 'factionChatDataAvailable', 'portalDataLoaded',
window.VALID_HOOKS = [
'mapDataRefreshStart', 'mapDataRefreshEnd',
'portalAdded', 'portalDetailsUpdated',
'publicChatDataAvailable', 'factionChatDataAvailable',
'requestFinished', 'nicknameClicked',
'geoSearch', 'iitcLoaded'];

View File

@ -69,6 +69,12 @@ window.MapDataRequest.prototype.clearQueue = function() {
}
window.MapDataRequest.prototype.getStatus = function() {
return { short: 'blah', long: 'blah blah blah' };
};
window.MapDataRequest.prototype.refresh = function() {
this.cache.expire();
@ -78,19 +84,21 @@ window.MapDataRequest.prototype.refresh = function() {
// a 'set' to keep track of hard failures for tiles
this.tileErrorCount = {};
// fill tileBounds with the data needed to request each tile
this.tileBounds = {};
var bounds = clampLatLngBounds(map.getBounds());
var zoom = getPortalDataZoom();
var minPortalLevel = getMinPortalLevelForZoom(zoom);
window.runHooks ('mapDataRefreshStart', {bounds: bounds, zoom: zoom});
this.render.startRenderPass(bounds);
this.render.clearPortalsBelowLevel(minPortalLevel);
console.log('requesting data tiles at zoom '+zoom+' (L'+minPortalLevel+'+ portals), map zoom is '+map.getZoom());
// fill tileBounds with the data needed to request each tile
this.tileBounds = {};
var x1 = lngToTile(bounds.getWest(), zoom);
var x2 = lngToTile(bounds.getEast(), zoom);
@ -143,6 +151,8 @@ window.MapDataRequest.prototype.processRequestQueue = function(isFirstPass) {
console.log("finished requesting data!");
window.runHooks ('mapDataRefreshEnd', {});
if (!window.isIdle()) {
this.refreshOnTimeout(this.REFRESH);
} else {

View File

@ -41,58 +41,6 @@ window.requests.abort = function() {
renderUpdateStatus();
}
// gives user feedback about pending operations. Draws current status
// to website. Updates info in layer chooser.
window.renderUpdateStatus = function() {
var t = '<span class="help portallevel" title="Indicates portal levels displayed. Zoom in to display lower level portals.">';
if(!window.isSmartphone()) // space is valueable
t += '<b>portals</b>: ';
var minlvl = getMinPortalLevel();
if(minlvl === 0)
t+= '<span id="loadlevel">all</span>';
else
t+= '<span id="loadlevel" style="background:'+COLORS_LVL[minlvl]+'">L'+minlvl+(minlvl<8?'+':'') + '</span>';
t +='</span>';
t += ' <span class="map"><b>map</b>: ';
if(mapRunsUserAction)
t += '<span class="help" title="Paused due to user interaction">paused</span';
else if(isIdle())
t += '<span style="color:#888">Idle</span>';
else if(window.requests._quickRefreshPending)
t += 'refreshing';
else if(window.activeRequests.length > 0)
t += window.activeRequests.length + ' requests';
else {
// tooltip with detailed tile counts
t += '<span class="help" title="'+window.statusTotalMapTiles+' tiles: '+window.statusCachedMapTiles+' cached, '+window.statusSuccessMapTiles+' successful, '+window.statusStaleMapTiles+' stale, '+window.statusErrorMapTiles+' failed">';
// basic error/out of date/up to date message
if (window.statusErrorMapTiles) t += '<span style="color:#f66">Errors</span>';
else if (window.statusStaleMapTiles) t += '<span style="color:#fa6">Out of date</span>';
else t += 'Up to date';
t += '</span>';
}
t += '</span>';
if(window.failedRequestCount > 0)
t += ' <span style="color:#f66">' + window.failedRequestCount + ' failed</span>'
var portalSelection = $('.leaflet-control-layers-overlays label');
//it's an array - 0=unclaimed, 1=lvl 1, 2=lvl 2, ..., 8=lvl 8 - 9 relevant entries
//mark all levels below (but not at) minlvl as disabled
portalSelection.slice(0, minlvl).addClass('disabled').attr('title', 'Zoom in to show those.');
//and all from minlvl to 8 as enabled
portalSelection.slice(minlvl, 8+1).removeClass('disabled').attr('title', '');
$('#innerstatus').html(t);
//$('#updatestatus').click(function() { startRefreshTimeout(10); });
//. <a style="cursor: pointer" onclick="startRefreshTimeout(10)" title="Refresh">⟳</a>';
}
// sets the timer for the next auto refresh. Ensures only one timeout

75
code/status_bar.js Normal file
View File

@ -0,0 +1,75 @@
// STATUS BAR ///////////////////////////////////////
// gives user feedback about pending operations. Draws current status
// to website. Updates info in layer chooser.
window.renderUpdateStatus = function() {
// portal level display
var t = '<span class="help portallevel" title="Indicates portal levels displayed. Zoom in to display lower level portals.">';
if(!window.isSmartphone()) // space is valueable
t += '<b>portals</b>: ';
var minlvl = getMinPortalLevel();
if(minlvl === 0)
t+= '<span id="loadlevel">all</span>';
else
t+= '<span id="loadlevel" style="background:'+COLORS_LVL[minlvl]+'">L'+minlvl+(minlvl<8?'+':'') + '</span>';
t +='</span>';
// map status display
t += ' <span class="map"><b>map</b>: ';
var status = window.mapDataRequest.getStatus();
// status.short - short description of status
// status.long - longer description, for tooltip (optional)
// status.progress - fractional progress (from 0 to 1) of current state (optional)
t += '<span class="help" title="'+status.long+'">'+status.short+'</span>';
if (Status.progress !== undefined)
t += ' '+Math.round(status.progress*100)+'%';
/*
if(mapRunsUserAction)
t += '<span class="help" title="Paused due to user interaction">paused</span';
else if(isIdle())
t += '<span style="color:#888">Idle</span>';
else if(window.requests._quickRefreshPending)
t += 'refreshing';
else if(window.activeRequests.length > 0)
t += window.activeRequests.length + ' requests';
else {
// tooltip with detailed tile counts
t += '<span class="help" title="'+window.statusTotalMapTiles+' tiles: '+window.statusCachedMapTiles+' cached, '+window.statusSuccessMapTiles+' successful, '+window.statusStaleMapTiles+' stale, '+window.statusErrorMapTiles+' failed">';
// basic error/out of date/up to date message
if (window.statusErrorMapTiles) t += '<span style="color:#f66">Errors</span>';
else if (window.statusStaleMapTiles) t += '<span style="color:#fa6">Out of date</span>';
else t += 'Up to date';
t += '</span>';
}
*/
t += '</span>';
//request status
if (window.activeRequests.length > 0)
t += ' ' + window.activeRequests.length + ' requests';
if (window.failedRequestCount > 0)
t += ' <span style="color:#f66">' + window.failedRequestCount + ' failed</span>'
// layer selector - enable/disable layers that aren't visible due to zoom level
//FIXME! move this somewhere more suitable!
var portalSelection = $('.leaflet-control-layers-overlays label');
//it's an array - 0=unclaimed, 1=lvl 1, 2=lvl 2, ..., 8=lvl 8 - 9 relevant entries
//mark all levels below (but not at) minlvl as disabled
portalSelection.slice(0, minlvl).addClass('disabled').attr('title', 'Zoom in to show those.');
//and all from minlvl to 8 as enabled
portalSelection.slice(minlvl, 8+1).removeClass('disabled').attr('title', '');
$('#innerstatus').html(t);
//$('#updatestatus').click(function() { startRefreshTimeout(10); });
//. <a style="cursor: pointer" onclick="startRefreshTimeout(10)" title="Refresh">⟳</a>';
}

View File

@ -22,7 +22,6 @@ window.plugin.maxLinks = function() {};
// const values
window.plugin.maxLinks.MAX_DRAWN_LINKS = 400;
window.plugin.maxLinks.MAX_DRAWN_LINKS_INCREASED_LIMIT = 1000;
window.plugin.maxLinks.STROKE_STYLE = {
color: '#FF0000',
opacity: 1,
@ -34,7 +33,6 @@ window.plugin.maxLinks.STROKE_STYLE = {
window.plugin.maxLinks.layer = null;
window.plugin.maxLinks._updating = false;
window.plugin.maxLinks._renderLimitReached = false;
window.plugin.maxLinks.Point = function(x,y) {
this.x=x;
@ -64,9 +62,6 @@ window.plugin.maxLinks.updateLayer = function() {
var drawnLinkCount = 0;
window.plugin.maxLinks._renderLimitReached = false;
var renderLimit = window.USE_INCREASED_RENDER_LIMIT ?
window.plugin.maxLinks.MAX_DRAWN_LINKS_INCREASED_LIMIT :
window.plugin.maxLinks.MAX_DRAWN_LINKS;
var orderedPoints = function(a,b) {
if(a.x<b.x) return [a,b];
@ -106,7 +101,7 @@ window.plugin.maxLinks.updateLayer = function() {
drawLink(triangle.c,triangle.a);
// we only check the render limit after drawing all three edges of a triangle, for efficency
if (drawnLinkCount > renderLimit ) {
if (drawnLinkCount > window.pligin.maxLinks.MAX_DRAWN_LINKS ) {
window.plugin.maxLinks._renderLimitReached = true;
return false; //$.each break
}
@ -122,13 +117,7 @@ window.plugin.maxLinks.setup = function() {
window.plugin.maxLinks.layer = L.layerGroup([]);
window.addHook('checkRenderLimit', function(e) {
if (window.map.hasLayer(window.plugin.maxLinks.layer) &&
window.plugin.maxLinks._renderLimitReached)
e.reached = true;
});
window.addHook('requestFinished', function(e) {
window.addHook('mapDataRefreshEnd', function(e) {
window.plugin.maxLinks.updateLayer();
});