From 571a17d84b22b1f9b2af8845315bd6473fbc1dbf Mon Sep 17 00:00:00 2001 From: Jon Atkins Date: Tue, 27 Aug 2013 21:04:28 +0100 Subject: [PATCH] work-in-progress - committing to switch to other work --- code/boot.js | 11 +++--- code/hooks.js | 8 +++-- code/map_data_request.js | 14 ++++++-- code/request_handling.js | 52 --------------------------- code/status_bar.js | 75 +++++++++++++++++++++++++++++++++++++++ plugins/max-links.user.js | 15 ++------ 6 files changed, 101 insertions(+), 74 deletions(-) create mode 100644 code/status_bar.js diff --git a/code/boot.js b/code/boot.js index 4e307b50..c1086737 100644 --- a/code/boot.js +++ b/code/boot.js @@ -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'); diff --git a/code/hooks.js b/code/hooks.js index 8bedaa42..e0633691 100644 --- a/code/hooks.js +++ b/code/hooks.js @@ -15,6 +15,8 @@ // required to successfully boot the plugin. // // Here’s 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']; diff --git a/code/map_data_request.js b/code/map_data_request.js index 0058c3c0..d5ffd818 100644 --- a/code/map_data_request.js +++ b/code/map_data_request.js @@ -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 { diff --git a/code/request_handling.js b/code/request_handling.js index d2116c74..4ae1d3fb 100644 --- a/code/request_handling.js +++ b/code/request_handling.js @@ -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 = ''; - if(!window.isSmartphone()) // space is valueable - t += 'portals: '; - var minlvl = getMinPortalLevel(); - if(minlvl === 0) - t+= 'all'; - else - t+= 'L'+minlvl+(minlvl<8?'+':'') + ''; - t +=''; - - t += ' map: '; - if(mapRunsUserAction) - t += 'paused 0) - t += window.activeRequests.length + ' requests'; - else { - // tooltip with detailed tile counts - t += ''; - - // basic error/out of date/up to date message - if (window.statusErrorMapTiles) t += 'Errors'; - else if (window.statusStaleMapTiles) t += 'Out of date'; - else t += 'Up to date'; - - t += ''; - - } - t += ''; - - if(window.failedRequestCount > 0) - t += ' ' + window.failedRequestCount + ' failed' - - 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); }); - //. '; -} // sets the timer for the next auto refresh. Ensures only one timeout diff --git a/code/status_bar.js b/code/status_bar.js new file mode 100644 index 00000000..10a61f4a --- /dev/null +++ b/code/status_bar.js @@ -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 = ''; + if(!window.isSmartphone()) // space is valueable + t += 'portals: '; + var minlvl = getMinPortalLevel(); + if(minlvl === 0) + t+= 'all'; + else + t+= 'L'+minlvl+(minlvl<8?'+':'') + ''; + t +=''; + + + // map status display + t += ' map: '; + + 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 += ''+status.short+''; + if (Status.progress !== undefined) + t += ' '+Math.round(status.progress*100)+'%'; + +/* + if(mapRunsUserAction) + t += 'paused 0) + t += window.activeRequests.length + ' requests'; + else { + // tooltip with detailed tile counts + t += ''; + + // basic error/out of date/up to date message + if (window.statusErrorMapTiles) t += 'Errors'; + else if (window.statusStaleMapTiles) t += 'Out of date'; + else t += 'Up to date'; + + t += ''; + + } +*/ + t += ''; + + //request status + if (window.activeRequests.length > 0) + t += ' ' + window.activeRequests.length + ' requests'; + if (window.failedRequestCount > 0) + t += ' ' + window.failedRequestCount + ' failed' + +// 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); }); + //. '; +} diff --git a/plugins/max-links.user.js b/plugins/max-links.user.js index 29218e8a..0a777c24 100644 --- a/plugins/max-links.user.js +++ b/plugins/max-links.user.js @@ -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 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(); });