I have spent the last two days trying to incorporate Bing Maps with a xhape file. I have read and tried all of the postings that I have found on your site. And I am still not able to merge my shape file into the Bing Map using the Infragistics xamMap control.
I would love to send you the pdf file that I am using, however, due to your rile limitations,. I am unable to do so. The shape file that I am using is the Oregon School District shape file that is available from http://navigator.state.or.us/sdl/data/shapefile/k100/schooldistricts.zip
Is there something wrong with this shape file? Can you merge the shape file with the Bing Map? If so, could you send me the front and back in code to do so?
Thanks
I assume you have to set XamMap's WindowRect and WorldRect. Try the following code:
In XAML:
<igMap:XamMap x:Name="xamMap" > <igMap:MapNavigationPane x:Name="nav" Margin="260, 180, 10, 10" igControls:XamDock.Edge="InsideRight" /> <igMap:XamMap.Layers> <igMap:MapLayer> <igMap:MapLayer.Reader> <igMap:ShapeFileReader Uri="ShapeFiles/school/schooldistricts"> <igMap:ShapeFileReader.CoordinateSystem> <igMap:CoordinateSystem UnitType="FT" FalseEasting="1312335.958" FalseNorthing="0.0" > <igMap:CoordinateSystem.Projection> <igMap:LambertConformalConic EllipsoidType="GRS1980" CentralMeridian="-120.5" StandardParallelNorth="43.0" StandardParallelSouth="45.5" LatitudeOrigin="41.75" /> </igMap:CoordinateSystem.Projection> </igMap:CoordinateSystem> </igMap:ShapeFileReader.CoordinateSystem> </igMap:ShapeFileReader> </igMap:MapLayer.Reader> </igMap:MapLayer>
</igMap:XamMap.Layers></igMap:XamMap>
In Code behind:
private void Page_Loaded(object sender, RoutedEventArgs e){ InitImageryService(); InitMapCoordinates();}
private void InitImageryService(){ ImageryMetadataRequest mapImgRequest = new ImageryMetadataRequest();
mapImgRequest.Credentials = new Credentials(); mapImgRequest.Credentials.ApplicationId = "BING_MAP_KEY";
mapImgRequest.Style = MapStyle.Road; var imgService = new ImageryServiceClient(); imgService.GetImageryMetadataCompleted += imgService_GetImageryMetadataCompleted; imgService.GetImageryMetadataAsync(mapImgRequest);}
private void imgService_GetImageryMetadataCompleted(object sender, VEImageryServiceReference.GetImageryMetadataCompletedEventArgs e){ // set map tile source for the XamMap control xamMap.MapTileSource = new Infragistics.Controls.Maps.BingMapsTileSource() { TilePath = e.Result.Results[0].ImageUri, SubDomains = new ObservableCollection<string>(e.Result.Results[0].ImageUriSubdomains) };}
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 = 80;
// Change the map control's WindowRect and WorldRect this.xamMap.WindowRect = this.xamMap.WorldRect = winRect;}
Regards,
Ivan Kotev
This works really great!! Thanks!!
Next question: I am having trouble getting it to zoom in. Is there something that I am missing?
Hi flowerdj
Please try with the following code snippet:
<igMap:ShapeFileReader Uri="ShapeFiles/school/schooldistricts"> <igMap:ShapeFileReader.CoordinateSystem> <igMap:CoordinateSystem UnitType="FT" FalseEasting="1312335.958" FalseNorthing="0.0" > <igMap:CoordinateSystem.Projection> <igMap:LambertConformalConic EllipsoidType="GRS1980" CentralMeridian="-120.5" StandardParallelNorth="43.0" StandardParallelSouth="45.5" LatitudeOrigin="41.75" /> </igMap:CoordinateSystem.Projection> </igMap:CoordinateSystem> </igMap:ShapeFileReader.CoordinateSystem></igMap:ShapeFileReader></igMap:MapLayer.Reader>
The information about shapefile's coordinate system and projection is stored in the .prj file. Ufortunately we don't read that file, but you can open it notepad and manually set data as in the above sample. The result is:
flowerdj,
I am looking into this and will keep you updated here on my findings.
Thanks,