57
Views
6
Comments
Solved
[OutSystems Maps] Zoom resetting on OS Maps when location changes
outsystems-maps
Reactive icon
Forge asset by OutSystems
Application Type
Mobile

I'm trying to use the OS maps component so that my team can make a smooth transition to ODC. Right now I am having a problem with using the maps along with the location plugin provided by OS.


I have a marker that is my current location and I want the map to follow that marker keeping it in the center of the map as I move. It does this, but on the location change it will reset the zoom level back to whatever zoom level I had it for configuration. 


I want the location to update and the marker that represents my location to stay in the middle. But I want it to respect whatever zoom I had manually done prior to me moving locations. I have tried messing with some settings like setting RespectUserZoom, but that then makes it so my marker is no longer in the center when I move and I have to scroll to find it. 


I have tried looking at the OS Map API, but haven't been able to find anything yet. Maybe it's something I can set in the provider part of the object?


Any help would be really appreciated!

See attached OML


Best,

Spencer

MapLocationZoomReset.oml
UserImage.jpg
Spencer Buhler
Solution

You're right, I apologize for not writing down what I figured out earlier. I also want to clarify a little bit more about the specific problem I was having. 


I wanted to be able to set the center of the map to follow my marker after a user hit an action. Similar to how google maps does it, where you can move away from your marker but then hit a button and it brings you back to center. I was having difficulty doing this while respecting the user zoom level. 


The solution I found was on the location change event I serialized my coordinates into a JSON object and then passed it into a custom JS block with the following code. 

if(OutSystems.Maps.MapAPI.MapManager.GetMapById($parameters.MapId) != undefined)

{         try{        

          OutSystems.Maps.MapAPI.MapManager.GetMapById($parameters.MapId).features.center.refreshCenter(JSON.parse($parameters.coords));         }     catch(error){          console.log(error);         } };

And this seemed to solve my problem.

2022-11-12 11-28-30
Gonçalo Martins
Staff

Hello @Spencer Buhler 

I could not properly test your use case, but have you tried to use the RespectUserZoom parameter?

Cheers,
GM

UserImage.jpg
Spencer Buhler

Hey Goncalo appreciate your response. So the RespectUserZoom parameter does keep the zoom at the same level and I can see my marker moving around without it refreshing to the starting zoom level. 

But the problem is once I set that parameter to true it no longer keeps my marker as the center of the map. So I can effectively zoom and watch my marker go off the map where instead I want it to follow me at my desired zoom level.


Thoughts?

UserImage.jpg
Spencer Buhler

I figured out a workaround, but I had to use some of the map object's private methods in custom JS to do it. I'm going to add it as a suggestion to the forge component to be included in the API.

2022-11-12 11-28-30
Gonçalo Martins
Staff

Hi @Spencer Buhler 

Noticed you have marked your message as the solution but you didn't share it so it can be used by other community members.

Also, I suggest you submit a pull request to the OutSystems Maps GitHub repository for that high-code API you're mentioning. 
The team will always try to review it asap and add it to the next version when it makes sense and you'll get the badge for OS Component Contributor 😎

Cheers,
GM

UserImage.jpg
Spencer Buhler
Solution

You're right, I apologize for not writing down what I figured out earlier. I also want to clarify a little bit more about the specific problem I was having. 


I wanted to be able to set the center of the map to follow my marker after a user hit an action. Similar to how google maps does it, where you can move away from your marker but then hit a button and it brings you back to center. I was having difficulty doing this while respecting the user zoom level. 


The solution I found was on the location change event I serialized my coordinates into a JSON object and then passed it into a custom JS block with the following code. 

if(OutSystems.Maps.MapAPI.MapManager.GetMapById($parameters.MapId) != undefined)

{         try{        

          OutSystems.Maps.MapAPI.MapManager.GetMapById($parameters.MapId).features.center.refreshCenter(JSON.parse($parameters.coords));         }     catch(error){          console.log(error);         } };

And this seemed to solve my problem.

2022-11-12 11-28-30
Gonçalo Martins
Staff

Hi @Spencer Buhler 

Thank you for getting back to this use case and sharing your solution with other community members.
If one day you're willing to contribute to the project, feel free to submit a pull request to the OutSystems Maps GitHub repository for that high-code API you shared. 
The team will always try to review it asap and add it to the next version when it makes sense and you'll get the badge for OS Component Contributor 😎 

Cheers,
GM

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