How to access variables/objects from "Web browser" with buttons?

I have a custom Mapbox map built in the page with the help of “Web browser”. It is a simple vanilla js map with a global variable MAP. I want to access this variable with buttons. So for example on button click call "MAP.setCenter() " etc.

Is this possible? Thanks

HI @benderlio

Unfortunately, it’s not possible to inject javascript function to inner content of a Web Browser Asset.

However, instead of using a Web Browser Asset, I recommend you to use a Map Collection Asset. It’s based on Mapbox too and comes with a set of actions for you to manipulate it directly from your experience.

In that case, the action that may help you is

Set viewport: Set current map viewport

  • Latitude
  • Longitude
  • Zoom

Kind regards,

Alex.

1 Like

but is it possible to somehow change the URL in ‘web browser’ component but do not reload the page.
like window.history.pushState('page2', 'Title', '/page2.php');

Hi Alex. How about a HTML frame rather than a browser asset? Is it possible in that asset?

You can change the URL or a Web Browser using actions provided with the asset itself.
In that case, use the Open URL one.

Needs to be tested but to be honest, I always try to use as less code as possible. Especially when there is already a Collection (in that case, Map) built-in, that fulfill my needs with its actions (in that case, Set viewport).

1 Like

we have a complex mapbox map with custom API calls, filters etc. there is no way to use the ‘Map Collection’ as it functionality is insufficient.
As I understand Open URL will reload the page with the new address.
So maybe there are any hacks to access global variables? or somehow communicate with the web browser component?