Generate MapView image for use in app

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.

@rweigand I noticed the question from @deryckchan about the option to export the mapview image from within the code itself. Currently I am working on downloading a word report from the VIKTOR code and would like to put the MapView in the report. For this it would be ideal to be able to export the MapView as an image from within the code itself. Is there any possibility to do so?

If yes, I was wondering if it is also possible to do this for any views that need to be exported from child entities. In these entities the MapViews are not actively generated since as a user you would need to update the view upon entering the entity. Is there any way to export a view from a child entity?

Hi @Rutger,

At this moment it’s not possible to take a mapview image and extract it directly from the code. You could (I think) use some 3rd party packages. E.g., if you refactor your code you could generate the map image in a separate function using some package (like folium mentioned earlier) and then pipe the result of that function into a mapresult to display in a view, or save it to a figure for further use (e.g. use in a doc).

Using information of child entities is always possible through the api, so if the generation of your image depend on child specific information you could use the api to request that entity and then process as needed.

Hope that helps.

We now have a sample app for how to add WMS-layers! Source code can be found on github and a live version of the app can be found on our demo environment.

1 Like

I have repurposed this question into a feature request because i have heard this request many times before and this already contains quite some context

@adam_hood interested…

There is a workaround shared here: Snippet Wednesday! - Add maps to your Automatic Reports 🗺️