Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to create custom position for controls #1080

Open
12rambau opened this issue Dec 12, 2022 · 0 comments
Open

how to create custom position for controls #1080

12rambau opened this issue Dec 12, 2022 · 0 comments

Comments

@12rambau
Copy link

I would love to display my legend in the "topcenter" area of the map as all the other corners are used by buttons, and other controls as shown in this example:

Capture d’écran 2022-12-12 à 09 52 57

the problem is that the "topcenter" doesn't exist in leaflet/ipyleaflet. option A would be to customize the css of one of the existing corner but they won't be usable anymore. looking on the web I found this workaround for leaflet (https://stackoverflow.com/a/60391674/6734243):

.leaflet-center {
    left: 50%;
    transform: translate(-50%, 0%);
}

.leaflet-middle {
    top: 50%;
    position: absolute;
    z-index: 1000;
    pointer-events: none;
  transform: translate(0%, -50%);

}

.leaflet-center.leaflet-middle {
  transform: translate(-50%, -50%);
}
L.Map.include({
  _initControlPos: function () {
    var corners = this._controlCorners = {},
      l = 'leaflet-',
      container = this._controlContainer =
        L.DomUtil.create('div', l + 'control-container', this._container);

    function createCorner(vSide, hSide) {
      var className = l + vSide + ' ' + l + hSide;

      corners[vSide + hSide] = L.DomUtil.create('div', className, container);
    }

    createCorner('top', 'left');
    createCorner('top', 'right');
    createCorner('bottom', 'left');
    createCorner('bottom', 'right');

    createCorner('top', 'center');
    createCorner('middle', 'center');
    createCorner('middle', 'left');
    createCorner('middle', 'right');
    createCorner('bottom', 'center');
  }
});

//Now you have 5 new positions to use.

Is there a way I can reach this level of customization from my side ? If yes where should I add the javascript part ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant