Page 1 of 1

Drawing a route via VB.net

Posted: Fri Nov 27, 2015 8:14 am
by ggiardina
Hello,
I'm supporting a customer of ours in order to use xServer.NET via vb.net but I can't reproduce the c# example in order to draw a route using a MapPolyline. Here is what I did:

this is the xRoute call and it works well returning the correct info and linestring:
Dim route As New Route
route = XRouteWSService1.calculateRoute(wayPoints, Nothing, Nothing, resultListOption, callerContext)


this is how I get points for the polyline:
Dim points As New PointCollection
For Each pp As XRoute.PlainPoint In route.polygon.lineString.wrappedPoints
points.Add(New Point(pp.x, pp.y))
Next


and here is the routing layer creation:
Dim routePolyLine As New MapPolyline
routePolyLine.Points = points
routePolyLine.Width = 10
routePolyLine.StrokeLineJoin = PenLineJoin.Round
routePolyLine.StrokeStartLineCap = PenLineCap.Round
routePolyLine.StrokeEndLineCap = PenLineCap.Round
routePolyLine.MapStrokeThickness = 50
routePolyLine.ScaleFactor = 0.1
routePolyLine.Visibility = True
routePolyLine.Stroke = New SolidColorBrush(Color.FromRgb(255, 0, 255))

routingLayer.Priority = 4
routingLayer.Shapes.Add(routePolyLine)
routingLayer.Refresh()

FormsMap1.Layers.Add(routingLayer)


the shape layer was previously created like this:
Dim routingLayer As New ShapeLayer("Percorsi")

If I create a layer with all points in the linestring I can show them correctly but MapPolyline does not. Due to the fact I did not find anything about vb.net I kindly ask you some tips.

Thank in advance!

Regards,
Giovanni.

Re: Drawing a route via VB.net

Posted: Fri Nov 27, 2015 3:39 pm
by Oliver Heilig
Hello Giovanni,

i've added the calculation and displaying of a route to FormsMapCS and FormsMapVB at https://github.com/ptv-logistics/xservernet-bin

Image

Regards

Oliver

Re: Drawing a route via VB.net

Posted: Mon Nov 30, 2015 9:21 am
by ggiardina
Thank you very much Oliver, it works perfectly.
Is it also possible to adapt drag&drop routing in vb.net ? For sure the customer will ask for this in the next future.

Best regards,
Giovanni.

Re: Drawing a route via VB.net

Posted: Thu Dec 03, 2015 12:55 pm
by Oliver Heilig
Hi Giovanni,

yes this is possible. We have a sample in the DemoCenter that shows howto implement Drag&Drop routing with xServer.NET. But porting the whole sample to VB would be much work. An option would be to extract this code to an assembly an use this from the VB application.

I'll take a look at it tomorrow.

Oliver

Re: Drawing a route via VB.net

Posted: Fri Dec 04, 2015 4:10 pm
by Oliver Heilig
Hi Giovanni,

added a sample "RoutingVB" to https://github.com/ptv-logistics/xservernet-bin. It's a little bit rough on the edges, but shows how to add the sample code from the DemoCenter to your VB.NET application.

It would be possible to extend this to a generic interactive C#/VB router like "leaflet-routing-machine" for JavaScript http://ptv-logistics.github.io/lrm-ptv/. But this would be still some way to go :D

Oliver