gabesmed / ember-leaflet

Ember + Leaflet = Fun with maps
gabesmed.github.io/ember-leaflet
MIT License
164 stars 35 forks source link

Manipulating the Map from the page controller #97

Open Chinow opened 9 years ago

Chinow commented 9 years ago

Hi guys,

I used your awesome addon to do add a Map into an EmberApp => https://github.com/wwoof/webapp => https://app.wwoof.fr/hosts

I ran into a couple issues so I wanted to share them with you. I wanted to use the Leaflet API to manage my map from the controller. However I was not able to access the map from the controller. Therefore I had to override an init method in the EmberLeaflet.MapView to forward the map Layer to the page controller:

export default EmberLeaflet.MapView.extend({
    [...]

    didCreateLayer: function () {

        // Get map init parameters from controller
        this._layer.setView(L.latLng(this.controller.get('lat'), this.controller.get('lon')), this.controller.get('mapZoom'), false);
        this.controller.set('mapLayer', this._layer);

        // declare moveEnd action sender
        this.moveend = function () {
            this.controller.send("mapChanged");
        };

        // continue Init
        this._super();
    }
});

Is there a better way of doing that? I think it's important to allow Map/Layer manipulation from a controller.

Also, if you want you could add a link to our App as an usage example of this addon.

Awem commented 9 years ago

Maybe a more specific example of the intended implementation would be helpful. IMHO you shouldn't access the map from the controller but bind it to controller values. Why not have a map component that has values and/or actions bound to correspondening controller values/actions? This package is currently being refactored into a component (provided as ember-cli-addon).