This is a simple example of how to create a network of route (GISRoutes to be precise) into the AnyLogic GIS module by code during runtime.
Let's assume there is already an ArrayList
Route Creation
//create a new GIS network and attach it to your map element
GISNetwork network = new GISNetwork(map,"myNetwork");
//add all GISPoints to this network
for(GISPoint p:locations){
network.add(p);
}
//somehow iterate through your points to create Routes between them (here just connect one after another, no cross connections)
for(int i=0;i<locations.size()-1;i++){
//create curves (neccessary for the GISRoutes)
Curve<GISMarkupSegment> curve = new Curve<>();
//create segment (neccessary for Curve)
GISMarkupSegment segment = new GISMarkupSegmentLine(locations.get(i).getLatitude(), locations.get(i).getLongitude(), locations.get(i+1).getLatitude(), locations.get(i+1).getLongitude());
curve.addSegment(segment);
curve.initialize();
network.add(new GISRoute(map,curve,locations.get(i), locations.get(i+1), true));
}
//Do not forget to initialize the network
network.initialize();
Keep in mind that in order for an Agent movement to use this newly created network, it is necessary that: - the origin - destination - and current Agents position are located on one of the GISNodes of this network, otherwise it will roam in free space or the wrong network when the moveTo-Block is used.
Conclusion
It is possible to add GISRoutes by code during runtime, but there are some pitfalls, such as the necessary network initialization. As a further step you can also create the GISNodes by code, but in this case you have to set your Agents position onto on of the GISNodes after you created them, otherwise it won't use your new network.