Hi.
I want to display some shape files using silverlight. I wanted to use xamMap or xamWebMap. btw. what is the difference between those two? I coulnd find xamWebMap control anywhere in the toolbox (i'm using trial version if that helps) but I did found xamMap so I tried with that. Where can I find some instructions on how to start? I found gazzillion examples for xamWebMap but none for xamMap. For the beggining I want to just load simple shp file from the local disc. And also what do I have to do to use xamWebMap?
I found documentation.
but now I have whole different set of issues.
1. How do you clear loaded shape file from the xamMap. I load your usa_pl as layer 1. then later I want to delete it with xamMap.Layers.Clear(); Map stops beeing interactive but image of use still remains visible.
2. I have shape file converted from the AutoCad that simply won't display. I get no loading error. I assume its some kind of problem with coordinates.
Hi grabah,
XamWebMap was changed to XamMap, please take a look at this page for full list of 2010.2 breaking changes: http://help.infragistics.com/Help/NetAdvantage/DV/2011.1/CLR4.0/html/Breaking_Changes_2010_Volume_2.html
About issue #1 - That seems like a bug that we have recently fixed, please apply the latest service release, for more information about SR take a look at: http://es.infragistics.com/support/service-releases.aspx#ServiceReleases. After layers are removed you can set the new map's WorldRect with the following snippet:
<pre>
private void InitMapCoordinates(){ // define world dimensions Point worldTopLeft = new Point(-180, 90); Point worldBottomRight = new Point(180, -90);
// Convert Geodetic to Cartesian coordinates Point winTopLeft = this.xamMap.MapProjection.ProjectToMap(worldTopLeft); Point winBottomRight = this.xamMap.MapProjection.ProjectToMap(worldBottomRight); // Create Rect structure the map control's WindowRect and WorldRect Rect winRect = new Rect() { X = Math.Min(winTopLeft.X, winBottomRight.X), Y = Math.Min(winTopLeft.Y, winBottomRight.Y), Width = Math.Abs(winTopLeft.X - winBottomRight.X), Height = Math.Abs(winTopLeft.Y - winBottomRight.Y) }; this.xamMap.IsAutoWorldRect = false; this.xamMap.WindowZoomMaximum = 40;
// Change the map control's WindowRect and WorldRect this.xamMap.WindowRect = this.xamMap.WorldRect = winRect;}
</pre>
About issue #2 -Please check the shapefile's prj file which contains coordinate system and projection information.
Regards,
Ivan Kotev
hi.
1. thx for the explanation
2. I don't seem to have .prj file. I have .shp .dbf .sbn .sbx and .shx. I'm not shure what all those files contain or do we need them, but that's what we got after conversion. Can I send you the whole thing so you can take look at it?
just to motivate you a bit we are looking into infragistic controls for some time and if we can make this thing with shape files work I think we will buy the whole package :)
Setting EllipsoidType="WGS84" fixed the issue. SphericalMercator's EllipsoidType sets or gets the current projections's datum.
For the zooming issue try setting XamMap's WindowRect and WorldRect explicitly after shapefile is imported:
MapLayer layer = new MapLayer();
ShapeFileReader reader = new ShapeFileReader();
CoordinateSystem cord = new CoordinateSystem();SphericalMercator spMerc = new SphericalMercator();spMerc.EllipsoidType = EllipsoidType.WGS84;cord.Projection = spMerc;reader.CoordinateSystem = cord;
reader.Uri = "akcijski_koridor";DataMapping.Converter converter = new DataMapping.Converter();reader.DataMapping = converter.ConvertFromString("Caption=POLGON") as DataMapping;layer.Reader = reader;xamMap1.Layers.Add(layer);
layer.Imported += (layerSender, layerEvents) =>{ if (layerEvents.Action == MapLayerImportAction.End) { xamMap1.WindowRect = xamMap1.WorldRect = layer.WorldRect; }};
layer.ImportAsync();
Could you please check again if latest SR is applied. As a workaround try to remove it with the following code:
xamMap.Layers.RemoveAt(0);
It finally works, great! thank you very much!
so whats was the catch, EllipsoidType="WGS84"?
Im doing the loading from the code like this:
MapLayer layer = new MapLayer(); ShapeFileReader reader = new ShapeFileReader(); CoordinateSystem cord = new CoordinateSystem(); SphericalMercator spMerc = new SphericalMercator(); spMerc.EllipsoidType = EllipsoidType.WGS84; cord.Projection = spMerc; reader.CoordinateSystem = cord; reader.Uri = "akcijski_koridor"; DataMapping.Converter converter = new DataMapping.Converter(); reader.DataMapping = converter.ConvertFromString("Caption=POLGON") as DataMapping; layer.Reader = reader; xamMap1.Layers.Add(layer); layer.ImportAsync();
I still have some problems with zooming thou. When first loaded shape file is mostly centered corectly, but if I trie to replace it with some other shape in a new layer I can't get it to display properly. I guess it's becouse of the funky coordinates and world sizes in those files...
and also I updated to latest version but still problem with persisted image after all layers are clerad is here. Only after I move new layer or zoom it new shape shows up and old one dissapears.
Try the following XAML code:
<ig:XamMap> <ig:XamMap.Layers> <ig:MapLayer> <ig:MapLayer.Reader> <ig:ShapeFileReader Uri="Shapefiles/akcijski_koridor"> <ig:ShapeFileReader.CoordinateSystem> <ig:CoordinateSystem> <ig:CoordinateSystem.Projection> <ig:SphericalMercator EllipsoidType="WGS84" /> </ig:CoordinateSystem.Projection> </ig:CoordinateSystem> </ig:ShapeFileReader.CoordinateSystem>
</ig:ShapeFileReader> </ig:MapLayer.Reader> </ig:MapLayer> </ig:XamMap.Layers></ig:XamMap>
The result is:
If you want map elements to have the same Fill color you can set MapLayer's Fill property:
Fill="DodgerBlue" and FillMode="None"
it should look like this:
Yes, You can send the shapefiles and we will investigate the issue further.
Thanks,