Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testing bulk adding #8

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

testing bulk adding #8

wants to merge 3 commits into from

Conversation

jperelli
Copy link
Owner

this might fix #7 but need help to test it

@DonNicoJs
Copy link

@jperelli I've prepared a variant of this component for vue-people that solves exactly this, I tried to make a PR but due to vue-cli changes I can't spin the repo and since is very short I add it here:

<script>
import { findRealParent, propsBinder, L } from 'vue2-leaflet';
import 'leaflet.markercluster';

export default {
  props: {
    options: {
      type: Object,
      default: () => ({})
    },
    total: {
      type: Number,
      default: 0
    }
  },
  data () {
    return {
      ready: false
    };
  },
  mounted () {
    this.mapObject = L.markerClusterGroup(this.options);
    L.DomEvent.on(this.mapObject, this.$listeners);
    propsBinder(this, this.mapObject, this.$options.props);
    this.parentContainer = findRealParent(this.$parent);
    this._layerAdded = 0;
    this._appended = false;
    this.ready = true;
  },
  beforeDestroy () {
    if (this._appended) {
      this.parentContainer.removeLayer(this);
    }
  },
  methods: {
    addLayer (layer, alreadyAdded) {
      if (!alreadyAdded) {
        this.mapObject.addLayer(layer.mapObject);
        this._layerAdded += 1;
        this.appendToMap();
      }
    },
    removeLayer (layer, alreadyRemoved) {
      if (!alreadyRemoved) {
        this.mapObject.removeLayer(layer.mapObject);
      }
    },
    appendToMap () {
      if (this._layerAdded >= this.total && !this._appended) {
        this.parentContainer.addLayer(this);
        this._appended = true;
      }
    }
  },
  render: function (h) {
    if (this.$slots.default && this.ready) {
      return h('div', { style: { display: 'none' } }, this.$slots.default);
    }
    return null;
  }
};
</script>

The substance of this is that if the total prop is filled with the expected amount of marker the cluster is not added to the map till all the markers are added to the cluster itself.
This is a huge boost in performance:
Following screenshots are with 1500 pins
Without total prop wired ( behave as normal cluster)
screenshot 2018-12-11 at 9 51 25

With total prop wired:
screenshot 2018-12-11 at 9 52 06

Side note: you will need to either use the latest vue2-leaflet beta version or write a dummy function for setTotal I hope this helps!

@jperelli
Copy link
Owner Author

@lordfuoco awesome! I'll try to use your code and update this library properly. Thanks for sharing this!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bulk adding and removing Markers
2 participants