From 3c90960e4cdc0224e8ddffa6ea4c1c577c6b59e1 Mon Sep 17 00:00:00 2001 From: Jon Atkins Date: Sun, 25 Aug 2013 17:50:28 +0100 Subject: [PATCH] work-in-progress - checking in while looking at other code on master. may be broken --- code/debugging.js | 6 +- code/hooks.js | 12 +- code/map_data.js | 3 - code/portal_marker.js | 26 +++++ code/portal_render_limit.js | 178 ------------------------------ code/request_handling.js | 3 - code/utils_misc.js | 53 +++++---- main.js | 16 +-- plugins/show-more-portals.user.js | 3 - 9 files changed, 65 insertions(+), 235 deletions(-) create mode 100644 code/portal_marker.js delete mode 100644 code/portal_render_limit.js diff --git a/code/debugging.js b/code/debugging.js index af0bf775..822318c5 100644 --- a/code/debugging.js +++ b/code/debugging.js @@ -5,9 +5,9 @@ window.debug = function() {} window.debug.renderDetails = function() { - console.log('portals: ' + window.portalsCount); - console.log('links: ' + window.linksCount); - console.log('fields: ' + window.fieldsCount); + console.log('portals: ' + Object.keys(window.portals).length); + console.log('links: ' + Object.keys(window.links).length); + console.log('fields: ' + Object.keys(window.fields).length); } window.debug.printStackTrace = function() { diff --git a/code/hooks.js b/code/hooks.js index 35fef550..8bedaa42 100644 --- a/code/hooks.js +++ b/code/hooks.js @@ -41,16 +41,6 @@ // array [GUID, time, details]. Plugin can manipulate the // array to change order or add additional values to the // details of a portal. -// beforePortalReRender: the callback argument is -// {portal: ent[2], oldPortal : d, portalGuid: ent[0], reRender : false}. -// The callback needs to update the value of reRender to -// true if the plugin has a reason to have the portal -// redrawn. It is called early on in the -// code/map_data.js#renderPortal as long as there was an -// old portal for the guid. -// checkRenderLimit: callback is passed the argument of -// {reached : false} to indicate that the renderlimit is reached -// set reached to true. // requestFinished: called after each request finished. Argument is // {success: boolean} indicated the request success or fail. // iitcLoaded: called after IITC and all plugins loaded @@ -59,7 +49,7 @@ window._hooks = {} window.VALID_HOOKS = ['portalAdded', 'portalDetailsUpdated', 'publicChatDataAvailable', 'factionChatDataAvailable', 'portalDataLoaded', - 'beforePortalReRender', 'checkRenderLimit', 'requestFinished', 'nicknameClicked', + 'requestFinished', 'nicknameClicked', 'geoSearch', 'iitcLoaded']; window.runHooks = function(event, data) { diff --git a/code/map_data.js b/code/map_data.js index bb72422e..ef1dd5f3 100644 --- a/code/map_data.js +++ b/code/map_data.js @@ -147,9 +147,6 @@ window.requestData = function() { } } - // Reset previous result of Portal Render Limit handler - portalRenderLimit.init(); - // send ajax requests console.log('requesting '+requestTileCount+' tiles in '+Object.keys(tiles).length+' requests'); diff --git a/code/portal_marker.js b/code/portal_marker.js new file mode 100644 index 00000000..7571192b --- /dev/null +++ b/code/portal_marker.js @@ -0,0 +1,26 @@ +// PORTAL MARKER ////////////////////////////////////////////// +// code to create and update a portal marker + +// sequence of calls: +// 1. var marker = createMarker(); +// 2. // IITC (elsewhere) sets up options.details, options.guid, etc +// 3. // IITC (elsewhere) calls marker.setLatLng() +// 3. setMarkerStyle(selected); + + +// create a blank marker. no data specified at this point +window.createMarker = function() { + return new L.CircleMarker(); +} + + +window.setMarkerStyle = function(selected) { + + var options = { + }; + + // call highlighter + + + +} diff --git a/code/portal_render_limit.js b/code/portal_render_limit.js deleted file mode 100644 index cd1f4cb5..00000000 --- a/code/portal_render_limit.js +++ /dev/null @@ -1,178 +0,0 @@ - -// PORTAL RENDER LIMIT HANDLER /////////////////////////////////////// -// Functions to handle hiding low level portal when portal render -// limit is reached. -// -// On initialization, previous minLevel will preserve to previousMinLevel -// and modify with zoom level difference. -// -// After initialized and reset in window.requestData(), "processPortals" -// intercept all portals data in "handleDataResponse". Put the count of -// new portals to newPortalsPerLevel[portal level]. Portals with level >= -// previousMinLevel and already on map will return as result and continue -// to render. Others will save to portalsLowerThanPrevMinLv. If there is -// no more active request of map data, portalsLowerThanPrevMinLv will add -// back to result and render base on current minLevel. -// -// "window.handleFailRequest" is added to handle the case when the last request -// failed and "processPortals" didn't get called. It will get -// portalsLowerThanPrevMinLv base on current minLevel and render them. -// -// "getMinLevel" will be called by "getMinPortalLevel" in utils_misc.js -// to determine min portal level to draw on map. -// -// "getMinLevel" will return minLevel and call "setMinLevel" if -// minLevel hasn't set yet. -// -// In "setMinLevel", it will loop through all portal level from -// high to low, and sum total portal count (old + new) to check -// minLevel. -// -// minLevel is preserved and only replaced when render limit reached in -// higher level, until next window.requestData() called and reset. -// - -window.portalRenderLimit = function() {} - -window.portalRenderLimit.initialized = false; -window.portalRenderLimit.minLevelSet = false; -window.portalRenderLimit.minLevel = -1; -window.portalRenderLimit.previousMinLevel = -1; -window.portalRenderLimit.previousZoomLevel = null; -window.portalRenderLimit.newPortalsPerLevel = new Array(MAX_PORTAL_LEVEL + 1); -window.portalRenderLimit.portalsLowerThanPrevMinLv = new Array(MAX_PORTAL_LEVEL + 1); -window.portalRenderLimit.portalsLowerThanPrevMinLvCnt = new Array(MAX_PORTAL_LEVEL + 1); - -window.portalRenderLimit.init = function () { - var currentZoomLevel = map.getZoom(); - // previousZoomLevel set to current zoom level on the first run - portalRenderLimit.previousZoomLevel = portalRenderLimit.previousZoomLevel || currentZoomLevel; - - // If there is a minLevel set in previous run, calculate previousMinLevel with it. - if(portalRenderLimit.minLevelSet) { - var zoomDiff = currentZoomLevel - portalRenderLimit.previousZoomLevel; - portalRenderLimit.previousMinLevel = Math.max(portalRenderLimit.minLevel - zoomDiff, -1); - portalRenderLimit.previousMinLevel = Math.min(portalRenderLimit.previousMinLevel, MAX_PORTAL_LEVEL); - } - - portalRenderLimit.previousZoomLevel = currentZoomLevel; - - portalRenderLimit.minLevel = -1; - portalRenderLimit.resetCounting(); - portalRenderLimit.resetPortalsLowerThanPrevMinLv(); - portalRenderLimit.initialized = true; -} - -window.portalRenderLimit.resetCounting = function() { - portalRenderLimit.minLevelSet = false; - for(var i = 0; i <= MAX_PORTAL_LEVEL; i++) { - portalRenderLimit.newPortalsPerLevel[i] = 0; - } -} - -window.portalRenderLimit.resetPortalsLowerThanPrevMinLv = function() { - for(var i = 0; i <= MAX_PORTAL_LEVEL; i++) { - portalRenderLimit.portalsLowerThanPrevMinLv[i] = {}; - portalRenderLimit.portalsLowerThanPrevMinLvCnt[i] = 0; - } -} - -// Use to clean up level of portals which is over render limit after counting new portals -window.portalRenderLimit.cleanUpOverLimitPortalLevel = function() { - var currentMinLevel = window.getMinPortalLevel(); - for(var i = 0; i < currentMinLevel; i++) { - portalsLayers[i].eachLayer(function(item) { - var itemGuid = item.options.guid; - // check if 'item' is a portal - if(getTypeByGuid(itemGuid) != TYPE_PORTAL) return true; - // Don’t remove if it is selected. - if(itemGuid == window.selectedPortal) return true; - portalsLayers[i].removeLayer(item); - }); - } -} - -// Count new portals. Then split lower level portal if it's not last request. -// And Merge back if it's last request and render limit not yet hit -window.portalRenderLimit.splitOrMergeLowLevelPortals = function(originPortals) { - portalRenderLimit.resetCounting(); - portalRenderLimit.countingPortals(originPortals); - - var resultPortals = requests.isLastRequest('getThinnedEntitiesV4') - ? portalRenderLimit.mergeLowLevelPortals(originPortals) - : portalRenderLimit.splitLowLevelPortals(originPortals); - - return resultPortals; -} - -window.portalRenderLimit.countingPortals = function(portals) { - $.each(portals, function(ind, portal) { - var portalGuid = portal[0]; - var portalLevel = parseInt(getPortalLevel(portal[2])); - var layerGroup = portalsLayers[portalLevel]; - - if(findEntityInLeaflet(layerGroup, window.portals, portalGuid)) return true; - - portalRenderLimit.newPortalsPerLevel[portalLevel]++; - }); -} - -// Split the portal if it's lower level and not on map -window.portalRenderLimit.splitLowLevelPortals = function(portals) { - var resultPortals = {}; - - $.each(portals || {}, function(guid, portal) { - var portalLevel = parseInt(getPortalLevel(portal[2])); - var portalOnMap = window.portals[guid]; - - if(!portalOnMap && portalLevel < portalRenderLimit.previousMinLevel) { - portalRenderLimit.portalsLowerThanPrevMinLv[portalLevel][guid] = portal; - portalRenderLimit.portalsLowerThanPrevMinLvCnt[portalLevel]++; - } else { - resultPortals[guid] = portal; - } - }); - return resultPortals; -} - -window.portalRenderLimit.mergeLowLevelPortals = function(appendTo) { - var resultPortals = appendTo ? appendTo : {}; - for(var i = portalRenderLimit.getMinLevel(); - i < portalRenderLimit.previousMinLevel; - i++) { - $.extend(resultPortals, portalRenderLimit.portalsLowerThanPrevMinLv[i]); - } - - // Reset portalsLowerThanPrevMinLv, ensure they return only once - portalRenderLimit.resetPortalsLowerThanPrevMinLv(); - return resultPortals; -} - -window.portalRenderLimit.getMinLevel = function() { - if(!portalRenderLimit.initialized) return -1; - if(!portalRenderLimit.minLevelSet) portalRenderLimit.setMinLevel(); - return portalRenderLimit.minLevel; -} - -window.portalRenderLimit.setMinLevel = function() { - var totalPortalsCount = 0; - var newMinLevel = MAX_PORTAL_LEVEL + 1; - - // Find the min portal level under render limit - while(newMinLevel > 0) { - var oldPortalCount = layerGroupLength(portalsLayers[newMinLevel - 1]); - var storedPortalCount = portalRenderLimit.portalsLowerThanPrevMinLvCnt[newMinLevel - 1]; - var newPortalCount = Math.max(storedPortalCount, portalRenderLimit.newPortalsPerLevel[newMinLevel - 1]); - - totalPortalsCount += oldPortalCount + newPortalCount; - if(totalPortalsCount >= MAX_DRAWN_PORTALS) - break; - newMinLevel--; - } - - // If render limit reached at max portal level, still let portal at max level render - newMinLevel = Math.min(newMinLevel, MAX_PORTAL_LEVEL); - - portalRenderLimit.minLevel = Math.max(newMinLevel, portalRenderLimit.minLevel); - portalRenderLimit.minLevelSet = true; -} diff --git a/code/request_handling.js b/code/request_handling.js index 722333b2..38421572 100644 --- a/code/request_handling.js +++ b/code/request_handling.js @@ -78,9 +78,6 @@ window.renderUpdateStatus = function() { } t += ''; - if(renderLimitReached()) - t += ' RENDER LIMIT' - if(window.failedRequestCount > 0) t += ' ' + window.failedRequestCount + ' failed' diff --git a/code/utils_misc.js b/code/utils_misc.js index 4e118b78..07f0a2fc 100644 --- a/code/utils_misc.js +++ b/code/utils_misc.js @@ -230,7 +230,6 @@ window.getPaddedBounds = function() { window._storedPaddedBounds = null; }); } - if(renderLimitReached(0.7)) return window.map.getBounds(); if(window._storedPaddedBounds) return window._storedPaddedBounds; var p = window.map.getBounds().pad(VIEWPORT_PAD_RATIO); @@ -238,20 +237,6 @@ window.getPaddedBounds = function() { return p; } -// returns true if the render limit has been reached. The default ratio -// is 1, which means it will tell you if there are more items drawn than -// acceptable. A value of 0.9 will tell you if 90% of the amount of -// acceptable entities have been drawn. You can use this to heuristi- -// cally detect if the render limit will be hit. -window.renderLimitReached = function(ratio) { - ratio = ratio || 1; - if(window.portalsCount*ratio >= MAX_DRAWN_PORTALS) return true; - if(window.linksCount*ratio >= MAX_DRAWN_LINKS) return true; - if(window.fieldsCount*ratio >= MAX_DRAWN_FIELDS) return true; - var param = { 'reached': false }; - window.runHooks('checkRenderLimit', param); - return param.reached; -} window.getPortalDataZoom = function() { var z = map.getZoom(); @@ -275,14 +260,36 @@ window.getPortalDataZoom = function() { } window.getMinPortalLevelForZoom = function(z) { - if(z >= 17) return 0; - if(z < 0) return 8; - var conv = [8,8,8,8,7,7,6,6,5,4,4,3,3,2,2,1,1]; - var minLevelByRenderLimit = portalRenderLimit.getMinLevel(); - var result = minLevelByRenderLimit > conv[z] - ? minLevelByRenderLimit - : conv[z]; - return result; +//based on code from stock gen_dashboard.js + switch(z) { + case 0: + case 1: + case 2: + case 3: + return 8; + case 4: + case 5: + return 7; + case 6: + case 7: + return 6; + case 8: + return 5; + case 9: + case 10: + return 4; + case 11: + case 12: + return 3; + case 13: + case 14: + return 2; + case 15: + case 16: + return 1; + default: + return 0 + } } diff --git a/main.js b/main.js index 15c8019a..b65cec97 100644 --- a/main.js +++ b/main.js @@ -143,15 +143,12 @@ window.CHAT_FACTION_ITEMS = 100; window.CHAT_REQUEST_SCROLL_TOP = 200; window.CHAT_SHRINKED = 60; -// Leaflet will get very slow for MANY items. It’s better to display -// only some instead of crashing the browser. -window.MAX_DRAWN_PORTALS = 1000; -window.MAX_DRAWN_LINKS = 400; -window.MAX_DRAWN_FIELDS = 200; // Minimum zoom level resonator will display window.RESONATOR_DISPLAY_ZOOM_LEVEL = 17; + // Minimum area to zoom ratio that field MU's will display window.FIELD_MU_DISPLAY_AREA_ZOOM_RATIO = 0.001; + // Point tolerance for displaying MU's window.FIELD_MU_DISPLAY_POINT_TOLERANCE = 60 @@ -246,15 +243,12 @@ window.portalAccessIndicator = null; window.mapRunsUserAction = false; var portalsLayers, linksLayer, fieldsLayer; -// contain references to all entities shown on the map. These are -// automatically kept in sync with the items on *sLayer, so never ever -// write to them. +// contain references to all entities loaded from the server. If render limits are hit, +// not all may be added to the leaflet layers window.portals = {}; -window.portalsCount = 0; window.links = {}; -window.linksCount = 0; window.fields = {}; -window.fieldsCount = 0; + window.resonators = {}; // contain current status(on/off) of overlay layerGroups. diff --git a/plugins/show-more-portals.user.js b/plugins/show-more-portals.user.js index a1af798c..21a446b7 100644 --- a/plugins/show-more-portals.user.js +++ b/plugins/show-more-portals.user.js @@ -29,9 +29,6 @@ window.plugin.showMorePortals.setup = function() { window.getPortalDataZoom = function() { var mapZoom = map.getZoom(); - // on mobile (at least), the map zoom has been non-integer occasionally. fix it. - z = Math.floor(z); - // yes, it is possible to increase this beyond "+1" - however, that will end up producing a rediculous number // of requests to the Niantic servers, giving many request failed errors/tile timeouts // (every increase by one requests four times as many data tiles)