manubb / Leaflet.PixiOverlay

Bring Pixi.js power to Leaflet maps
MIT License
463 stars 85 forks source link

Example for adding markers dynamically #57

Open hokiepokedad2 opened 3 years ago

hokiepokedad2 commented 3 years ago

Hello there. Is there an example in the docs on how to add or remove markers dynamically after the map and layers have been rendered? For instance, after a specified interval, I'd like to check a datasource for any changes. If a new element is added in the source, I'd like to add that as a marker to the map. Same for the inverse.

I tried looking in the docs, googling and examples but couldn't find anything. Any tips?

kamilcglr commented 3 years ago

Hi @hokiepokedad2, did you succeed? I'm in the same case I don't understand how to remove the old markers.

azzahrah commented 3 years ago

@hokiepokedad2

  1. create sprinte var marker = new PIXI.Sprite(markerTexture);
  2. add to Container pixiContainer.addChild(marker);
  3. to remove/hide, just set sprinte to visible=false, or visible=true opposite
  4. don't forget to call renderer.render(pixiContainer);