Here is our problem:
Russia is very big country and eastern part of Primorsky Kray renders on the left part of the map (it is right for GIS but looks pretty ugly for financial reporting system:) ) see attached screenshot .
How can we work around of this?
We are using CylindricalEquidistant projection for map.
PSI can't attach shape file - it is pritty big for forum - 3Mb.I can send it via e-mail if you need.
It depends if there is an easy way to determine which elements you want to exclude in order to narrow the view to a different section of the file. If you can edit the shapefiles you could just delete the shapes you don't want to include in the view, or if you don't want to delete them, and can edit the DBF attributes, you could create an attribute that signals you to not include it while determining the bounding box of the elements you want to display.
In the above code I just sorted the elements by the X coordinate, and removed the outlier from the calculation of the worldRect. But you could use some other mechanism to decide which elements to not include in your calculation, but the simplest solution may just be to edit the shapefiles and remove the unwanted sections.
-Graham
Hello, Graham!
First method works like a charm. Thank you very much.
One questions though - what to do with other(more detailed) layers.Should I do same thing for each layer?
Regards,
Sergey
Its easy enough to choose a new world rect for the layer to center on a new point:
private void theLayer_Imported( object sender, Infragistics.Silverlight.Map.MapLayerImportEventArgs e) { double minX = Double.MaxValue; double minY = Double.MaxValue; double maxX = Double.MinValue; double maxY = Double.MinValue; bool hasElements = false; List<MapElement> list = new List<MapElement>(theMap.Layers[0].Elements); list.Sort( (ele, ele2) => ele.WorldRect.X.CompareTo(ele2.WorldRect.X)); bool first = true; foreach (MapElement ele in list) { if (!first) { minX = Math.Min(minX, ele.WorldRect.X); minY = Math.Min(minY, ele.WorldRect.Y); maxX = Math.Max(maxX, ele.WorldRect.X + ele.WorldRect.Width); maxY = Math.Max(maxY, ele.WorldRect.Y + ele.WorldRect.Height); hasElements = true; } else { first = false; } } if (hasElements) { theMap.Layers[0].WorldRect = new Rect(minX, minY, maxX - minX + ((maxX - minY) * .05), maxY - minY); } }
This excludes the leftmost element which is getting split by the coordinate system from the world rectange calculation for the layer, which will recenter the view on the desired elements. It extends the width of the rectangle a little bit to not cut off the rendered portion of the split element. This doesn't however solve the problem of rendering the split portion of that element in a different place. I've tried various settings to not much effect. and I think part of the problem is that the shape file considers the bounding box of that split element to include the far left portion and the far right portion of the element. So doing things like unprojecting and reprojecting with a different coordinate system aren't effective to move the left portion of that element to be flush with the rest of the elements.
Maybe you can use a shapefile tool to either move that left portion of the element, or make it a distinct element from the rest of the elements, or perhaps use a different coordinate system for the shapefile which won't cause that element to be divided. Or if you change your central meridian value the shape file editor, then perhaps it will unsplit the element in the generated shapefile.
Here's an example of the kind of things you can do to try and effect the coordinate system in the control, in case it is of use to you, but it doesn't seem to help in this instance. This sets a coordinate system on the reader to indicate that the shapes in the file are represented using that coordinate system, when they are loaded they can be unprojected from that system. Then it specifies a projection on the map control to indicate which projection to perform on the unprojected data.
<igMap:XamWebMap x:Name="theMap" > <igMap:XamWebMap.MapProjection> <igMap:MillerCylindrical /> </igMap:XamWebMap.MapProjection> <igMap:XamWebMap.Layers> <igMap:MapLayer x:Name="theLayer" Imported="theLayer_Imported"> <igMap:MapLayer.Reader> <igMap:ShapeFileReader Uri="ShapeFiles\map" > <igMap:ShapeFileReader.CoordinateSystem> <igMap:CoordinateSystem> <igMap:CoordinateSystem.Projection> <igMap:CylindricalEquidistant/> </igMap:CoordinateSystem.Projection> </igMap:CoordinateSystem> </igMap:ShapeFileReader.CoordinateSystem> </igMap:ShapeFileReader> </igMap:MapLayer.Reader> </igMap:MapLayer> </igMap:XamWebMap.Layers> </igMap:XamWebMap>
Does this help? I'll get back to you if I think of anything else that may help adjust the positioning.
Here is scan from my school book for proof of rendering correctness:)
Yes sure, map rendered correctly and this part of Russia definitely on other side of the globe :) I'm not an expert but I think that "line of ellipsoid cut" is placed in 180 degree and central pint in Greenwich (0 meridian). And what we need is simply move central point to Moscow.
PS
I've e-mailed you shp file.