Configuring the viin_map View
The viin_map view can be used to display locations or routes on the map. Below are examples of how to configure the view for different use cases.
### Displaying Location Data
To display locations as markers on the map, you can configure the viin_map view for a model like res.partner. The view will display each partner as a marker on the map with relevant information shown in a popup.
Example of a viin_map view displaying locations:
<record id="res_partner_view_map" model="ir.ui.view">
<field name="name">res.partner.view.map</field>
<field name="model">res.partner</field>
<field name="arch" type="xml">
<viin_map res_partner="id">
<marker-popup>
<field name="name" string="Name"/>
<field name="mapping_address" string="Address"/>
</marker-popup>
</viin_map>
</field>
</record>
Explanation:
- res_partner="id": The map uses the id field from the res.partner model to locate the partner on the map.
- marker-popup: Specifies the fields to show in the marker popup, in this case, the partner’s name and mapping_address.
### Displaying Routes
To display a route between multiple waypoints, you can configure the viin_map view with the routing="true" attribute. If the polyline field is not explicitly defined, it will be automatically generated from the waypoints.
Example of a viin_map view displaying a route:
<record id="view_route_route_map" model="ir.ui.view">
<field name="name">route.route.viin_map</field>
<field name="model">route.route</field>
<field name="arch" type="xml">
<viin_map res_partner="address_from_id"
routing="true"
waypoint_field="waypoint_ids"
polyline_field="polyline">
<field name="waypoint_ids" />
<field name="polyline" />
<marker-popup>
<field name="code" string="Ref."/>
<field name="mapping_address" string="Instructions"/>
</marker-popup>
</viin_map>
</field>
</record>
Explanation:
- routing="true": Enables the route functionality, allowing the map to display a route between multiple waypoints.
- waypoint_field="waypoint_ids": Defines the field that holds the list of waypoints used to calculate the route.
- polyline_field="polyline": Optional. If omitted, the polyline will be auto-generated from the waypoints.
- field name="waypoint_ids": Displays all the waypoints on the map.
### Automatically Generating Polyline from Waypoints
When you configure a route with waypoints but do not specify a polyline field, the polyline is automatically generated based on the coordinates of the defined waypoints. This allows you to visualize the route without manually defining the polyline.
Example:
<record id="view_route_route_map_auto_polyline" model="ir.ui.view">
<field name="name">route.route.viin_map.auto_polyline</field>
<field name="model">route.route</field>
<field name="arch" type="xml">
<viin_map res_partner="address_from_id"
routing="true"
waypoint_field="waypoint_ids">
<field name="waypoint_ids" />
<marker-popup>
<field name="code" string="Ref."/>
<field name="mapping_address" string="Instructions"/>
</marker-popup>
</viin_map>
</field>
</record>
### Required Fields for Routing
When using routing="true", the following fields are required:
- waypoint_field: Defines the waypoints for the route.
- res_partner: Always mandatory in all viin_map views.
If polyline_field is not specified, it is automatically generated from the waypoints.