Page 1 of 1

c# WPF example of Geometry Layer

Posted: Mon May 23, 2016 9:29 am
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

Re: c# WPF example of Geometry Layer

Posted: Mon May 23, 2016 10:10 am
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

Re: c# WPF example of Geometry Layer

Posted: Mon May 23, 2016 10:27 am
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

Re: c# WPF example of Geometry Layer

Posted: Mon May 23, 2016 11:42 am
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);

Re: c# WPF example of Geometry Layer

Posted: Tue May 24, 2016 7:40 am
by danper
Great...it works like a charm.

Many Thanks,

Daniele