[Google Maps] Expose the Google Map object for client javascript

[Google Maps] Expose the Google Map object for client javascript

  
Forge Component
(13)
Published on 29 Sep (11 hours ago) by OutSystems Labs
13 votes
Published on 29 Sep (11 hours ago) by OutSystems Labs

The current version does not expose the Google Map object. Is there a plan to do so for future versions? If not, how to modify the current version to expose it?

Hey, Stanley,

If I understood you correctly, you want to access the Google Maps' Map JS object that is created using the JS API, right?

Well, the component has a osGoogleMap object available, that contains references to all Maps/Markers/Events we create with the component. Each of these includes a reference to the respective Google Maps API object you are looking for. In case of Maps, you should be able to obtain it like so:

var googlesMap = osGoogleMap.getMap(<MapIdentifier>).gMap;

However, the osGoogleMap object mentioned above is not available through the console directly. To be able to reach it, you should use the platform's "RunJavaScript" action to run your code (instead of using unescaped expressions).

Is this what you were looking for? Please let us know how thing's went :).

Best regards,

Carlos Simões

Solution

Here is an example of interacting with the map using "RunJavaScript".

"(function() {

    var MapId = "+ TestMap.Id +";
    var MarkerId = "+ TextMarker.Id +";

    var TempMap = osGoogleMap.getMap(MapId).gMap;

    var TempMarker = osGoogleMap.getMap(MapId).getMarker(MarkerId).gMarker;

    TempMap.setZoom(12);

    TempMap.setCenter(TempMarker.getPosition());

})();"

There is a quirk in how you access the marker in that you have to instantiate it directly and not via the map object.

Ouen

Solution

Spot on, Ouen! That's exactly what I was aiming for!

I'd just add (I forgot to mention on my post also) that where you have TestMap.Id and TestMarker.Id, that those are the names we gave the markers, like so:

Thank you for sharing the example!

Excellent! Thanks for Ouen's example and Carlos explanation. This exactly what I am looking for.

Many thanks.