Select to view content in your preferred language

Silverlight URL

1226
2
09-06-2013 03:57 AM
stevemiller
Emerging Contributor
I have the Silverlight application builder installed to serve out maps internally to our organization. What I'm trying to do is construct a url that will load the web map and zoom to a specific Lat and Lng.

"http://myserver/apps/water" loads our water system map. I'd like to load the water map and then zoom to a location defined by Lat and Lng on the map.

Thanks
Steve
0 Kudos
2 Replies
Noah-Sager
Esri Regular Contributor
Hi Steve,

One way to change or define the initial extent is in the "Map.xml" file in the Config folder of your application.

Hope this helps!

-Noah
0 Kudos
PietaSwanepoel2
Frequent Contributor
Create a new behavior tool to do this.

Example code on how to do it. I supply the application with a BBOX querystring parameter (similar to WMS definition) and zoom to the area. You can modify this to zoom to a point in stead of an extent. Coordinates must be in the same format as the definition of the map (basemap defined this)

using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Windows;
using System.Windows.Browser;
using System.Windows.Controls;
using System.Windows.Interactivity;
using System.Windows.Media.Animation;
using ESRI.ArcGIS.Client;
using ESRI.ArcGIS.Client.Extensibility;
using ESRI.ArcGIS.Client.Geometry;

namespace Behavior.Startup
{
    [Export(typeof(Behavior<Map>))]
    [DisplayName("Enable application to start with initial extent")]
    [Category("Behaviors")]
    [Description("Enable application to start with initial BBOX extent")]
    public class StartupExtentBehavior : Behavior<Map>
    {
        #region Behavior Overrides
        protected override void OnAttached()
        {
            base.OnAttached();

            MapApplication.Current.Map.Loaded += Map_Loaded;
        }

        protected override void OnDetaching()
        {
            MapApplication.Current.Map.Loaded -= Map_Loaded;
        }
        #endregion

        #region Events
        void Map_Loaded(object sender, RoutedEventArgs e)
        {
            // BBOX in format: BBOX=minx,miny,maxx,maxy: Bounding box corners (lower left, upper right) in SRS units.
            if (HtmlPage.Document != null && HtmlPage.Document.QueryString.Count > 0 && HtmlPage.Document.QueryString["BBOX"] != null)
            {
                double[] bbox = new double[4];
                var val = HtmlPage.Document.QueryString["BBOX"].ToString();
                var dd = val.Split(',').Select(x => double.Parse(x));
                int i = 0;
                foreach (double d in dd)
                {
                    bbox = d;
                    i++;
                }
                Envelope newExtent = new Envelope(bbox[0], bbox[2], bbox[2], bbox[3]);
                MapApplication.Current.Map.ZoomTo(newExtent);
            }
        }
        #endregion
    }
}
0 Kudos