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 } }
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.