ember-leaflet icon indicating copy to clipboard operation
ember-leaflet copied to clipboard

Popup state

Open drwlrsn opened this issue 9 years ago • 6 comments

I was wondering if anyone had any ideas on how to reflect the popup state in the URL. For example, if I had a map with a bunch of POIs and a user clicked the marker for a particular market, it would be great if the URL would change something like /supermarkets/3424 or /supermarket/<some controller property>.

I have been digging around descending SomeCollectionLayer._childLayers[n]._childLayers[n]. This seems like the really wrong way to do this. How should I approach this problem?

drwlrsn avatar Oct 18 '14 23:10 drwlrsn

You're suggesting having a link-to inside a popup? Or clicking a popup would trigger a transition to a different route?

miguelcobain avatar Oct 18 '14 23:10 miguelcobain

Clicking a popup would trigger a transition to a different route. And then the reverse: if the app is loaded with the route, the popup is open.

drwlrsn avatar Oct 18 '14 23:10 drwlrsn

The reasoning would be to change the model through the router and make the marker react accordingly to the model.

Example:

  • enter route: /restaurants/1
  • Make a selected property in the restaurants controller to hold the currently selected restaurant. or
  • set a highlighted property to true in the restaurant 1 model
  • observe this property in your MarkerLayer subclass and act accordingly (open the popup in this case)

miguelcobain avatar Dec 02 '14 17:12 miguelcobain

What if popups were componentized as compositional components:

{{#ember-leaflet}}
  {{tile-layer tileUrl="//a.tiles.mapbox.com/v3/examples.map-zr0njcqy/{z}/{x}/{y}.png"}}
  {{#container-layer}}
    {{#each enabledLocations as |location|}}
      {{#marker-layer location=location.location}}
        {{#marker-popup}}
          <p>Some HTML content goes here, potentially including {{boundProperties}} or <button {{action "doSomething"}}>actionable elements</button> which get handled by the parent route/component.</p>
        {{/marker-popup}}
      {{/marker-layer}}
    {{/each}}
  {{/container-layer}}
{{/ember-leaflet}}

So to reflect popup content in the URL you would do:

{{#marker-popup}}
  {{outlet}}
{{/marker-popup}}

And let Ember's router take care of the rest by using nested routes.

nickiaconis avatar Mar 25 '15 22:03 nickiaconis

As you know, related: https://github.com/gabesmed/ember-leaflet/pull/98#issuecomment-78551161 Something like that is planned for future versions.

miguelcobain avatar Mar 26 '15 00:03 miguelcobain

Yep, I remember that. Basically, it solves this case with very little "heavy lifting" on EmberLeaflet's side. Plus it looks a lot cleaner and is generally more flexible than something like {{popup-marker-layer popupContent=someComputedProp}}.

This is just a thing to keep in mind when implementing those components.

nickiaconis avatar Mar 26 '15 01:03 nickiaconis