mapbox-gl-js icon indicating copy to clipboard operation
mapbox-gl-js copied to clipboard

Allow controls to be placed at top-center, bottom-center, left-center, and right-center

Open mb12 opened this issue 9 years ago • 12 comments

mapbox-gl-js version:Master

Steps to Trigger Behavior

Can you please suggest a workaround / solution for this? This is blocking switching from G Maps to Mapbox GL JS.

We need to put controls on the map at top center and bottom center. Google maps supports this and other positions for controls. You can find more details of supported positions at the link below. TOP_CENTER and BOTTOM_CENTER would unblock me.

I am hoping it just a matter of adding css. mapbox-gl.css only includes css for adding controls at the four corners.

https://developers.google.com/maps/documentation/javascript/controls

Expected Behavior

Actual Behavior

mb12 avatar Aug 20 '16 00:08 mb12

@mb12 Until this lands in master, you should be able to implement this functionality downstream by adding your own CSS rules for mapboxgl-ctrl-*-center.

lucaswoj avatar Aug 22 '16 18:08 lucaswoj

@mb12 here's a quick and dirty hack https://jsfiddle.net/wwbh6qsh/

mollymerp avatar Aug 22 '16 19:08 mollymerp

A workaround that I'm using, instead of renaming another position like the jsfiddle molly shared.

function registerControlPosition(map, positionName) {
        if (map._controlPositions[positionName]) {
            return;
        }
        var positionContainer = document.createElement('div');
        positionContainer.className = `mapboxgl-ctrl-${positionName}`;
        map._controlContainer.appendChild(positionContainer);
        map._controlPositions[positionName] = positionContainer;
    }

You just have to define css rules for mapboxgl-ctrl-${positionName}. This mutates some property of the map, so may not work in the future. I'm using v0.44.2.

hermesespinola avatar Jul 02 '18 23:07 hermesespinola

I hope there should have right-bottom, left-bottom, right-top, left-top those placed on different direction with bottom-right, bottom-left, top-right, top-left. such https://developers.google.com/maps/documentation/javascript/controls#ControlPositioning

cs09g avatar Apr 29 '19 05:04 cs09g

6 years and still nothing...

Strongleong avatar Jun 30 '22 01:06 Strongleong

+1 for more out-of-the-box options for control positioning

srgorelik avatar Dec 09 '22 15:12 srgorelik

+1

mbrammer avatar Jan 22 '23 10:01 mbrammer

+1

JulienBlancher avatar Apr 03 '23 19:04 JulienBlancher

+1

syshriki9 avatar Jul 19 '23 00:07 syshriki9

+1

AndreasAtakan avatar Feb 05 '24 13:02 AndreasAtakan