diff --git a/code/map_data_render.js b/code/map_data_render.js index 13f665d7..0985e9d3 100644 --- a/code/map_data_render.js +++ b/code/map_data_render.js @@ -10,8 +10,11 @@ window.Render = function() { this.CLUSTER_SIZE = L.Browser.mobile ? 16 : 8; // the map is divited into squares of this size in pixels for clustering purposes. mobile uses larger markers, so therefore larger clustering areas this.CLUSTER_PORTAL_LIMIT = 4; // no more than this many portals are drawn in each cluster square + // link length, in pixels, to be visible. use the portal cluster size, as shorter than this is likely hidden + // under the portals + this.LINK_VISIBLE_PIXEL_LENGTH = this.CLUSTER_SIZE; - this.currentPortalClusterZoom = undefined; + this.entityVisibilityZoom = undefined; } @@ -435,7 +438,9 @@ window.Render.prototype.createLinkEntity = function(ent,faked) { // only add the link to the layer if it's long enough to be seen - linksFactionLayers[poly.options.team].addLayer(poly); + if (this.linkVisible(poly)) { + linksFactionLayers[poly.options.team].addLayer(poly); + } } @@ -490,48 +495,55 @@ window.Render.prototype.createLinksFromPortalData = function(portalGuid) { } +window.Render.prototype.updateEntityVisibility = function() { + if (this.entityVisibilityZoom === undefined || this.entityVisibilityZoom != map.getZoom()) { + this.entityVisibilityZoom = map.getZoom(); + + this.resetPortalClusters(); + this.resetLinkVisibility(); + } +} + + // portal clustering functionality window.Render.prototype.resetPortalClusters = function() { - if (this.currentPortalClusterZoom === undefined || this.currentPortalClusterZoom != map.getZoom()) { - this.portalClusters = {}; - this.currentPortalClusterZoom = map.getZoom(); + this.portalClusters = {}; - // first, place the portals into the clusters - for (var pguid in window.portals) { - var p = window.portals[pguid]; - var cid = this.getPortalClusterID(p); + // first, place the portals into the clusters + for (var pguid in window.portals) { + var p = window.portals[pguid]; + var cid = this.getPortalClusterID(p); - if (!(cid in this.portalClusters)) this.portalClusters[cid] = []; + if (!(cid in this.portalClusters)) this.portalClusters[cid] = []; - this.portalClusters[cid].push(p.options.guid); - } + this.portalClusters[cid].push(p.options.guid); + } - // now, for each cluster, sort by some arbitary data (the guid will do), and display the first CLUSTER_PORTAL_LIMIT - for (var cid in this.portalClusters) { - var c = this.portalClusters[cid]; + // now, for each cluster, sort by some arbitary data (the guid will do), and display the first CLUSTER_PORTAL_LIMIT + for (var cid in this.portalClusters) { + var c = this.portalClusters[cid]; - c.sort(); + c.sort(); - for (var i=0; i= this.LINK_VISIBLE_PIXEL_LENGTH; +} + + +window.Render.prototype.resetLinkVisibility = function() { + + for (var guid in window.links) { + var link = window.links[guid]; + + var visible = this.linkVisible(link); + + if (visible) { + if (!linksFactionLayers[link.options.team].hasLayer(link)) linksFactionLayers[link.options.team].addLayer(link); + } else { + if (linksFactionLayers[link.options.team].hasLayer(link)) linksFactionLayers[link.options.team].removeLayer(link); + } + } +} diff --git a/code/map_data_request.js b/code/map_data_request.js index 701fbb23..91b87615 100644 --- a/code/map_data_request.js +++ b/code/map_data_request.js @@ -205,7 +205,7 @@ window.MapDataRequest.prototype.refresh = function() { this.render.clearEntitiesOutsideBounds(dataBounds); - this.render.resetPortalClusters(); + this.render.updateEntityVisibility(); console.log('requesting data tiles at zoom '+zoom+' (L'+minPortalLevel+'+ portals), map zoom is '+map.getZoom());