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

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

  
Forge Component
(14)
Published on 4 Oct by OutSystems Labs
14 votes
Published on 4 Oct 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.


Hi all,

just to thanks Ouen and Carlos the explanation! 

Help me a lot to integrate the Google API's from OS with other Google API JS codes.

Great job! Thanks!

Cheers


No problem, Gonçalo!

We aimed right from the start to have the component as open and extensible as possible, allowing people to implement custom scenarios alongside the more streamlined use-cases.

Feel free to reach out if you need help on something else or have suggestions.

Best regards,

Carlos