Get map bounds
Question
Application Type
Reactive

Hi All,

I need to get the map bounds.

This is the JS am using,

setTimeout(function(){

    mapContainerId = (document.getElementById($parameters.MapId)).getElementsByClassName("map-container")[0].id;

    map = osGoogleMap.getMapObject(mapContainerId);

    var bounds = map.getBounds();

    var southWest = bounds.getSouthWest();

    var northEast = bounds.getNorthEast();

},100);


Am getting an error in console."map.getBounds is not a function".

Can anyone help me resolve this.


Thanks in advance,

Wasim Khan S

mvp_badge
MVP

Hi Wasim,

It seems "osGoogleMap" is not the right way to get the map object, per this post. If you get a "map.getBounds" is not a function error, it means that whatever object osGoogleMap.getMapObject returns does not contain a function called "getBounds". You could also use the browser's devtools to inspect what map is for kind of object.

Hi,

Can I get screenshot of dev tool, where to inspect what map is for kind of object?

Thanks,

Wasim Khan S

mvp_badge
MVP

Hi Wasim,

The development tools are standard Chrome, Edge and FireFox tools that you an access by pressing F12 in the browser.

Hi,

Give a name to the map in Service studio, then pass that id of the map to your JS node and try this:

setTimeout(function(){

   var map = MapAPI.MapManager.GetMapById(YourMapIdInput).provider;

var bounds = map.getBounds();

    var southWest = bounds.getSouthWest();

    var northEast = bounds.getNorthEast();


},100);



Let me know if this helped.
Cheers,
Paulo

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.