Pricing Blog

Mapbox + custom actions

  • saillmone-1374659111878393941

    saillmone

    2 months ago

    Hello,

    I'm having a little trouble with MapBox and Custom Actions.
    I've initialized my map with a custom action, and it's working.

    Now I'd like to send data to this map to apply a filter (via a client click).
    To return the map, we need to use events, right?
    The problem is that the map keeps reinitializing and creates duplicates if I call ctx.triggerActionEvent("returnMap", mapBox);

    I tried doing an "if(mapBox) return mapBox;" but that takes the HTML block into account.

    What's the solution?

    Thanks in advance!
    Simon
    1374659112259948554-image.png
  • filip_dajkovic-1374755904414679090

    Filip Dajkovic

    2 months ago

    You can attach a custom event listener to the window object in Mapbox init action, and than call it from another custom action. Not sure if there's a better way to approach it
  • Tod-1374755907375861783

    Tod

    2 months ago

    Great job @Filip Dajkovic! Your contribution to the Nordcraft Community just made you advance to Community Level 6! 🌲
  • saillmone-1375106037568245883

    saillmone

    2 months ago

    Thanks for your feedback.
    Indeed, I made an event listener and it works wonderfully!
    1375106037346074714-image.png
  • filip_dajkovic-1375147294499799090

    Filip Dajkovic

    2 months ago

    Great, you've even made it work better for your scenario, glad to see it!