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

Add ability to show controls #12

Open
DynamiteGoesBoom opened this issue Sep 11, 2024 · 2 comments
Open

Add ability to show controls #12

DynamiteGoesBoom opened this issue Sep 11, 2024 · 2 comments

Comments

@DynamiteGoesBoom
Copy link

DynamiteGoesBoom commented Sep 11, 2024

Like the Google Maps' plugin already has, it would be awesome if we could control whether or not the mapbox map had controls.

I'm not sure what the API would look like for this but I'm currently passing this options object into the {{ mapbox.map(locations, options).tag() }} like so:

{% set options = {
    'id': 'locations-map',
    'popupTemplate': '_molecules/embeds/embed--popup.twig',
    'mapOptions': {
		'attributionControl': true,
        'scrollZoom': false,
		'dragPan': true,
		'keyboard': true,
		'style': 'mapbox://styles/mapbox/navigation-day-v1',
		'trackResize': true,
		'cooperativeGestures': true,
		'showCompass': true,
		'boxZoom': true,
    },
	'markerOptions': {
		'compact': true,
	},
	'height': 480,
} %}

Thanks again!

@DynamiteGoesBoom
Copy link
Author

@lindseydiloreto I just wanted to follow up with you on this to see if anything could be done to add controls, much like your Google Maps plugin offers. I don't need anything fancy. But having some basic controls would be lovely.

Thanks!

@DACbyJS
Copy link

DACbyJS commented Oct 25, 2024

Hey there, while we're waiting...

Via Javascript:
The instantiated MapBox Map Object is kept in the DynamicMap object return by this plugin's getMap function.
It is just not documented very clearly.

const tagCallbackOption = () => {
        const thisMap = mapbox.getMap('unique-map-id-from-map-options');

        console.log('Craft Plugin Object:');
        console.log(thisMap);

        console.log('Mapbox Gl Object inside the Craft Plugin Object:');
        console.log(thisMap._map);

        const mapboxGlMap = thisMap._map;
        mapboxGlMap.addControl(new mapboxgl.NavigationControl());
}

From there you can treat it like you need to.
In order to minimize issues, I use the 'callback' option in the plugin's tag() function to make sure the Craft plugin does its stuff first and then MapBox GL stuff after.

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

2 participants