Can the xamMap control be used for the ESRI REST Service?
I am using the following REST for their maps:
http://server.arcgisonline.com/ArcGIS/rest/services/NGS_Topo_US_2D/MapServer
Thanks
flowerdj,
As I mentioned in the support case you have opened, this support is coming in v11.1, planned for May release.
As an interim work-around, Engineering has provided the following:
Please find attached the ESRI Tile source. To setup the XamMap, you can use the following code with the attached file if you want to use only the ESRI REST service, but if your goal is to overlay a shapefile or add MapElements (SurfaceElement, SymbolElement or PathElement) then you will need to wait for the 11.1 release:
<Grid x:Name="LayoutRoot" Background="White">
<ig:XamMap Name="igMap" Loaded="igMap_Loaded" MapProjectionType="SphericalMercator">
<ig:XamMap.MapTileSource>
<local:ESRIMapTileSource />
</ig:XamMap.MapTileSource>
</ig:XamMap>
</Grid>
public partial class MainPage : UserControl
{
public MainPage()
InitializeComponent();
}
private void InitMapCoordinates()
// define world dimensions
var worldTopLeft = new Point(-180, 90);
var worldBottomRight = new Point(180, -90);
// Convert Geodetic to Cartesian coordinates
var winTopLeft = this.igMap.MapProjection.ProjectToMap(worldTopLeft);
var winBottomRight = this.igMap.MapProjection.ProjectToMap(worldBottomRight);
// Create Rect structure the map control's WindowRect and WorldRect
var 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.igMap.IsAutoWorldRect = false;
this.igMap.WindowZoomMaximum = 80;
// Change the map control's WindowRect and WorldRect
this.igMap.WindowRect = this.igMap.WorldRect = winRect;
private void igMap_Loaded(object sender, RoutedEventArgs e)
InitMapCoordinates();
Thanks,
Has the new release come out yet?
Hi,
I'd like to do a similar thing as grabah above.
I have a code-behind function which gets called during Map_Loaded,
<igMap:XamMap x:Name="map" Loaded="map_Loaded" >
<igMap:XamMap.Layers>
<igMap:MapLayer x:Name="WorldTopoLayer" IsSensitive="False" ShadowFill="Transparent" />
</igMap:XamMap.Layers> </igMap:XamMap>
private void map_Loaded(object sender, RoutedEventArgs e) {
AddPictureToMap("WashingtonTopoLayer", "../img/washington-bw.png", "", Settings.GPSTopLeft.X, Settings.GPSTopLeft.Y, Settings.GPSBottomRight.X, Settings.GPSBottomRight.Y);
private void AddPictureToMap(string layerName, String fileContents, String myCaption, double left, double top, double right, double bottom) { if (map == null || map.Layers[layerName] == null) return; // Polyline collection to hold points for shape var lines = new MapPolylineCollection(); var points = new List<Point>(); // Points to make the shape points.Add(new Point(left, top)); points.Add(new Point(right, top)); points.Add(new Point(right, bottom)); points.Add(new Point(left, bottom)); // Convert Geodetic to RelativeCartesian coordinates lines.Add(map.MapProjection.ProjectToMap(points)); var b = new ImageBrush(); b.Opacity = 1; b.Stretch = Stretch.UniformToFill; //tried different settings here: [Stretch.None (no picture shows up), the rest of them have the same problem] if (!string.IsNullOrEmpty(fileContents) && fileContents.StartsWith("../")) b.ImageSource = new BitmapImage(new Uri(fileContents, UriKind.Relative)); // Create surface element and position shape using polylines var surfaceElement = new SurfaceElement { Polylines = lines, Fill = b, Caption = myCaption, StrokeThickness = 0, Name = myCaption }; surfaceElement.ShadowFill = new SolidColorBrush(Colors.Transparent); map.Layers[layerName].Elements.Add(surfaceElement); Rect worldRect = surfaceElement.WorldRect; worldRect = lines.GetWorldRect(); surfaceElement.WorldRect = worldRect; }
this currently works... except that when you try to PAN so that the surface element goes OFF the screen, then instead of going off the screen nicely, the surface element's Fill (ImageBrush) Stretches the Image so that it fits in the remaining portion of the screen (washington gets squashed, but points and lines correctly stay at their GPS coordinates - off the screen). Please help!
Hello Will,
Thank you for your post. I have been looking into it and it seems like that I am missing something in your scenario, so if this is still an issue for you, could you please send an isolated sample project, where the issue is reproduced, so I can investigate it further for you.
Looking forward for your reply.
Hi Stefan,
Thanks for looking into this.Really what I'd like is for a surface element's Image Fill to stay stretched to the surface element's GPS/mapped position, not the screen itself.But right now, the SurfaceElement's Image Fill looks like it gets re-stretched when you try to pan or zoom the surface element partially off the screen.
One potential avenue that I've investigated would be to create a Shapefile from my washington image. But eventually I'd like to write bitmaps and update the image dynamically, changing them several times per second, in which case creating a shapefile becomes highly innefficient (if it's even possible to do at runtime?). So is there a way to stop the surface element from re-stretching on panning the element half-way off the screen?My Solution.Zip
How to reproduce the error/situation:1. load my project & run it2. click and drag to pan the windowView so that the map goes half-way "off the screen".3. Instead of going off the screen (and keeping the same stretch as when loaded), the imagefill gets re-stretched to fit on the screen. :(
Thanks for your time,
-Will
I think this *may* be a similar problem that user:dalereed was experiencing http://es.infragistics.com/community/forums/t/54545.aspx
Unfortunately the surface element is being clipped when it goes out of bounds so using an image brush in this manner will cause the image to get squashed when the surface element is partly occluded.
To support your request we may need to introduce a type of element that does not get clipped by the map boundary in this manner. I would recommend making a feature request.
In the meantime I'll see if there is some other way to satisfy your request, but it may not be possible without additional feature work.
-Graham