Trying to center or clear a map

Good day.

I'm trying to center a map. I have two scenarios one is where I have X markers that I add to the map and then want to fit the map so that the markers shows on the edges of the map. At the moment it zooms out very far and does not even show any of the markers. I use the FitMapToBounds action to attempt to fit and centre it.

The other scenario is that I add directions to a map and want to remove them from the map. When I add the RemoveDirectionsFromMap action I get an exception thrown. Indicating a null reference.

Any help would be appreciated.
Hi Jean-Pierre,

2 things may be happening on the FitToBounds usage, according to your description of the symptoms:
  • Can you make sure there's no weird marker, like one in the Gulf of Guinea (lat=0, lon=0)?
  • Are you using the FitToBounds correctly? You need to create a BoundId first, then add all markers and for each register the marker as part of that bound, and then fit the map to that bound group.

Try doing the code above in the preparation of your page.

About the second issue, without knowing more of your code, it's going to be difficult to help, but... *going in blindfolded* it may be the case that you are refreshing the div which contains the map. When doing this, the DOM structure is affected and the javascript variables, once valid, may be now rendered useless.

I've also seen this issue before also when trying to run specific actions of the google maps component before the map was completely instanciated.

Hope this helps.

Kind Regards,
João Grazina

I believe I've done what you suggested in my preparation. I don't see any weird markers at all. The weird thing is wen I create it for the first time. It all works. Subsequently when I refresh the page it centers in a strange place. The centering does not work the moment I add directions. The directions stay there even when the logic does not put it in (but then the centering work) as per the attached file. I need to refresh the page to get rid of it. .

My Bounds variable has a value of "MultipleMarkersBounds" not sure if this makes a difference.

On the second issue as soon as I insert the remove directions from map component I then get "An exception occurred in the client script.<br> Error: Unable to get property 'renderer' of undefined or null reference"

If tried to debug it to see which component it is, but the error only comes once the screen loads. Maybe its the DOM structure.

Please let me know what you think.

Thanks for the help so far.

Hi Jean-Pierre, 

You didn't get to attach the file. Maybe I can look at it if you do.

Kind Regards,
João Grazina
Here is the file.