Generate territories¶
Generate a number of polygon territories from a list of coordinates and display them on the map.
To generate one territory, a minimum of 3 coordinates are needed; so remember that the number of coordinates should be at least 3 times the number of territories that you want to create. If the number of territories to be created is not specified, the algorithm will determine how many should be created.
Use case¶
When having many locations to visit, it is better if first you divide them by territories and then you can create optimizations with the stops from each territory.
How to use the sample¶
First, get an API key token, see the Getting Started guide.
Download the Maps & Navigation SDK for C++ archive file for Linux or WindowsWhen you run the sample, a list of territories will be returned and showed on the map.
How it works¶
Create a
CoordinatesList
and add all the Coordinates.Create a
ProgressListener
,vrp::Service
andvrp::Territorylist
, in which the territories will be returned.Call the
generateTerritories()
method fromvrp::Service
using the lists from 2.) and 1.), specify the number of territories that you want to create and the progress listener.Once the operation completes, the list from 2.) will contain the generated territories.
To display the stops and routes on the map¶
Create a
MapServiceListener
,OpenGLContext
andMapView
.Create a
MarkerCollection
of typePoint
and addCoordinatesList
from above.Create a
MarkerCollectionDisplaySettings
and set thepointsGroupingZoomLevel
to0
, to not group the points on the map.Set the newly created
MarkerCollection
in the markers collections of the map view preferences, together with theMarkerCollectionDisplaySettings
.Instruct the
MapView
to center on theMarkerCollection
’s area.For each territory create a
MarkerCollection
and aMarkerCollectionDisplaySettings
. In theMarkerCollection
add the data of the territory and in theMarkerCollectionDisplaySettings
set the territory’s color to thepolygonFillColor
.Set the all the newly created
MarkerCollection
in the markers collections of the map view preferences, together with theMarkerCollectionDisplaySettings
.Allow the application to run until the map view is fully loaded.