From dff09ed0c1afe0df201ff7bbaddfac81ea7c3bb6 Mon Sep 17 00:00:00 2001 From: Jon Atkins Date: Fri, 23 Aug 2013 05:08:08 +0100 Subject: [PATCH] work-in-progress on render rewrite... --- code/map_data_render.js | 43 ++++++++++++++++++++++++----------- code/portal_detail_display.js | 6 ++--- code/portal_highlighter.js | 2 +- 3 files changed, 34 insertions(+), 17 deletions(-) diff --git a/code/map_data_render.js b/code/map_data_render.js index 22ed0915..80f4cb13 100644 --- a/code/map_data_render.js +++ b/code/map_data_render.js @@ -159,14 +159,38 @@ window.Render.prototype.createPortalEntity = function(ent) { var latlng = L.latLng(ent[2].locationE6.latE6/1E6, ent[2].locationE6.lngE6/1E6); - var marker = this.createMarker(ent, portalLevel, latlng, team); +//TODO: move marker creation, style setting, etc into a separate class +//(as it's called from elsewhere - e.g. selecting/deselecting portals) + +//ALSO: change API for highlighters - make them return the updated style rather than directly calling setStyle on the portal marker +//(can this be done in a backwardly-compatable way??) + + var marker = this.createMarker(portalLevel, latlng, team); marker.on('click', function() { window.renderPortalDetails(ent[0]); }); marker.on('dblclick', function() { window.renderPortalDetails(ent[0]); window.map.setView(latlng, 17); }); + // we store various portal data within the portal options (style) data for use by IITC + // this data is constant throughout the life of the marker (as we destroy and re-create it if the ent data changes) + marker.setStyle ({ + level: portalLevel, + team: team, + ent: ent, // LEGACY - TO BE REMOVED AT SOME POINT! use .guid, .timestamp and .details instead + guid: ent[0], + timestamp: ent[1], + details: ent[2] + }); + + // portal highlighters highlightPortal(marker); + // handle re-rendering of the selected portal + if (ent[0] === selectedPortal) { + marker.setStyle({color: COLOR_SELECTED_PORTAL}); + } + + window.runHooks('portalAdded', {portal: marker}); window.portals[ent[0]] = marker; @@ -176,34 +200,27 @@ window.Render.prototype.createPortalEntity = function(ent) { } -window.Render.prototype.createMarker = function(ent, portalLevel, latlng, team) { +window.Render.prototype.createMarker = function(portalLevel, latlng, team) { - var options = this.portalPolyOptions (ent, portalLevel, team); + var options = this.portalPolyOptions (portalLevel, team); var marker = L.circleMarker (latlng, options); return marker; } -window.Render.prototype.portalPolyOptions = function(ent, portalLevel, team) { +window.Render.prototype.portalPolyOptions = function(portalLevel, team) { var lvWeight = Math.max(2, Math.floor(portalLevel) / 1.5); var lvRadius = team === window.TEAM_NONE ? 7 : Math.floor(portalLevel) + 4; var options = { radius: lvRadius + (L.Browser.mobile ? PORTAL_RADIUS_ENLARGE_MOBILE : 0), - color: ent[0] === selectedPortal ? COLOR_SELECTED_PORTAL : COLORS[team], + color: COLORS[team], opacity: 1, weight: lvWeight, fillColor: COLORS[team], fillOpacity: 0.5, - clickable: true, - level: portalLevel, - team: team, - ent: ent, - guid: ent[0], - timestamp: ent[1], - details: ent[2], - ent: ent // LEGACY - TO BE REMOVED AT SOME POINT! use .guid, .timestamp and .details instead + clickable: true }; return options; diff --git a/code/portal_detail_display.js b/code/portal_detail_display.js index f8398864..113b7b70 100644 --- a/code/portal_detail_display.js +++ b/code/portal_detail_display.js @@ -150,12 +150,12 @@ window.clearPortalIndicators = function() { window.selectPortal = function(guid) { var update = selectedPortal === guid; var oldPortal = portals[selectedPortal]; - if(!update && oldPortal) portalResetColor(oldPortal); +// if(!update && oldPortal) portalResetColor(oldPortal); selectedPortal = guid; if(portals[guid]) { - resonatorsSetSelectStyle(guid); +// resonatorsSetSelectStyle(guid); portals[guid].bringToFront().setStyle({color: COLOR_SELECTED_PORTAL}); } @@ -165,7 +165,7 @@ window.selectPortal = function(guid) { window.unselectOldPortal = function() { var oldPortal = portals[selectedPortal]; - if(oldPortal) portalResetColor(oldPortal); +// if(oldPortal) portalResetColor(oldPortal); selectedPortal = null; $('#portaldetails').html(''); if(isSmartphone()) { diff --git a/code/portal_highlighter.js b/code/portal_highlighter.js index f048741b..d4a0eaf9 100644 --- a/code/portal_highlighter.js +++ b/code/portal_highlighter.js @@ -67,5 +67,5 @@ window.resetHighlightedPortals = function() { renderPortal(portal.options.ent); } catch(e) {} - }); + }); }