Map, Focus on selected item

Hi devs!

I am using a OptionField and a MapView. If the OptionField selection changes a new GeoPolyline is created which replaces the current GeoPolyline. I am looking for a way to also make sure that the MapView is now automatically focused on that GeoPolyline but I cannot find the right code for that. For now it will only focus on the first selection.

Is it possible to make the MapView zoom / focus on the new GeoPolyline?

code: https://github.com/breinbaas/vheightassessment

Hi Rob,

I looked into your code and this seems to be a bit of a bug on our side. I will create an issue for our frontend team to pick up.

p.s. It is not strictly necessary to create the GeoPoints and GeoPolyline to visualize a MapPolyLine. You could use the RDWGSConverter to convert from rd to lat, lon (SDK Reference - Geometry | VIKTOR Documentation)

features = []
p1 = MapPoint(*RDWGSConverter.from_rd_to_wgs((params.location.x1, params.location.y1)))
p2 = MapPoint(*RDWGSConverter.from_rd_to_wgs((params.location.x2, params.location.y2)))
l1 = MapPolyline(p1, p2)
features.append(l1)

The GeoPoint, GeoPolyline and GeoPolygon are returned in the parametrization when using the corresponding fields (GeoPointField, etc.) that allow users to interactively select points or lines on the map, for an example using these fields see the following sample app: https://github.com/viktor-platform/sample-map-view

2 Likes

For other people who might be interested;

old code

features = []  
points = self._postgres_db.get_levee_referenceline(params.levee_code) # results in List[Tuple[float, float]]
geopoints = [GeoPoint.from_rd(p) for p in points]
geoployline = GeoPolyline(*geopoints)
features.append(MapPolyline.from_geo_polyline(geoployline))
return MapResult(features)

suggested new code (tested and working off course :slight_smile: )

features = []  
points = self._postgres_db.get_levee_referenceline(params.levee_code) # results in List[Tuple[float, float]]
latlons = [MapPoint(*RDWGSConverter.from_rd_to_wgs((p[0], p[1]))) for p in points]
features.append(MapPolyline(*latlons))
return MapResult(features)

Hi, I am also starting to work wit MapView and I have the same question: when I change coordinates for my MapPoint, the map stays focused on the previous point. It would be very helpful to have a command to automatically reset the focus (and specify the zoom level). Thanks!

Hi Boudewijn,

The refocussing issue accidentally dropped of our radar, thanks for reporting again. We will look into a fix.