Extract current extents on MapView and save to image

In MapView, the user can arbitrarily pan and zoom the map.

How do I:

  • Extract the coordinates of the 4 corners of the extents shown in the MapView (without requiring the user to draw a polygon)?
  • Generate a PNG (or other image format) of the current view shown on the MapView, ideally including annotations?

Hi @deryckchan, welcome to our community forum

Interesting questions you ask, especially regarding the extraction of coordinates of the extents currently shown on screen without drawing a polygon. I myself am not actually sure this is possible. I also wonder why you would need this, what is the problem you are attempting to fix? Perhaps if you give some context we can think of other ways to get to the same end result.

About generating a PNG (or other), if you click the … button on the top right of the mapview you can export the view as an image:

I would like to overlay items from an external WMS (Web Map Service) server onto the map view. To do that, I need to know what geographical extents are currently displayed on the map.

Ideally, we want to overlay a PNG with transparency (Overlapping an image to a map - Feature Requests - VIKTOR Community) but drawing points on the map can also work.

For the “Export as image” function, is there functionality to call “Export as image” from a function (e.g. as part of the actions triggered by a Download button)?

Hi @deryckchan,

Good to have some more context about what you are trying to do. We are seeing more and more questions regarding this type of GIS like functionalities for the mapview, such as yours about using an external WMS. We are already tracking an issue about this on our internal issue board, and I have added your request to that issue, giving it a bit more weight.

For now though, a good option for you might be to make use of the wide variety of existing python packages out there in combination with your VIKTOR app. For example, in this situation it is probably possible to get what you want by using Folium and then save the map figure to a html which you can display inside of a webview.

A colleague pointed me to this stack overflow question regarding the combination of Folium and WMS.

Hope this helps!

Thanks. I don’t think I’ll plunge into Folium just yet, as the advantage of Viktor is its ease of interface implementation. For my use case, the point / image overlays are optional niceties; MapView with Polygon selection is absolutely critical.