diff --git a/code/map_data_render.js b/code/map_data_render.js index 4a21f7c9..3bd12e50 100644 --- a/code/map_data_render.js +++ b/code/map_data_render.js @@ -14,14 +14,12 @@ window.Render = function() { // under the portals this.LINK_VISIBLE_PIXEL_LENGTH = this.CLUSTER_SIZE; - this.entityVisibilityZoom = undefined; - this.portalMarkerScale = undefined; } // start a render pass. called as we start to make the batch of data requests to the servers -window.Render.prototype.startRenderPass = function() { +window.Render.prototype.startRenderPass = function(level,bounds) { this.isRendering = true; this.deletedGuid = {}; // object - represents the set of all deleted game entity GUIDs seen in a render pass @@ -29,6 +27,16 @@ window.Render.prototype.startRenderPass = function() { this.seenPortalsGuid = {}; this.seenLinksGuid = {}; this.seenFieldsGuid = {}; + + this.bounds = bounds; + + this.clearPortalsBelowLevel(level); + + this.resetPortalClusters(); + this.resetLinkVisibility(); + + this.rescalePortalMarkers(); + } window.Render.prototype.clearPortalsBelowLevel = function(level) { @@ -44,40 +52,6 @@ window.Render.prototype.clearPortalsBelowLevel = function(level) { console.log('Render: deleted '+count+' portals by level'); } -window.Render.prototype.clearEntitiesOutsideBounds = function(bounds) { - var pcount=0, lcount=0, fcount=0; - - for (var guid in window.portals) { - var p = portals[guid]; - if (!bounds.contains (p.getLatLng()) && guid !== selectedPortal && !artifact.isInterestingPortal(guid)) { - this.deletePortalEntity(guid); - pcount++; - } - } - - for (var guid in window.links) { - var l = links[guid]; - if (!bounds.intersects (l.getBounds())) { - this.deleteLinkEntity(guid); - lcount++; - } - } - - for (var guid in window.fields) { - var f = fields[guid]; - if (!bounds.intersects (f.getBounds())) { - this.deleteFieldEntity(guid); - fcount++; - } - } - console.log('Render: deleted '+pcount+' portals, '+lcount+' links, '+fcount+' fields by bounds check'); -} - -// TODO? as well as clearing portals by level, and clearing entities outside the bounds... -// can we clear unneeded 'fake' links after zooming out? based on the portals no longer being available to construct -// the data? (not *required* - as they'll be removed in the endRenderPass code - but clearing things earlier rather than -// later is preferred, if possible) - // process deleted entity list and entity data window.Render.prototype.processTileData = function(tiledata) { @@ -406,21 +380,15 @@ window.Render.prototype.createLinkEntity = function(ent,faked) { -window.Render.prototype.updateEntityVisibility = function() { - if (this.entityVisibilityZoom === undefined || this.entityVisibilityZoom != map.getZoom()) { - this.entityVisibilityZoom = map.getZoom(); +window.Render.prototype.rescalePortalMarkers = function() { + if (this.portalMarkerScale === undefined || this.portalMarkerScale != portalMarkerScale()) { + this.portalMarkerScale = portalMarkerScale(); - this.resetPortalClusters(); - this.resetLinkVisibility(); + console.log('Render: map zoom '+map.getZoom()+' changes portal scale to '+portalMarkerScale()+' - redrawing all portals'); - if (this.portalMarkerScale === undefined || this.portalMarkerScale != portalMarkerScale()) { - this.portalMarkerScale = portalMarkerScale(); - - console.log('Render: map zoom '+map.getZoom()+' changes portal scale to '+portalMarkerScale()+' - redrawing all portals'); - - //NOTE: we're not calling this because it resets highlights - we're calling it as it resets the style (inc size) of all portal markers - resetHighlightedPortals(); - } + //NOTE: we're not calling this because it resets highlights - we're calling it as it + // resets the style (inc size) of all portal markers, applying the new scale + resetHighlightedPortals(); } } @@ -458,7 +426,7 @@ window.Render.prototype.resetPortalClusters = function() { var guid = c[i]; var p = window.portals[guid]; var layerGroup = portalsFactionLayers[parseInt(p.options.level)][p.options.team]; - if (i= 0) { this.portalClusters[cid].splice(index,1); - // FIXME? if this portal was in on the screen (in the first 10), and we still have 10+ portals, add the new 10to to the screen? + // FIXME? if this portal was in on the screen (in the first 10), and we still have 10+ portals, add the new 10th to the screen? } } } @@ -520,6 +490,10 @@ window.Render.prototype.getPortalClusterID = function(portal) { window.Render.prototype.linkVisible = function(link) { + if (!this.bounds.intersects(link.getBounds())) { + return false; + } + var lengthSquared = this.getLinkPixelLengthSquared (link); return lengthSquared >= this.LINK_VISIBLE_PIXEL_LENGTH*this.LINK_VISIBLE_PIXEL_LENGTH; diff --git a/code/map_data_request.js b/code/map_data_request.js index 25746ddd..0fac9c92 100644 --- a/code/map_data_request.js +++ b/code/map_data_request.js @@ -227,11 +227,8 @@ window.MapDataRequest.prototype.refresh = function() { window.runHooks ('mapDataRefreshStart', {bounds: bounds, mapZoom: mapZoom, dataZoom: dataZoom, minPortalLevel: tileParams.level, tileBounds: dataBounds}); - this.render.startRenderPass(); - this.render.clearPortalsBelowLevel(tileParams.level); - this.render.clearEntitiesOutsideBounds(dataBounds); + this.render.startRenderPass(tileParams.level, dataBounds); - this.render.updateEntityVisibility(); this.render.processGameEntities(artifact.getArtifactEntities());