+ Reply to Thread
Results 1 to 7 of 7

Thread: How to zoom to a point in map

  1. #1
    Joby George
    Join Date
    Apr 2012
    Posts
    12
    Points
    0
    Answers Provided
    0


    0

    Default How to zoom to a point in map

    Hi

    I have created an application in silverlight using arcgis api. In that I am saving the location in map using map points.

    I got the map points while I try to save the record.

    When i try to edit the same record I want to zoom to the particular location. How can I do this

    <Grid x:Name="LayoutRoot" Margin="2">
    <Grid.Resources>
    <esri:PictureMarkerSymbol x:Key="PinPictureMarkerSymbol" Source="/UIControls.AccidentRecordForm;component/Images/Delete_2.png" />
    </Grid.Resources>
    <esri:Map MouseClick="Map_MouseClick" x:Name="MyMap">
    <esri:Map.Layers>
    <esri:ArcGISTiledMapServiceLayer Url="http://www.darb.ae/ArcGIS/rest/services/BaseMaps/DOT_StreetMap_En/MapServer"/>
    <esri:GraphicsLayer ID="MyGraphicsLayer">
    <esri:GraphicsLayer.Graphics >
    <esri:Graphic Symbol="{StaticResource PinPictureMarkerSymbol}">
    </esri:Graphic>
    </esri:GraphicsLayer.Graphics>
    </esri:GraphicsLayer>

    </esri:Map.Layers>
    </esri:Map>
    </Grid>


    MapPoint mapPoint=new MapPoint(Convert.ToDouble(crashForm.tbLocationEasting.Text), Convert.ToDouble(crashForm.tbLocationNorthing.Text));
    GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;
    Graphic graphic = new Graphic()
    {
    Geometry = mercator.FromGeographic(mapPoint),
    Symbol = LayoutRoot.Resources["PinPictureMarkerSymbol"] as Symbol
    };
    graphicsLayer.Graphics.Clear();
    graphicsLayer.Graphics.Add(graphic);

    this is the code where I add graphics to the map whle editting.

    How can I zoom or focus to this location?
    Please help.

  2. #2
    Demin Hu
    Join Date
    Apr 2010
    Posts
    136
    Points
    2
    Answers Provided
    0


    0

    Default Re: How to zoom to a point in map

    MyMap.ZoomTo ( pt);

    If you don't want to Zoom too close, you can do something like the following:
    Envelope env = new Envelope();
    env.SpatialReference = MyMap.SpatialReference;
    env.XMax = pt.X + 500;
    env.YMax = pt.Y + 500;
    env.XMin = pt.X - 500;
    env.YMin = pt.Y - 500;
    MyMap.ZoomTo(env);

  3. #3
    Jennifer Nery

    Join Date
    May 2010
    Posts
    2,449
    Points
    289
    Answers Provided
    51


    0

    Default Re: How to zoom to a point in map

    Jennifer Nery
    Software Developer
    ArcGIS API for SL/WPF/WP7

  4. #4
    Joby George
    Join Date
    Apr 2012
    Posts
    12
    Points
    0
    Answers Provided
    0


    0

    Default Re: How to zoom to a point in map

    Quote Originally Posted by deminhu View Post
    MyMap.ZoomTo ( pt);

    If you don't want to Zoom too close, you can do something like the following:
    Envelope env = new Envelope();
    env.SpatialReference = MyMap.SpatialReference;
    env.XMax = pt.X + 500;
    env.YMax = pt.Y + 500;
    env.XMin = pt.X - 500;
    env.YMin = pt.Y - 500;
    MyMap.ZoomTo(env);

    Hi deminhu,

    by using this I am able to set the focus to that point. Now I am facing an issue, that is when I trying to focus at first time without loading the map the spatial reference become null so
    It wont focus to the correct location. I also tryed to hard cord the spatial reference but the issue continues.
    Please help.

    Is there any event in map which will fire after loading the map so that I can run the code at that time?

  5. #5
    Jennifer Nery

    Join Date
    May 2010
    Posts
    2,449
    Points
    289
    Answers Provided
    51


    0

    Default Re: How to zoom to a point in map

    You can subscribe to Map.PropertyChanged (e.PropertyName == "SpatialReference") or Map.Layers.LayersInitialized event.
    Jennifer Nery
    Software Developer
    ArcGIS API for SL/WPF/WP7

  6. #6
    Morten Nielsen

    Join Date
    Oct 2009
    Posts
    1,166
    Points
    44
    Answers Provided
    7


    0
    This post is marked as the answer

    Default Re: How to zoom to a point in map

    Quote Originally Posted by joby003 View Post
    Is there any event in map which will fire after loading the map so that I can run the code at that time?
    If you want to set the extent prior to the map is ready for zooming, just set the extent instead of zooming.
    ie. myMap.Extent = myNewExtent;
    /Morten Nielsen
    ArcGIS Runtime SDK for .NET
    silverlight team blog - twitter - personal blog

  7. #7
    Joby George
    Join Date
    Apr 2012
    Posts
    12
    Points
    0
    Answers Provided
    0


    0

    Default Re: How to zoom to a point in map

    Quote Originally Posted by SharpGIS View Post
    If you want to set the extent prior to the map is ready for zooming, just set the extent instead of zooming.
    ie. myMap.Extent = myNewExtent;
    By using this I am able to solve the problem.

    focusing after initializing the layer is of no use if we want to zoom to a point before loading the map.

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts