开发者

How to add a Marker to ArcGIS map (Silverlight)

I am teaching my self arcGIS maps via the Silverlight API for work, and i was trying to do a simple, place marker symbol at XY example, but darn it if I can't get it to work! I am using the following sample page as a reference, but when i go to debug the thing, my marker always ends up dead center of the map, regardless of what the MapPoint's X and Y values:

http://blogs.esri.com/dev/blogs/silverlightwpf/archive/2010/12/14/adding-gps-location-to-the-map-in-the-arcgis-api-for-windows-phone.aspx

my xaml looks as follows:

<UserControl x:Class="CustomGeometry.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.co开发者_运维技巧m/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:esri="clr-namespace:ESRI.ArcGIS.Client;assembly=ESRI.ArcGIS.Client"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">

    <Grid x:Name="LayoutRoot" Background="White">
        <esri:Map x:Name="mapWells" Loaded="mapWells_Loaded">
            <esri:ArcGISTiledMapServiceLayer x:Name="BaseLayer" ID="Base Map" Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer" />
        </esri:Map>
    </Grid>
</UserControl>

my back end code looks like the following:

  public partial class MainPage : UserControl
    {

        public MainPage()
        {
            InitializeComponent();
        }
        /// <summary>
        /// creating Wells Layer
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void mapWells_Loaded(object sender, RoutedEventArgs e)
        {
            GraphicsLayer wellsLayer = mapWells.Layers["WellsLayer"] as GraphicsLayer;
            if (wellsLayer == null)
            {
                wellsLayer = new GraphicsLayer()
                {
                    ID = "wellsLayer"
                };
                mapWells.Layers.Add(wellsLayer);

                Graphic marker = new Graphic();
                marker.Symbol = new SimpleMarkerSymbol();
                wellsLayer.Graphics.Add(marker);
            }
            // map point not being set correctly.
            MapPoint location = new MapPoint(-122.466903686523, 48.7440490722656, mapWells.SpatialReference);
            wellsLayer.Graphics[0].Geometry = location;

        }
    }

What am I doing wrong? I'm assuming it has to do with the spatialReference, but the maps spatial reference is null. Help!


Found the issue. While the walkthough example stated that the GeographicToWebMercator was optional, it clearly is not. When I replaced the line

wellsLayer.Graphics[0].Geometry = location;

with

wellsLayer.Graphics[0].Geometry = ESRI.ArcGIS.Client.Bing.Transform.GeographicToWebMercator(location);

the map marker moves to a location based upon my map point, because while the latitude and longitude might be correct to the given Spacial reference system, the bing maps system has to convert those values to something it knows how to display on the current projection.

Hope this helps others!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜