diff --git a/core/code/map_data_render.js b/core/code/map_data_render.js index 906c7ee63..e76f5d2d9 100644 --- a/core/code/map_data_render.js +++ b/core/code/map_data_render.js @@ -286,6 +286,14 @@ window.Render.prototype.createPortalEntity = function(ent, details) { // details var data = decodeArray.portal(ent[2], details); var guid = ent[0]; + // add missing fields + data.guid = guid; + if (!data.timestamp) + data.timestamp = ent[1]; + + // LEGACY - TO BE REMOVED AT SOME POINT! use .guid, .timestamp and .data instead + data.ent = ent; + // check if entity already exists var oldPortal = guid in window.portals; @@ -293,35 +301,18 @@ window.Render.prototype.createPortalEntity = function(ent, details) { // details // yes. now check to see if the entity data we have is newer than that in place var p = window.portals[guid]; - if (!data.history || p.options.data.history === data.history) { - if (p.options.timestamp > ent[1]) { - return p; // this data is older - abort processing - } - - if (p.options.timestamp == ent[1] && p.hasFullDetails()) // this data is identical - abort processing - return p; + if (!p.willUpdate(data)) { + // this data doesn't bring new detail - abort processing + return p; } // the data we have is newer. many data changes require re-rendering of the portal // (e.g. level changed, so size is different, or stats changed so highlighter is different) // remember the old details, for the callback - previousData = p.getDetails(); - - // preserve history - if (!data.history) { - data.history = previousData.history; - } + previousData = $.extend(true, {}, p.getDetails()); } - // add missing fields - data.guid = guid; - if (!data.timestamp) - data.timestamp = ent[1]; - - // LEGACY - TO BE REMOVED AT SOME POINT! use .guid, .timestamp and .data instead - data.ent = ent; - var latlng = L.latLng(data.latE6/1E6, data.lngE6/1E6); window.pushPortalGuidPositionCache(data.guid, data.latE6, data.lngE6); diff --git a/core/code/portal_marker.js b/core/code/portal_marker.js index 89274341e..987d6628c 100644 --- a/core/code/portal_marker.js +++ b/core/code/portal_marker.js @@ -36,14 +36,53 @@ L.PortalMarker = L.CircleMarker.extend({ this.on('dblclick', handler_portal_dblclick); this.on('contextmenu', handler_portal_contextmenu); }, + willUpdate: function (details) { + // portal location edit + if (this._details.latE6 !== details.latE6 || this._details.lngE6 !== details.lngE6) + return true; + // new data + if (this._details.timestamp < details.timestamp) + return true; + // even if we get history that was missing ? is it even possible ? + if (this._details.timestamp > details.timestamp) + return false; + + // get new history + if (details.history) { + if (!this._details.history) + return true; + if (this._details.history._raw !== details.history._raw) + return true; + } + + // get details portal data + if (!this._details.mods && details.mods) + return true; + + // does portal picture/name/location modfication update the timestamp ? + return false; + }, updateDetails: function(details) { // portal has been moved - if (this.details) + if (this._details) { if (this._details.latE6 !== details.latE6 || this._details.lngE6 !== details.lngE6) this.setLatLng(L.latLng(details.latE6/1E6, details.lngE6/1E6)); - // xxx: handle permanent data - this._details = details; + // we got more details + if (this._details.timestamp == details.timestamp) { + var localThis = this; + ["mods", "resonators", "owner", "artifactDetail", "history"].forEach(function (prop) { + if (details[prop]) localThis._details[prop] = details[prop]; + }); + // LEGACY - TO BE REMOVED AT SOME POINT! use .guid, .timestamp and .data instead + this._details.ent = details.ent; + } else { + // permanent data (history only) + if (!details.history) details.history = this._details.history; + + this._details = details; + } + } else this._details = details; this._level = parseInt(details.level)||0; this._team = teamStringToId(details.team);