Hi.
Thank you very much for the new DevExpress 24.2.5 version as now we can get the Azure map service to create optimised routes.
However when don't want to optimize the route the application is crashing. Either setting computeBestOrder = false or not setting it at all, getting NullReferenceException. Even tried to set the computeBestOrder = false by also setting routetype = eco, just in case requires both of them even if the Microsoft documentation says that's not needed. (see attached image)
Here is a code sample for the logic statement. The language used is Oxygene (Objective Pascal)
if aSelectedOptimization <> 'None' then
begin
lAzureRouteOptions.CustomParameters.Add('routetype', aSelectedOptimization.ToLower);
lAzureRouteOptions.CustomParameters.Add('computeBestOrder', 'true');
end
else begin
//lAzureRouteOptions.CustomParameters.Add('routetype','eco');
lAzureRouteOptions.CustomParameters.Add('computeBestOrder', 'false');
end;
Not setting computeBestOrder didn't crash the application with 24.2.4 which is the previous version used when started development of the current map module. Previous version was just checking if the value is not "None" to parse the optional.
Here is the whole sub doing the work.
method D0746MapGenerator.LoadAzureMap(aInstanceId : Integer; aSiteName : String; aDepartAt : DateTime; aInstanceNode : TreeListNode; aSelectedOptimization : String := 'None');
var
lAzureRouteDataProvider : AzureRouteDataProvider := new AzureRouteDataProvider;
lAzureMapDataProviderImagery : AzureMapDataProvider := new AzureMapDataProvider;
lAzureMapDataProviderBaseHybridRoad : AzureMapDataProvider := new AzureMapDataProvider;
lRouteLocationslist : List<RouteWaypoint> := new List<RouteWaypoint>();
lRouteInfoLayer : InformationLayer := new InformationLayer();
lImageLayerImagery : ImageLayer := new ImageLayer();
lImageLayerBaseHybridRoad : ImageLayer := new ImageLayer();
lVectorItemsLayer : VectorItemsLayer;
lAzureRouteOptions : AzureRouteOptions := new AzureRouteOptions();
begin
//get the list
lRouteLocationslist := self.GetRouteLocationWaypoints(aInstanceId, aSiteName);
self.fProcessInstance := aInstanceNode; //store this for later on when handling the event to load the metadata
//clear everything
self.fMapControl.Layers.Clear;
//set the Route Data Provider
lAzureRouteDataProvider.AzureKey := ReflexAzureKey;
lAzureRouteDataProvider.RouteCalculated += AzureRouteDataProvider_OnRouteCalculated; //
lAzureRouteDataProvider.LayerItemsGenerating += AzureRouteDataProvider_LayerItemsGenerating;
lAzureMapDataProviderImagery.AzureKey := ReflexAzureKey;
lAzureMapDataProviderImagery.Tileset := AzureTileset.BaseRoad;
lAzureMapDataProviderBaseHybridRoad.AzureKey := ReflexAzureKey;
lAzureMapDataProviderBaseHybridRoad.Tileset := AzureTileset.BaseHybridRoad;
//set the information layer
lRouteInfoLayer.DataProvider := lAzureRouteDataProvider;
lRouteInfoLayer.Error += RouteInfoLayer_Error;
lImageLayerImagery.DataProvider := lAzureMapDataProviderImagery;
lImageLayerBaseHybridRoad.DataProvider := lAzureMapDataProviderBaseHybridRoad;
self.fMapControl.Layers.Add(lImageLayerImagery);
self.fMapControl.Layers.Add(lImageLayerBaseHybridRoad);
self.fMapControl.Layers.Add(lRouteInfoLayer);
lRouteInfoLayer.ItemStyle.StrokeWidth := 2;
lRouteInfoLayer.ItemStyle.Stroke := Color.DeepSkyBlue;
self.fMapControl.Zoom(8);
self.fMapControl.SetCenterPoint(new GeoPoint(self.fOriginLat, self.fOriginLon), false);
self.fMapControl.EnableRotation := false;
try
var newDepart: DateTime := new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, aDepartAt.Hour, aDepartAt.Minute, aDepartAt.Second);
lAzureRouteOptions.TravelMode := AzureTravelMode.Van;
lAzureRouteOptions.CustomParameters := new Dictionary<String,String>();
lAzureRouteOptions.CustomParameters.Add('departAt', newDepart.ToString('yyyy-MM-ddTHH:mm:ss.fffK'));
if aSelectedOptimization <> 'None' then
begin
lAzureRouteOptions.CustomParameters.Add('routetype', aSelectedOptimization.ToLower);
lAzureRouteOptions.CustomParameters.Add('computeBestOrder', 'true');
end
else begin
lAzureRouteOptions.CustomParameters.Add('routetype','eco');
lAzureRouteOptions.CustomParameters.Add('computeBestOrder', 'false');
end;
lAzureRouteDataProvider.CalculateRoute(lRouteLocationslist, lAzureRouteOptions);
except
on lError : Exception do
begin
// Handle the exception
MessageBox.Show(String.Format('An error occurred with Azure Map service {0} {1}', Environment.NewLine, lError.Message));
end;
end;
end;