tombatossals / angular-leaflet-directive

AngularJS directive to embed an interact with maps managed by Leaflet library
http://tombatossals.github.io/angular-leaflet-directive
MIT License
1.5k stars 635 forks source link

Changing cotrol position #1027

Closed DDroll closed 9 years ago

DDroll commented 9 years ago

Is there is any way to change default layer control position? Setted through 'layers' attribute.

srthurman commented 9 years ago

You can change the position for a control with the "position" option, as with a plain-old leaflet map. Example:

$scope.controls = {
     scale: {position: 'topleft'}
};
lavahot commented 9 years ago

I was just wondering this myself. Thanks @srthurman!

EDIT: So to do what @DDroll is asking, would you do

$scope.controls = {
    layers: {position: 'topleft'}
};

and then

<leaflet controls="controls"></leaflet>
lavahot commented 9 years ago

No, the controls property only contains draw, scale, fullscreen, search, custom, and minimap properties.

DDroll commented 9 years ago

$scope.controls = { layers: {position: 'topleft'} } does not works) After little reading of directive source code i've tryed this one: defaults: { controls : { layers : {position : 'bottomleft'}}} and added 'defaults' attribute to tpl, but after that layers control just disappears without any errors in console:) . There is .setPosition metod with controls, but it is unclear, where to i should to apply it. The pot of my ideas is showing its bottom)

srthurman commented 9 years ago

Try putting this in your controller. I'm making a directive, so I had luck with the following in the link option as well. You might not have to put it in the listener for map load, but visually that looked best (I saw the layer control jump from the original top right to the new position in other cases).

$scope.$on('leafletDirectiveMap.load', function(event, args) {
    var layerPos = {
        controls: {
            layers: {
                visible: true,
                position: 'topleft',
                collapsed: true,
            },
        }
    };
    leafletMapDefaults.setDefaults(layerPos, '');
});
DDroll commented 9 years ago

@srthurman, great thx, visible attribute is that, what i'm lost. Now it works even without map directive load event listener. Im just define

$scope.dafaults = controls: {
     layers: {
        visible: true,
        position: 'topleft',
        collapsed: true,
    },
 }

and then

<leaflet defaults="defaults">

May be, it'll be valuable for solving your search control problem (and helps to avoid initial control blinking)