Skip to content
This repository was archived by the owner on Sep 20, 2019. It is now read-only.

Addition of on delete actions for overlays #308

Merged
merged 1 commit into from
Nov 17, 2017

Conversation

LyndonArmitage
Copy link
Contributor

(FYI: I am not really an angular or JavaScript developer, having not done any proper front end development in a long while so apologies if this doesn't fit the code style etc.)

This is partially addressing the TODO present in the layers directive:

TODO: Depending on the layer type we will have to delete what's included on it

We noticed on one of our applications that there was a memory leak to do with a heatmap overlay that refreshed every 10 seconds. It seemed like Chrome was keeping a reference to the many points being fed into the layer, adding in the ability to clean up the heatmap layer upon refresh seemed to eliminate this issue.

I might be able to come up with an example piece of code showing the issue at some point but basically this PR adds the ability to add an action that should be executed on the old layer before it is removed from the leaflet overlays array.

Example configuration (using heatmap support provided by ui-leaflet-layers):

      {
        heat: {
          name: 'Heat Map',
          type: 'heat',
          data: [],
          layerOptions: {
            radius: 15,
            blur: 15,
            minOpacity: .4,
            max: 1,
            gradient: defaultGradient,
          },
          visible: true,
          doRefresh: false,
          cleanupAction: function (layer) {
            console.log("cleaning up layer");
            layer.setLatLngs([]);
          }
        },
      }

Simply add a a "cleanupAction" field to your configured layer that is a
function that takes in the layer and you can perform actions on it
before it is deleted.

This is very useful for layers like heatmaps etc that seemed to leak
memory upon being refreshed.
@elesdoar elesdoar merged commit 6ff6d90 into angular-ui:master Nov 17, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants