IITC-CE / ingress-intel-total-conversion

intel.ingress.com total conversion user script with some new features. Should allow easier extension of the intel map.
https://iitc.app
ISC License
290 stars 109 forks source link

Permanent portal entities #325

Open johnd0e opened 4 years ago

johnd0e commented 4 years ago

Currently portal entity (represented by CircleMarker) is not permanent: every time we get some data with newer timestamp - portal marker is recreated:

createPortalEntity() https://github.com/IITC-CE/ingress-intel-total-conversion/blob/36a9b69e55c409a091523401422f532e628c3b1d/core/code/map_data_render.js#L292-L307

So all additional data (potentially attached by plugins) is discarded, including event listeners and other leaflet-binded things. In such case two hooks are run consequentially:

https://github.com/IITC-CE/ingress-intel-total-conversion/blob/36a9b69e55c409a091523401422f532e628c3b1d/core/code/map_data_render.js#L225 https://github.com/IITC-CE/ingress-intel-total-conversion/blob/36a9b69e55c409a091523401422f532e628c3b1d/core/code/map_data_render.js#L351

So data is discarded, but not completely lost: plugin may restore some data from previousData property. But as you see it's not so obvious and in many cases it may be tricky or cumbersome - to keep continuity between separated portal entities.

I propose to change this approach to some more simple and consistent: keep same portal marker, and only update it's data. Examples of potential benefits:

johnd0e commented 4 years ago

I propose to change this approach to some more simple and consistent: keep same portal marker, and only update it's data.

But we must consider compatibility, so all current hooks should stay.

  1. Instead, we could extend hook data with additional property update (both hooks)
  2. Alternatively, we may leave old hooks apart (keep as they are), and implement this as completely independent event system #217.

107 is another important improvement (though not directly related to subj).

MysticJay commented 3 years ago

Related problem? Hook portalSelected gets executed two or three times when a portal is selected. code to check:

window.addHook("portalSelected", someFunction);
function someFunction(d) {
  console.log(d);
}