c# WPF example of Geometry Layer

Within this forum we want to offer discussions all around our .NET based Map control including all .Net-language specific questions concerning calls of the xServer-API. Attention: xServer-relevant concepts can be found in further forums such as xRoute or xTour.
Post Reply
User avatar
danper
Posts: 19
Joined: Mon Apr 28, 2014 8:16 am

c# WPF example of Geometry Layer

Post by danper »

Hi,

I need an adaption of the example in the CookBook about the use of GeometryLayer form Java to c# WPF.
The code below unfortunately doesn't show the polyline:


xserver.GeometryOption[] test_geometryOptions = new xserver.GeometryOption[] {
new xserver.GeometryOption { option = xserver.GeometryOptions.BORDERCOLOR, value = rgbToColorString(0,128,255)},
new xserver.GeometryOption { option = xserver.GeometryOptions.FILLCOLOR, value = rgbToColorString(255,0,0)},
new xserver.GeometryOption { option = xserver.GeometryOptions.FILLALPHA, value = "200"}, // 0-255
new xserver.GeometryOption { option = xserver.GeometryOptions.AUTOCENTEROBJECTS, value = "1"} // 0-255
};

xserver.PlainPoint[] test_points = new xserver.PlainPoint[] {
new xserver.PlainPoint { x = 7.06654212202759, y = 41.3049992893457 },
new xserver.PlainPoint { x = 10.7403702470276, y = 41.2521586885924 },
new xserver.PlainPoint { x = 10.7052139970276, y = 38.6520066768626 },
new xserver.PlainPoint { x = 7.52357337202759, y = 38.5970748172508 },
new xserver.PlainPoint { x = 7.57630774702759, y = 41.1728175884917 }
};

xserver.PlainLinearRing test_plainLinearRing = new xserver.PlainLinearRing();
test_plainLinearRing.wrappedPoints = test_points;

xserver.Polygon test_polygon = new xserver.Polygon();

test_polygon.polygon = new xserver.PlainPolygon();

test_polygon.polygon.wrappedLinearRings = new xserver.PlainLinearRing[] { test_plainLinearRing };

xserver.Point point = new xserver.Point { point = new xserver.PlainPoint { x = 7.06654212202759, y = 41.3049992893457 } };

xserver.Geometry test_geometry = new xserver.Geometry {
description = "test_geometry",
id = 0,
geometry = test_polygon,
referencePoint = point
};

xserver.Geometries test_geometries = new xserver.Geometries();
test_geometries.wrappedGeometries = new xserver.Geometry[] { test_geometry };
test_geometries.wrappedOptions = test_geometryOptions;

xserver.GeometryLayer layer = new xserver.GeometryLayer {
name = "test_geometry_Layer",
drawPriority = 150,
visible = true,
wrappedGeometries = new xserver.Geometries[] { test_geometries },
objectInfos = xserver.ObjectInfoType.GEOMETRY
};



thanks in advance and Kind Regards
Daniele
Daniele Perella
Solution Engineer
PTV ITALIA Logistics
User avatar
Oliver Heilig
Posts: 160
Joined: Tue May 13, 2014 12:10 pm
Location: Karlsruhe, Germany
Contact:

Re: c# WPF example of Geometry Layer

Post by Oliver Heilig »

Hi Daniele,

this is a common misconception with xMapServer and xServer.NET. The xMapServer GeometryLayer is a part of the xMapServer WSDL. The GeometryLayer can be used to create static map images with custom content on the server-side. However if you use the xServer.NET widget, you typically render your custom content client-side. The client-side equivalent to the GeometryLayer is the xServer.NET ShapeLayer. So you should look at the xServer.NET ShapeLayer docs and samples.

Regards
Oliver
Oliver Heilig
Chief Developer Logistic Services
PTV GROUP - Germany

https://github.com/oliverheilig/
User avatar
danper
Posts: 19
Joined: Mon Apr 28, 2014 8:16 am

Re: c# WPF example of Geometry Layer

Post by danper »

Hi Oliver,

thanks for this clarification. The shape layer is ok, the only problem is how to add an own shape layer, making it visible on the map but not in the control layer widget. is it possible?


Regards,

Daniele
Daniele Perella
Solution Engineer
PTV ITALIA Logistics
User avatar
Oliver Heilig
Posts: 160
Joined: Tue May 13, 2014 12:10 pm
Location: Karlsruhe, Germany
Contact:

Re: c# WPF example of Geometry Layer

Post by Oliver Heilig »

In this case the only option would be to add an underlying ShapeCanvas directly to the map, without using a layer. It is a bit hackish, but works

Code: Select all

// get the map view containing the content
var mapView = Ptv.XServer.Controls.Map.Tools.MapElementExtensions.FindChild<MapView>(Map);

// initialize shape canvas
var shapes = new ObservableCollection<FrameworkElement>();
var sc = new ShapeCanvas(mapView, shapes, "EPSG:4326", false);
Canvas.SetZIndex(sc, 100000000); // set it tomost

// add shape to shape collection
var pin = new Pin();
pin.Width = pin.Height = 30;
ShapeCanvas.SetLocation(pin, new System.Windows.Point(8.4, 49));
ShapeCanvas.SetAnchor(pin, LocationAnchor.RightBottom);
shapes.Add(pin);
Oliver Heilig
Chief Developer Logistic Services
PTV GROUP - Germany

https://github.com/oliverheilig/
User avatar
danper
Posts: 19
Joined: Mon Apr 28, 2014 8:16 am

Re: c# WPF example of Geometry Layer

Post by danper »

Great...it works like a charm.

Many Thanks,

Daniele
Daniele Perella
Solution Engineer
PTV ITALIA Logistics
Post Reply