/// <summary>
        /// Create extent envelope
        /// </summary>
        /// <param name="envelope">Extent envelope in WGS84</param>
        /// <param name="spatialReferenceID">Map spatial reference ID</param>
        /// <returns>Extent envelope in map spatial reference</returns>
        public static ESRI.ArcGIS.Client.Geometry.Envelope CreateExtent(ESRI.ArcLogistics.Geometry.Envelope envelope,
                                                                        int?spatialReferenceID)
        {
            // Project extent to map spatial reference
            ESRI.ArcLogistics.Geometry.Point leftTop     = new ESRI.ArcLogistics.Geometry.Point(envelope.left, envelope.top);
            ESRI.ArcLogistics.Geometry.Point rightBottom = new ESRI.ArcLogistics.Geometry.Point(envelope.right, envelope.bottom);

            // Project point from WGS84 to Web Mercator if spatial reference of map is Web Mercator
            if (spatialReferenceID.HasValue)
            {
                leftTop     = WebMercatorUtil.ProjectPointToWebMercator(leftTop, spatialReferenceID.Value);
                rightBottom = WebMercatorUtil.ProjectPointToWebMercator(rightBottom, spatialReferenceID.Value);
            }

            // Create map extent envelope
            ESRI.ArcGIS.Client.Geometry.Envelope extent = new ESRI.ArcGIS.Client.Geometry.Envelope();

            extent.XMin = leftTop.X;
            extent.XMax = rightBottom.X;
            extent.YMin = rightBottom.Y;
            extent.YMax = leftTop.Y;

            // Project point from WGS84 to Web Mercator if spatial reference of map is Web Mercator
            if (spatialReferenceID.HasValue)
            {
                extent.SpatialReference = new ESRI.ArcGIS.Client.Geometry.SpatialReference(spatialReferenceID.Value);
            }

            return(extent);
        }
        public BatchGeocoding()
        {
            InitializeComponent();

            ESRI.ArcGIS.Client.Geometry.Envelope initialExtent =
                        new ESRI.ArcGIS.Client.Geometry.Envelope(
                    _mercator.FromGeographic(
                        new ESRI.ArcGIS.Client.Geometry.MapPoint(-117.387, 33.97)) as MapPoint,
                    _mercator.FromGeographic(
                        new ESRI.ArcGIS.Client.Geometry.MapPoint(-117.355, 33.988)) as MapPoint);

            initialExtent.SpatialReference = new SpatialReference(102100);

            MyMap.Extent = initialExtent;

            _locatorTask = new Locator("http://serverapps101.esri.com/arcgis/rest/services/USA_Geocode/GeocodeServer");
            _locatorTask.AddressesToLocationsCompleted += _locatorTask_AddressesToLocationsCompleted;
            _locatorTask.Failed += LocatorTask_Failed;

            geocodedResults = MyMap.Layers["LocationGraphicsLayer"] as GraphicsLayer;

            //List of addresses to geocode
            batchaddresses.Add(new Dictionary<string, string> { { "Street", "4409 Redwood Dr" }, { "Zip", "92501" } });
            batchaddresses.Add(new Dictionary<string, string> { { "Street", "3758 Cedar St" }, { "Zip", "92501" } });
            batchaddresses.Add(new Dictionary<string, string> { { "Street", "3486 Orange St" }, { "Zip", "92501" } });
            batchaddresses.Add(new Dictionary<string, string> { { "Street", "2999 4th St" }, { "Zip", "92507" } });
            batchaddresses.Add(new Dictionary<string, string> { { "Street", "3685 10th St" }, { "Zip", "92501" } });

            AddressListbox.ItemsSource = batchaddresses;
        }
        public AreasAndLengths()
        {
            InitializeComponent();

            ESRI.ArcGIS.Client.Geometry.Envelope initialExtent =
                    new ESRI.ArcGIS.Client.Geometry.Envelope(
                mercator.FromGeographic(
                    new ESRI.ArcGIS.Client.Geometry.MapPoint(-130, 20)) as MapPoint,
                mercator.FromGeographic(
                    new ESRI.ArcGIS.Client.Geometry.MapPoint(-65, 55)) as MapPoint);

            initialExtent.SpatialReference = new SpatialReference(102100);

            MyMap.Extent = initialExtent;

            MyDrawObject = new Draw(MyMap)
            {
                DrawMode = DrawMode.Polygon,
                IsEnabled = true,
                FillSymbol = LayoutRoot.Resources["DefaultFillSymbol"] as ESRI.ArcGIS.Client.Symbols.FillSymbol
            };
            MyDrawObject.DrawComplete += MyDrawObject_DrawComplete;
            MyDrawObject.DrawBegin += MyDrawObject_DrawBegin;

            calculationTypeCombo.ItemsSource = Enum.GetValues(typeof(CalculationType));
            calculationTypeCombo.SelectedIndex = 0;
        }
Example #4
0
        public AreaAndLengths()
        {
            InitializeComponent();
            ESRI.ArcGIS.Client.Geometry.Envelope initialExtent =
                new ESRI.ArcGIS.Client.Geometry.Envelope(
                    ESRI.ArcGIS.Client.Bing.Transform.GeographicToWebMercator(
                        new ESRI.ArcGIS.Client.Geometry.MapPoint(-130, 20)),
                    ESRI.ArcGIS.Client.Bing.Transform.GeographicToWebMercator(
                        new ESRI.ArcGIS.Client.Geometry.MapPoint(-65, 55)));

            initialExtent.SpatialReference = new SpatialReference(102100);

            MyMap.Extent = initialExtent;

            MyDrawObject = new Draw(MyMap)
            {
                DrawMode   = DrawMode.Polygon,
                IsEnabled  = false,
                FillSymbol = LayoutRoot.Resources["DefaultFillSymbol"] as ESRI.ArcGIS.Client.Symbols.FillSymbol
            };
            MyDrawObject.DrawComplete += MyDrawObject_DrawComplete;
            MyDrawObject.DrawBegin    += MyDrawObject_DrawBegin;

            List <CalculationType> enumVals = new List <CalculationType>();

            foreach (var val in typeof(CalculationType).GetFields())
            {
                if (val.IsLiteral)
                {
                    enumVals.Add((CalculationType)val.GetValue(typeof(CalculationType)));
                }
            }
            CalcTypeListBox.ItemsSource   = enumVals;
            CalcTypeListBox.SelectedIndex = 0;
        }
Example #5
0
        public AreasAndLengths()
        {
            InitializeComponent();

            ESRI.ArcGIS.Client.Geometry.Envelope initialExtent =
                new ESRI.ArcGIS.Client.Geometry.Envelope(
                    mercator.FromGeographic(
                        new ESRI.ArcGIS.Client.Geometry.MapPoint(-130, 20)) as MapPoint,
                    mercator.FromGeographic(
                        new ESRI.ArcGIS.Client.Geometry.MapPoint(-65, 55)) as MapPoint);

            initialExtent.SpatialReference = new SpatialReference(102100);

            MyMap.Extent = initialExtent;

            MyDrawObject = new Draw(MyMap)
            {
                DrawMode   = DrawMode.Polygon,
                IsEnabled  = true,
                FillSymbol = LayoutRoot.Resources["DefaultFillSymbol"] as ESRI.ArcGIS.Client.Symbols.FillSymbol
            };
            MyDrawObject.DrawComplete += MyDrawObject_DrawComplete;
            MyDrawObject.DrawBegin    += MyDrawObject_DrawBegin;

            calculationTypeCombo.ItemsSource   = Enum.GetValues(typeof(CalculationType));
            calculationTypeCombo.SelectedIndex = 0;
        }
        public AreaAndLengths()
        {
            InitializeComponent();
            ESRI.ArcGIS.Client.Geometry.Envelope initialExtent =
                new ESRI.ArcGIS.Client.Geometry.Envelope(
            ESRI.ArcGIS.Client.Bing.Transform.GeographicToWebMercator(
                new ESRI.ArcGIS.Client.Geometry.MapPoint(-130, 20)),
            ESRI.ArcGIS.Client.Bing.Transform.GeographicToWebMercator(
                new ESRI.ArcGIS.Client.Geometry.MapPoint(-65, 55)));

            initialExtent.SpatialReference = new SpatialReference(102100);

            MyMap.Extent = initialExtent;

            MyDrawObject = new Draw(MyMap)
            {
                DrawMode = DrawMode.Polygon,
                IsEnabled = false,
                FillSymbol = LayoutRoot.Resources["DefaultFillSymbol"] as ESRI.ArcGIS.Client.Symbols.FillSymbol
            };
            MyDrawObject.DrawComplete += MyDrawObject_DrawComplete;
            MyDrawObject.DrawBegin += MyDrawObject_DrawBegin;

            List<CalculationType> enumVals = new List<CalculationType>();
            foreach (var val in typeof(CalculationType).GetFields())
            {
                if (val.IsLiteral)
                    enumVals.Add((CalculationType)val.GetValue(typeof(CalculationType)));
            }
            CalcTypeListBox.ItemsSource = enumVals;
            CalcTypeListBox.SelectedIndex = 0;
        }
Example #7
0
        private void LocatorTask_AddressToLocationsCompleted(object sender, ESRI.ArcGIS.Client.Tasks.AddressToLocationsEventArgs args)
        {
            List <AddressCandidate> returnedCandidates = args.Results;

            AddressBorder.Visibility = System.Windows.Visibility.Collapsed;

            if (returnedCandidates.Count > 0)
            {
                AddressCandidate candidate = returnedCandidates[0];

                Graphic graphic = new Graphic()
                {
                    Symbol   = LayoutRoot.Resources["DefaultMarkerSymbol"] as Symbol,
                    Geometry = candidate.Location
                };

                graphic.Attributes.Add("Address", candidate.Address);

                graphicsLayer.Graphics.Add(graphic);

                ResultsTextBlock.Visibility = System.Windows.Visibility.Visible;
                ResultsTextBlock.Text       = candidate.Address;

                double displaySize = MyMap.MinimumResolution * 30;
                ESRI.ArcGIS.Client.Geometry.Envelope displayExtent = new ESRI.ArcGIS.Client.Geometry.Envelope(
                    candidate.Location.X - (displaySize / 2),
                    candidate.Location.Y - (displaySize / 2),
                    candidate.Location.X + (displaySize / 2),
                    candidate.Location.Y + (displaySize / 2));
                MyMap.ZoomTo(displayExtent);
            }
        }
        /// <summary>
        /// The parser for the layers and the image.
        /// </summary>
        /// <param name="sResult"></param>
        /// <param name="onComplete"></param>
        private void ParseAXL(string sResult, OnUrlComplete onComplete)
        {
            XDocument xDoc = XDocument.Parse(sResult);

            if (xDoc.Element("ARCXML").Element("RESPONSE").Element("SERVICEINFO") != null)
            {
                //ARCIMS SERVICE INFO HAS BEEN RETURNED
                XMin = Convert.ToDouble(xDoc.Element("ARCXML").Element("RESPONSE").Element("SERVICEINFO").Element("PROPERTIES").Element("ENVELOPE").Attribute("minx").Value);
                XMax = Convert.ToDouble(xDoc.Element("ARCXML").Element("RESPONSE").Element("SERVICEINFO").Element("PROPERTIES").Element("ENVELOPE").Attribute("maxx").Value);
                YMin = Convert.ToDouble(xDoc.Element("ARCXML").Element("RESPONSE").Element("SERVICEINFO").Element("PROPERTIES").Element("ENVELOPE").Attribute("miny").Value);
                YMax = Convert.ToDouble(xDoc.Element("ARCXML").Element("RESPONSE").Element("SERVICEINFO").Element("PROPERTIES").Element("ENVELOPE").Attribute("maxy").Value);

                coorsys = Int32.Parse(xDoc.Element("ARCXML").Element("RESPONSE").Element("SERVICEINFO").Element("PROPERTIES").Element("FEATURECOORDSYS").Attribute("id").Value);

                // Get the ArcXml request
                this.SpatialReference = new SpatialReference(coorsys);

                FullExtent = new ESRI.ArcGIS.Client.Geometry.Envelope()
                {
                    XMin             = XMin,
                    YMin             = YMin,
                    XMax             = XMax,
                    YMax             = YMax,
                    SpatialReference = new SpatialReference(coorsys)
                };

                base.Initialize();
            }

            else if (xDoc.Element("ARCXML").Element("RESPONSE").Element("IMAGE") != null)
            {
                //AN IMAGE HAS BEEN RETURNED
                string imageUrl = xDoc.Element("ARCXML").Element("RESPONSE").Element("IMAGE").Element("OUTPUT").Attribute("url").Value;

                this.ImageUrl = imageUrl;

                ESRI.ArcGIS.Client.Geometry.Envelope newEnv = new Envelope();
                newEnv.XMin = Convert.ToDouble(xDoc.Element("ARCXML").Element("RESPONSE").Element("IMAGE").Element("ENVELOPE").Attribute("minx").Value);
                newEnv.YMin = Convert.ToDouble(xDoc.Element("ARCXML").Element("RESPONSE").Element("IMAGE").Element("ENVELOPE").Attribute("miny").Value);
                newEnv.YMax = Convert.ToDouble(xDoc.Element("ARCXML").Element("RESPONSE").Element("IMAGE").Element("ENVELOPE").Attribute("maxy").Value);
                newEnv.XMax = Convert.ToDouble(xDoc.Element("ARCXML").Element("RESPONSE").Element("IMAGE").Element("ENVELOPE").Attribute("maxx").Value);
                SpatialReference spRef = new SpatialReference(coorsys);
                newEnv.SpatialReference = spRef;
                _onComplete(this.ImageUrl, _width, _height, newEnv);
            }
            else if (xDoc.Element("ARCXML").Element("RESPONSE").Element("ERROR") != null)
            {
                //AN ERROR HAS BEEN RETURNED
                this.Cancel();

                this.ErrorMsg = xDoc.Element("ARCXML").Element("RESPONSE").Element("ERROR").Value;

                this.GetImageFailed(this, new EventArgs());
            }

            else
            {
                System.Diagnostics.Debug.WriteLine(string.Format("IMS Returned an unknown response" + xDoc.ToString()));
            }
        }
Example #9
0
        private double getResolutionForGeographic(ESRI.ArcGIS.Client.Geometry.Envelope extent, double resolution)
        {
            degreeDist = earthRadius * toRadians;
            MapPoint center = extent.GetCenter();
            double   y      = center.Y;

            if (Math.Abs(y) > 90)
            {
                return(0);
            }
            return(Math.Cos(y * toRadians) * resolution * degreeDist);
        }
Example #10
0
        protected void ProfileButtonClicked(object parameters)
        {
            string str = parameters.ToString();

            switch (str)
            {
            case "SAVE":
                if (DownloadExtent == null || Levels == null || Levels.Length == 0)
                {
                    MessageBox.Show(App.Current.FindResource("msgDownloadProfileInvalid").ToString(), App.Current.FindResource("msgError").ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                Util.Envelope env    = new Util.Envelope(DownloadExtent.XMin, DownloadExtent.YMin, DownloadExtent.XMax, DownloadExtent.YMax);
                string        result = _configManager.SaveDownloadProfileWithOverwrite(new PBS.DownloadProfile(SelectedProfile, Levels, env, _downloadPolygon));
                if (result != string.Empty)
                {
                    MessageBox.Show(result, App.Current.FindResource("msgError").ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                break;

            case "LOAD":
                DownloadProfile profile = _configManager.LoadDownloadProfile(SelectedProfile);
                if (profile == null)
                {
                    MessageBox.Show(App.Current.FindResource("msgLoadFailed").ToString(), App.Current.FindResource("msgError").ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                _downloadPolygon = profile.Polygon;
                Levels           = profile.Levels;
                DownloadExtent   = new Envelope(profile.Envelope.XMin, profile.Envelope.YMin, profile.Envelope.XMax, profile.Envelope.YMax);
                _graphicsLayer.ClearGraphics();
                _graphicsLayer.Graphics.Add(new Graphic()
                {
                    Symbol = new SimpleFillSymbol()
                    {
                        BorderBrush = new SolidColorBrush(Colors.Red),
                        Fill        = new SolidColorBrush(Color.FromArgb(100, 255, 0, 0))
                    },
                    Geometry = profile.Polygon == null ? _webMercator.FromGeographic(DownloadExtent) : AppUtility.ConvertPBSPolygonToEsriPolygon(profile.Polygon)
                });
                (CMDClickStartButton as DelegateCommand).RaiseCanExecuteChanged();
                TilesCount = AppUtility.CalculateTileCount(Levels, (Envelope)_webMercator.FromGeographic(DownloadExtent));
                break;

            case "DELETE":
                _configManager.DeleteDownloadProfile(SelectedProfile);
                break;

            default:
                break;
            }
            Profiles = new ObservableCollection <string>(_configManager.GetAllDownloadProfileNames());
        }
Example #11
0
        /// <summary>
        /// Method converts ESRI ArcGIS Envelope object to ESRI ArcLogistics Envelope object.
        /// </summary>
        /// <param name="envelope">Envelope to covert.</param>
        /// <returns>ESRI ArcLogistics Envelope object.</returns>
        private ESRI.ArcLogistics.Geometry.Envelope _ConvertToArcLogisticsEnvelope(
            ESRISDSGeometry.Envelope envelope)
        {
            Debug.Assert(envelope != null);

            var geometry = new ESRI.ArcLogistics.Geometry.Envelope(
                envelope.XMin,
                envelope.YMax,
                envelope.XMax,
                envelope.YMin);

            return(geometry);
        }
Example #12
0
        private void RadioButton_OnChecked(object sender, RoutedEventArgs e)
        {
            RadioButton r = sender as RadioButton;

            if (MyMap == null)
            {
                return;
            }

            if (MyMap.Layers.Count > 1)
            {
                MyMap.Layers.Clear();
            }

            if (r.Content.ToString() == "WMS")
            {
                //中国范围
                Envelope FullExtent = new ESRI.ArcGIS.Client.Geometry.Envelope(121.156, 30.895442, 121.938455, 31.3189)
                {
                    SpatialReference = new SpatialReference(4326)
                };
                this.MyMap.ZoomTo(FullExtent);

                BaidumapWmsLayer Alayer = new BaidumapWmsLayer();
                Alayer.Visible = true;
                this.MyMap.Layers.Insert(0, Alayer);

                this.MyMap.ZoomTo(FullExtent);
            }
            else
            {
                //中国范围
                Envelope FullExtent = new ESRI.ArcGIS.Client.Geometry.Envelope(9001735.65795624, 2919532.04645186, 19020489.8293508, 8346937.81802098)
                {
                    SpatialReference = new SpatialReference(102100)
                };
                this.MyMap.ZoomTo(FullExtent);

                BaidumapWmtsLayer Alayer = new BaidumapWmtsLayer();
                Alayer.MapType = "Map";
                Alayer.Visible = true;
                this.MyMap.Layers.Insert(0, Alayer);

                //中国范围
                FullExtent = new ESRI.ArcGIS.Client.Geometry.Envelope(9001735.65795624, 2919532.04645186, 19020489.8293508, 8346937.81802098)
                {
                    SpatialReference = new SpatialReference(102100)
                };
                this.MyMap.ZoomTo(FullExtent);
            }
        }
        /// <summary>
        /// 查询完成后触发的事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private void QueryTask_ExecuteCompleted(object sender, ESRI.ArcGIS.Client.Tasks.QueryEventArgs args)
        {
            ResourceDictionary resourcedic = new ResourceDictionary();

            resourcedic.Source = new Uri("Resources/MapSymbolResources.xaml", UriKind.Relative);
            GraphicsLayer graphicsLayer = MainMap.Layers["MyGraphicsLayer"] as GraphicsLayer;

            graphicsLayer.ClearGraphics();

            // Check for new results.
            FeatureSet featureSet = args.FeatureSet;

            if (featureSet.Features.Count > 0)
            {
                if (featureSet.Features.Count > 1)
                {
                    foreach (Graphic resultFeature in featureSet.Features)
                    {
                        resultFeature.Symbol = resourcedic["ResultsFillSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol;
                        graphicsLayer.Graphics.Add(resultFeature);
                    }
                }
                else
                {
                    featureSet.Features[0].Symbol = resourcedic["ResultsFillSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol;
                    graphicsLayer.Graphics.Add(featureSet.Features[0]);
                    ESRI.ArcGIS.Client.Geometry.Envelope selectedFeatureExtent = featureSet.Features[0].Geometry.Extent;

                    double expandPercentage = 100;

                    double widthExtend  = selectedFeatureExtent.Width * (expandPercentage / 100);
                    double heightExtend = selectedFeatureExtent.Height * (expandPercentage / 100);

                    ESRI.ArcGIS.Client.Geometry.Envelope displayExtent = new Envelope
                                                                         (
                        selectedFeatureExtent.XMin,
                        selectedFeatureExtent.YMin,
                        selectedFeatureExtent.XMax,
                        selectedFeatureExtent.YMax

                                                                         );
                    MainMap.ZoomTo(displayExtent);
                }
            }
            else
            {
                MessageBox.Show("没有对应的数据");
            }
        }
        public SDSMap()
        {
            InitializeComponent();

            ESRI.ArcGIS.Client.Geometry.Envelope initialExtent =
                    new ESRI.ArcGIS.Client.Geometry.Envelope(
                mercator.FromGeographic(
                    new ESRI.ArcGIS.Client.Geometry.MapPoint(-130, 20)) as MapPoint,
                mercator.FromGeographic(
                    new ESRI.ArcGIS.Client.Geometry.MapPoint(-65, 55)) as MapPoint);

            initialExtent.SpatialReference = new SpatialReference(102100);

            MyMap.Extent = initialExtent;
        }
        public ToolkitAttachmentEditor()
        {
            InitializeComponent();

            ESRI.ArcGIS.Client.Geometry.Envelope initialExtent =
                new ESRI.ArcGIS.Client.Geometry.Envelope(
                    _mercator.FromGeographic(
                        new ESRI.ArcGIS.Client.Geometry.MapPoint(-122.4306073721, 37.7666097907)) as MapPoint,
                    _mercator.FromGeographic(
                        new ESRI.ArcGIS.Client.Geometry.MapPoint(-122.4230971868, 37.77197420877)) as MapPoint);

            initialExtent.SpatialReference = new SpatialReference(102100);

            MyMap.Extent = initialExtent;
        }
Example #16
0
        private void MyMap_Loaded(object sender, RoutedEventArgs e)
        {
            BaidumapWmsLayer Alayer = new BaidumapWmsLayer();

            Alayer.Visible = true;
            this.MyMap.Layers.Insert(0, Alayer);

            //中国范围
            Envelope FullExtent = new ESRI.ArcGIS.Client.Geometry.Envelope(121.156, 30.895442, 121.938455, 31.3189)
            {
                SpatialReference = new SpatialReference(4326)
            };

            this.MyMap.ZoomTo(FullExtent);
        }
        public ToolkitFeatureDataForm()
        {
            InitializeComponent();

            ESRI.ArcGIS.Client.Geometry.Envelope initialExtent =
                new ESRI.ArcGIS.Client.Geometry.Envelope(
            _mercator.FromGeographic(
                new ESRI.ArcGIS.Client.Geometry.MapPoint(-122.4545596, 37.783443296)) as MapPoint,
            _mercator.FromGeographic(
                new ESRI.ArcGIS.Client.Geometry.MapPoint(-122.4449924, 37.786447331)) as MapPoint);

            initialExtent.SpatialReference = new SpatialReference(102100);

            MyMap.Extent = initialExtent;
        }
        public ToolkitFeatureDataForm()
        {
            InitializeComponent();

            ESRI.ArcGIS.Client.Geometry.Envelope initialExtent =
                new ESRI.ArcGIS.Client.Geometry.Envelope(
                    _mercator.FromGeographic(
                        new ESRI.ArcGIS.Client.Geometry.MapPoint(-122.4545596, 37.783443296)) as MapPoint,
                    _mercator.FromGeographic(
                        new ESRI.ArcGIS.Client.Geometry.MapPoint(-122.4449924, 37.786447331)) as MapPoint);

            initialExtent.SpatialReference = new SpatialReference(102100);

            MyMap.Extent = initialExtent;
        }
        public ToolkitTemplatePicker()
        {
            InitializeComponent();

            ESRI.ArcGIS.Client.Geometry.Envelope initialExtent =
                new ESRI.ArcGIS.Client.Geometry.Envelope(
            _mercator.FromGeographic(
                new ESRI.ArcGIS.Client.Geometry.MapPoint(-117.6690936441, 34.19871558256)) as MapPoint,
            _mercator.FromGeographic(
                new ESRI.ArcGIS.Client.Geometry.MapPoint(-117.411944901, 34.37896002836)) as MapPoint);

            initialExtent.SpatialReference = new SpatialReference(102100);

            MyMap.Extent = initialExtent;
        }
        public ToolkitAttachmentEditor()
        {
            InitializeComponent();

            ESRI.ArcGIS.Client.Geometry.Envelope initialExtent =
                    new ESRI.ArcGIS.Client.Geometry.Envelope(
                _mercator.FromGeographic(
                    new ESRI.ArcGIS.Client.Geometry.MapPoint(-122.4306073721, 37.7666097907)) as MapPoint,
                _mercator.FromGeographic(
                    new ESRI.ArcGIS.Client.Geometry.MapPoint(-122.4230971868, 37.77197420877)) as MapPoint);

            initialExtent.SpatialReference = new SpatialReference(102100);

            MyMap.Extent = initialExtent;
        }
Example #21
0
        public ToolkitEditorWidget()
        {
            InitializeComponent();

            ESRI.ArcGIS.Client.Geometry.Envelope initialExtent =
                new ESRI.ArcGIS.Client.Geometry.Envelope(
                    _mercator.FromGeographic(
                        new ESRI.ArcGIS.Client.Geometry.MapPoint(-117.6690936441, 34.19871558256)) as MapPoint,
                    _mercator.FromGeographic(
                        new ESRI.ArcGIS.Client.Geometry.MapPoint(-117.411944901, 34.37896002836)) as MapPoint);

            initialExtent.SpatialReference = new SpatialReference(102100);

            MyMap.Extent = initialExtent;
        }
        public SDSMap()
        {
            InitializeComponent();

            ESRI.ArcGIS.Client.Geometry.Envelope initialExtent =
                new ESRI.ArcGIS.Client.Geometry.Envelope(
                    mercator.FromGeographic(
                        new ESRI.ArcGIS.Client.Geometry.MapPoint(-130, 20)) as MapPoint,
                    mercator.FromGeographic(
                        new ESRI.ArcGIS.Client.Geometry.MapPoint(-65, 55)) as MapPoint);

            initialExtent.SpatialReference = new SpatialReference(102100);

            MyMap.Extent = initialExtent;
        }
        public AddressToLocation()
        {
            InitializeComponent();
            ESRI.ArcGIS.Client.Geometry.Envelope initialExtent =
                new ESRI.ArcGIS.Client.Geometry.Envelope(
                    _mercator.FromGeographic(
                        new ESRI.ArcGIS.Client.Geometry.MapPoint(-122.554, 37.615)) as MapPoint,
                    _mercator.FromGeographic(
                        new ESRI.ArcGIS.Client.Geometry.MapPoint(-122.245, 37.884)) as MapPoint);

            initialExtent.SpatialReference = new SpatialReference(102100);

            MyMap.Extent = initialExtent;

            _candidateGraphicsLayer = MyMap.Layers["CandidateGraphicsLayer"] as GraphicsLayer;
        }
        /// <summary>
        /// Gets the URL.
        /// </summary>
        /// <param name="extent">The extent.</param>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="onComplete">The on complete.</param>
        public override void GetUrl(ESRI.ArcGIS.Client.Geometry.Envelope extent, int width, int height, DynamicMapServiceLayer.OnUrlComplete onComplete)
        {
            string sAXL = AxlHelper.GetRequestAxl(extent.XMin,
                                                  extent.YMin, extent.XMax, extent.YMax, _backgroundColor, _backgroundTranscolor, _imageFormat,
                                                  width, height);

            //ARCIMS CAN RETURN ERROR WHEN HEIGHT AND WIDTH DON'T MATCH THE LIMITED SETTINGS - HAVE SEEN WHERE THIS DOESN'T OCCUR WITH FLEX AND DOES IN SILVERLIGHT - OUR MAP SEEMS TO
            //BE LARGER - ACCORDING TO DOCUMENTATION, THIS CAN ONLY BE FIXED ON THE ARCIMS SERVER BY CHANGING THE SETTINGS

            _width  = width;
            _height = height;

            // Builds the url
            string sUrl = AxlHelper.BuildURL(ServiceHost, ServiceName, ProxyUrl);

            MakeRequest(sUrl, sAXL, onComplete);
        }
        public LocationToAddress()
        {
            InitializeComponent();

            ESRI.ArcGIS.Client.Geometry.Envelope initialExtent =
                new ESRI.ArcGIS.Client.Geometry.Envelope(
                    _mercator.FromGeographic(
                        new ESRI.ArcGIS.Client.Geometry.MapPoint(-117.387, 33.97)) as MapPoint,
                    _mercator.FromGeographic(
                        new ESRI.ArcGIS.Client.Geometry.MapPoint(-117.355, 33.988)) as MapPoint);

            initialExtent.SpatialReference = new SpatialReference(102100);

            MyMap.Extent = initialExtent;

            _locationGraphicsLayer = MyMap.Layers["LocationGraphicsLayer"] as GraphicsLayer;
        }
        public AddressToLocation()
        {
            InitializeComponent();

            ESRI.ArcGIS.Client.Geometry.Envelope initialExtent =
                    new ESRI.ArcGIS.Client.Geometry.Envelope(
                _mercator.FromGeographic(
                    new ESRI.ArcGIS.Client.Geometry.MapPoint(-122.554, 37.615)) as MapPoint,
                _mercator.FromGeographic(
                    new ESRI.ArcGIS.Client.Geometry.MapPoint(-122.245, 37.884)) as MapPoint);

            initialExtent.SpatialReference = new SpatialReference(102100);

            MyMap.Extent = initialExtent;

            _candidateGraphicsLayer = MyMap.Layers["CandidateGraphicsLayer"] as GraphicsLayer;
        }
        public LocationToAddress()
        {
            InitializeComponent();

            ESRI.ArcGIS.Client.Geometry.Envelope initialExtent =
                    new ESRI.ArcGIS.Client.Geometry.Envelope(
                _mercator.FromGeographic(
                    new ESRI.ArcGIS.Client.Geometry.MapPoint(-117.387, 33.97)) as MapPoint,
                _mercator.FromGeographic(
                    new ESRI.ArcGIS.Client.Geometry.MapPoint(-117.355, 33.988)) as MapPoint);

            initialExtent.SpatialReference = new SpatialReference(102100);

            MyMap.Extent = initialExtent;

            _locationGraphicsLayer = MyMap.Layers["LocationGraphicsLayer"] as GraphicsLayer;
        }
        void _candidateListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            int index = (sender as ListBox).SelectedIndex;

            if (index >= 0)
            {
                MapPoint candidatePoint = _candidateGraphicsLayer.Graphics[index].Geometry as MapPoint;
                double   displaySize    = MyMap.MinimumResolution * 30;

                ESRI.ArcGIS.Client.Geometry.Envelope displayExtent = new ESRI.ArcGIS.Client.Geometry.Envelope(
                    candidatePoint.X - (displaySize / 2),
                    candidatePoint.Y - (displaySize / 2),
                    candidatePoint.X + (displaySize / 2),
                    candidatePoint.Y + (displaySize / 2));

                MyMap.ZoomTo(displayExtent);
            }
        }
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Get rect from extent envelope
        /// </summary>
        /// <param name="envelope">Extent envelope in map spatial reference</param>
        /// <param name="spatialReferenceID">Map spatial reference ID</param>
        /// <returns>Extent envelope in WGS84</returns>
        public static ESRI.ArcLogistics.Geometry.Envelope CreateRect(ESRI.ArcGIS.Client.Geometry.Envelope env,
                                                                     int?spatialReferenceID)
        {
            // Project extent to map spatial reference
            ESRI.ArcLogistics.Geometry.Point leftTop     = new ESRI.ArcLogistics.Geometry.Point(env.XMin, env.YMax);
            ESRI.ArcLogistics.Geometry.Point rightBottom = new ESRI.ArcLogistics.Geometry.Point(env.XMax, env.YMin);

            // Project point from Web Mercator to WGS84 if spatial reference of map is Web Mercator
            if (spatialReferenceID.HasValue)
            {
                leftTop     = WebMercatorUtil.ProjectPointFromWebMercator(leftTop, spatialReferenceID.Value);
                rightBottom = WebMercatorUtil.ProjectPointFromWebMercator(rightBottom, spatialReferenceID.Value);
            }

            ESRI.ArcLogistics.Geometry.Envelope rect = new ESRI.ArcLogistics.Geometry.Envelope(
                leftTop.X, leftTop.Y, rightBottom.X, rightBottom.Y);

            return(rect);
        }
        /// <summary>
        /// Suspended extent changing.
        /// </summary>
        private void _ChangeExtentOnViewVisibilityChanged(ESRI.ArcLogistics.Geometry.Envelope oldExtent)
        {
            Debug.Assert(_mapControl != null);

            if (_oldExtent != null)
            {
                // Increase counter of changing extent by changing map control size, but not more than 2
                _mapExtentChangedPostponedCount++;
                if (_mapExtentChangedPostponedCount > MAX_EXTENT_CHANGING_BY_CHANGE_SIZE)
                {
                    _mapExtentChangedPostponedCount = MAX_EXTENT_CHANGING_BY_CHANGE_SIZE;
                }

                ESRI.ArcGIS.Client.Geometry.Envelope extent = GeometryHelper.CreateExtent(_oldExtent.Value, _mapControl.Map.SpatialReferenceID);
                _mapControl.ZoomTo(extent);
            }

            _mapSizeChangedProcessed = false;
        }
        public BatchGeocoding()
        {
            InitializeComponent();

            ESRI.ArcGIS.Client.Geometry.Envelope initialExtent =
                new ESRI.ArcGIS.Client.Geometry.Envelope(
                    _mercator.FromGeographic(
                        new ESRI.ArcGIS.Client.Geometry.MapPoint(-117.387, 33.97)) as MapPoint,
                    _mercator.FromGeographic(
                        new ESRI.ArcGIS.Client.Geometry.MapPoint(-117.355, 33.988)) as MapPoint);

            initialExtent.SpatialReference = new SpatialReference(102100);

            MyMap.Extent = initialExtent;

            _locatorTask = new Locator("http://serverapps101.esri.com/arcgis/rest/services/USA_Geocode/GeocodeServer");
            _locatorTask.AddressesToLocationsCompleted += _locatorTask_AddressesToLocationsCompleted;
            _locatorTask.Failed += LocatorTask_Failed;

            geocodedResults = MyMap.Layers["LocationGraphicsLayer"] as GraphicsLayer;

            //List of addresses to geocode
            batchaddresses.Add(new Dictionary <string, string> {
                { "Street", "4409 Redwood Dr" }, { "Zip", "92501" }
            });
            batchaddresses.Add(new Dictionary <string, string> {
                { "Street", "3758 Cedar St" }, { "Zip", "92501" }
            });
            batchaddresses.Add(new Dictionary <string, string> {
                { "Street", "3486 Orange St" }, { "Zip", "92501" }
            });
            batchaddresses.Add(new Dictionary <string, string> {
                { "Street", "2999 4th St" }, { "Zip", "92507" }
            });
            batchaddresses.Add(new Dictionary <string, string> {
                { "Street", "3685 10th St" }, { "Zip", "92501" }
            });

            AddressListbox.ItemsSource = batchaddresses;
        }
        public AreasAndLengths()
        {
            InitializeComponent();
            ESRI.ArcGIS.Client.Geometry.Envelope initialExtent =
                new ESRI.ArcGIS.Client.Geometry.Envelope(
                    ESRI.ArcGIS.Client.Bing.Transform.GeographicToWebMercator(
                        new ESRI.ArcGIS.Client.Geometry.MapPoint(-130, 20)),
                    ESRI.ArcGIS.Client.Bing.Transform.GeographicToWebMercator(
                        new ESRI.ArcGIS.Client.Geometry.MapPoint(-65, 55)));

            initialExtent.SpatialReference = new SpatialReference(102100);

            MyMap.Extent = initialExtent;

            MyDrawObject = new Draw(MyMap)
            {
                DrawMode   = DrawMode.Polygon,
                IsEnabled  = true,
                FillSymbol = LayoutRoot.Resources["DefaultFillSymbol"] as ESRI.ArcGIS.Client.Symbols.FillSymbol
            };
            MyDrawObject.DrawComplete += MyDrawObject_DrawComplete;
            MyDrawObject.DrawBegin    += MyDrawObject_DrawBegin;
        }
Example #33
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="levels"></param>
        /// <param name="extent">sr=3857</param>
        /// <returns></returns>
        public static long CalculateTileCount(int[] levels, ESRI.ArcGIS.Client.Geometry.Envelope extent)
        {
            long total         = 0;
            int  constTileSize = 256;

            LODInfo[]    LODs             = new LODInfo[20];
            const double cornerCoordinate = 20037508.3427892;
            double       resolution       = cornerCoordinate * 2 / 256;
            double       scale            = 591657527.591555;

            for (int i = 0; i < LODs.Length; i++)
            {
                LODs[i] = new LODInfo()
                {
                    Resolution = resolution,
                    LevelID    = i,
                    Scale      = scale
                };
                resolution /= 2;
                scale      /= 2;
            }
            PBS.Util.Point TileOrigin = new PBS.Util.Point(-cornerCoordinate, cornerCoordinate);
            foreach (int level in levels)
            {
                LODInfo lod             = LODs[level];
                double  oneTileDistance = lod.Resolution * constTileSize;
                //calculate start tile and end tile
                int startTileRow = (int)(Math.Abs(TileOrigin.Y - extent.YMax) / oneTileDistance);
                int startTileCol = (int)(Math.Abs(TileOrigin.X - extent.XMin) / oneTileDistance);
                int endTileRow   = (int)(Math.Abs(TileOrigin.Y - extent.YMin) / oneTileDistance);
                int endTileCol   = (int)(Math.Abs(TileOrigin.X - extent.XMax) / oneTileDistance);
                //"startR,startC,endR,endC"
                total += Math.Abs((endTileCol - startTileCol + 1) * (endTileRow - startTileRow + 1));
            }
            return(total);
        }
Example #34
0
        private double getValueFromMap(ESRI.ArcGIS.Client.Geometry.Envelope extent)
        {
            if (layerResolutions == null || layerResolutions.Length == 0 ||
                Map == null || extent == null)
            {
                return(-1);
            }
            double mapRes = extent.Width / Map.ActualWidth;

            for (int i = 0; i < layerResolutions.Length - 1; i++)
            {
                double thisRes = layerResolutions[i];
                double nextRes = layerResolutions[i + 1];
                if (mapRes >= thisRes)
                {
                    return(i);
                }
                if (mapRes < thisRes && mapRes > nextRes)
                {
                    return(i + (thisRes - mapRes) / (thisRes - nextRes));
                }
            }
            return(Convert.ToDouble(layerResolutions.Length - 1));
        }
        void _candidateListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            int index = (sender as ListBox).SelectedIndex;
            if (index >= 0)
            {
                MapPoint candidatePoint = _candidateGraphicsLayer.Graphics[index].Geometry as MapPoint;
                double displaySize = MyMap.MinimumResolution * 30;

                ESRI.ArcGIS.Client.Geometry.Envelope displayExtent = new ESRI.ArcGIS.Client.Geometry.Envelope(
                    candidatePoint.X - (displaySize / 2),
                    candidatePoint.Y - (displaySize / 2),
                    candidatePoint.X + (displaySize / 2),
                    candidatePoint.Y + (displaySize / 2));

                MyMap.ZoomTo(displayExtent);
            }
        }
        private void LocatorTask_AddressToLocationsCompleted(object sender, ESRI.ArcGIS.Client.Tasks.AddressToLocationsEventArgs args)
        {
            List<AddressCandidate> returnedCandidates = args.Results;

            AddressBorder.Visibility = System.Windows.Visibility.Collapsed;

            if (returnedCandidates.Count > 0)
            {
                AddressCandidate candidate = returnedCandidates[0];

                Graphic graphic = new Graphic()
                {
                    Symbol = LayoutRoot.Resources["DefaultMarkerSymbol"] as Symbol,
                    Geometry = candidate.Location
                };

                graphic.Attributes.Add("Address", candidate.Address);

                graphicsLayer.Graphics.Add(graphic);

                ResultsTextBlock.Visibility = System.Windows.Visibility.Visible;
                ResultsTextBlock.Text = candidate.Address;

                double displaySize = MyMap.MinimumResolution * 30;
                ESRI.ArcGIS.Client.Geometry.Envelope displayExtent = new ESRI.ArcGIS.Client.Geometry.Envelope(
                    candidate.Location.X - (displaySize / 2),
                    candidate.Location.Y - (displaySize / 2),
                    candidate.Location.X + (displaySize / 2),
                    candidate.Location.Y + (displaySize / 2));
                MyMap.ZoomTo(displayExtent);
            }
        }
        private void LoadMapButton_Click(object sender, RoutedEventArgs e)
        {
            WebClient webClient = new WebClient();
            string uri = string.Format("http://dev.virtualearth.net/REST/v1/Imagery/Metadata/Aerial?supressStatus=true&key={0}", BingKeyTextBox.Text);

            webClient.OpenReadCompleted += (s, a) =>
            {
                if (a.Error == null)
                {
                    JsonValue jsonResponse = JsonObject.Load(a.Result);
                    string authenticationResult = jsonResponse["authenticationResultCode"];
                    a.Result.Close();

                    if (authenticationResult == "ValidCredentials")
                    {
                        ESRI.ArcGIS.Client.Bing.TileLayer tileLayer = new TileLayer()
                        {
                            ID = "BingLayer",
                            LayerStyle = TileLayer.LayerType.Road,
                            ServerType = ServerType.Production,
                            Token = BingKeyTextBox.Text
                        };

                        MyMap.Layers.Insert(0, tileLayer);

                        // Add your Bing Maps key in the constructor for the Routing class. Use http://www.bingmapsportal.com to generate a key.
                        routing = new ESRI.ArcGIS.Client.Bing.Routing(BingKeyTextBox.Text);
                        routing.ServerType = ServerType.Production;

                        myDrawObject = new Draw(MyMap)
                        {
                            DrawMode = DrawMode.Point,
                            IsEnabled = true
                        };

                        myDrawObject.DrawComplete += MyDrawObject_DrawComplete;
                        waypointGraphicsLayer = MyMap.Layers["WaypointGraphicsLayer"] as GraphicsLayer;
                        routeResultsGraphicsLayer = MyMap.Layers["RouteResultsGraphicsLayer"] as GraphicsLayer;

                        ESRI.ArcGIS.Client.Geometry.Envelope initialExtent =
                                new ESRI.ArcGIS.Client.Geometry.Envelope(
                            mercator.FromGeographic(
                                new ESRI.ArcGIS.Client.Geometry.MapPoint(-130, 20)) as MapPoint,
                            mercator.FromGeographic(
                                new ESRI.ArcGIS.Client.Geometry.MapPoint(-65, 55)) as MapPoint);

                        initialExtent.SpatialReference = new SpatialReference(102100);

                        MyMap.Extent = initialExtent;

                        BingKeyGrid.Visibility = System.Windows.Visibility.Collapsed;
                        RouteGrid.Visibility = System.Windows.Visibility.Visible;

                        InvalidBingKeyTextBlock.Visibility = System.Windows.Visibility.Collapsed;

                    }
                    else InvalidBingKeyTextBlock.Visibility = System.Windows.Visibility.Visible;
                }
                else InvalidBingKeyTextBlock.Visibility = System.Windows.Visibility.Visible;
            };

            webClient.OpenReadAsync(new System.Uri(uri));
        }
        /// <summary>
        /// The parser for the layers and the image.
        /// </summary>
        /// <param name="sResult"></param>
        /// <param name="onComplete"></param>
        private void ParseAXL(string sResult, OnUrlComplete onComplete)
        {
            XDocument xDoc = XDocument.Parse(sResult);

            if (xDoc.Element("ARCXML").Element("RESPONSE").Element("SERVICEINFO") != null)
            {
                //ARCIMS SERVICE INFO HAS BEEN RETURNED
                XMin = Convert.ToDouble(xDoc.Element("ARCXML").Element("RESPONSE").Element("SERVICEINFO").Element("PROPERTIES").Element("ENVELOPE").Attribute("minx").Value);
                XMax = Convert.ToDouble(xDoc.Element("ARCXML").Element("RESPONSE").Element("SERVICEINFO").Element("PROPERTIES").Element("ENVELOPE").Attribute("maxx").Value);
                YMin = Convert.ToDouble(xDoc.Element("ARCXML").Element("RESPONSE").Element("SERVICEINFO").Element("PROPERTIES").Element("ENVELOPE").Attribute("miny").Value);
                YMax = Convert.ToDouble(xDoc.Element("ARCXML").Element("RESPONSE").Element("SERVICEINFO").Element("PROPERTIES").Element("ENVELOPE").Attribute("maxy").Value);

                coorsys = Int32.Parse(xDoc.Element("ARCXML").Element("RESPONSE").Element("SERVICEINFO").Element("PROPERTIES").Element("FEATURECOORDSYS").Attribute("id").Value);

                // Get the ArcXml request
                this.SpatialReference = new SpatialReference(coorsys);

                FullExtent = new ESRI.ArcGIS.Client.Geometry.Envelope()
                {
                    XMin = XMin,
                    YMin = YMin,
                    XMax = XMax,
                    YMax = YMax,
                    SpatialReference = new SpatialReference(coorsys)
                };

                base.Initialize();
            }

            else if (xDoc.Element("ARCXML").Element("RESPONSE").Element("IMAGE") != null)
            {
                //AN IMAGE HAS BEEN RETURNED
                string imageUrl = xDoc.Element("ARCXML").Element("RESPONSE").Element("IMAGE").Element("OUTPUT").Attribute("url").Value;

                this.ImageUrl = imageUrl;

                ESRI.ArcGIS.Client.Geometry.Envelope newEnv = new Envelope();
                newEnv.XMin = Convert.ToDouble(xDoc.Element("ARCXML").Element("RESPONSE").Element("IMAGE").Element("ENVELOPE").Attribute("minx").Value);
                newEnv.YMin = Convert.ToDouble(xDoc.Element("ARCXML").Element("RESPONSE").Element("IMAGE").Element("ENVELOPE").Attribute("miny").Value);
                newEnv.YMax = Convert.ToDouble(xDoc.Element("ARCXML").Element("RESPONSE").Element("IMAGE").Element("ENVELOPE").Attribute("maxy").Value);
                newEnv.XMax = Convert.ToDouble(xDoc.Element("ARCXML").Element("RESPONSE").Element("IMAGE").Element("ENVELOPE").Attribute("maxx").Value);
                SpatialReference spRef = new SpatialReference(coorsys);
                newEnv.SpatialReference = spRef;
                _onComplete(this.ImageUrl, _width, _height, newEnv);

            }
            else if (xDoc.Element("ARCXML").Element("RESPONSE").Element("ERROR") != null)
            {
                //AN ERROR HAS BEEN RETURNED
                this.Cancel();

                this.ErrorMsg = xDoc.Element("ARCXML").Element("RESPONSE").Element("ERROR").Value;

                this.GetImageFailed(this, new EventArgs());

            }

            else
            {

                System.Diagnostics.Debug.WriteLine(string.Format("IMS Returned an unknown response" + xDoc.ToString()));
            }
        }
Example #39
0
        private void ConfigureApplication(ref Configuration xmlConfiguation)
        {
            Title  = xmlConfiguation.Title;
            Width  = xmlConfiguation.Width;
            Height = xmlConfiguation.Height;

            ParcelLines.MaxHeight = _xmlConfiguation.MaxGridHeight;

            // insert layer before [graphical] layers defined in xaml
            Int32  layerIndex = 0;
            String lastUnit   = "";

            foreach (LayerDefinition definition in xmlConfiguation.DisplayLayers)
            {
                if (definition.Type == "dynamic")
                {
                    ArcGISDynamicMapServiceLayer dynamicMS = new ArcGISDynamicMapServiceLayer();
                    dynamicMS.Url = definition.Url;
                    dynamicMS.ID  = definition.Id;
                    dynamicMS.InitializationFailed += Layer_InitializationFailed;
                    ParcelMap.Layers.Insert(layerIndex++, dynamicMS);
                    if ((dynamicMS.Units != null) && (dynamicMS.Units != "") && !xmlConfiguation.HasSpatialReferenceUnit)
                    {
                        lastUnit = dynamicMS.Units;
                    }
                }

                if (definition.Type == "feature")
                {
                    FeatureLayer featureMS = new FeatureLayer();
                    featureMS.Url = definition.Url + "/" + definition.Id.ToString();
                    featureMS.ID  = definition.Id;
                    featureMS.InitializationFailed += Layer_InitializationFailed;
                    featureMS.Mode = FeatureLayer.QueryMode.OnDemand;
                    ParcelMap.Layers.Insert(layerIndex++, featureMS);
                    // FOOBAR FeatureLayer does not support unit?
                }

                if (definition.Type == "tiled")
                {
                    ArcGISTiledMapServiceLayer tiledMS = new ArcGISTiledMapServiceLayer();
                    tiledMS.Url = definition.Url;
                    tiledMS.ID  = definition.Id;
                    tiledMS.InitializationFailed += Layer_InitializationFailed;
                    ParcelMap.Layers.Insert(layerIndex++, tiledMS);
                    if ((tiledMS.Units != null) && (tiledMS.Units != "") && !xmlConfiguation.HasSpatialReferenceUnit)
                    {
                        lastUnit = tiledMS.Units;
                    }
                }

                if (definition.Type == "image")
                {
                    ArcGISImageServiceLayer imageS = new ArcGISImageServiceLayer();
                    imageS.Url = definition.Url;
                    imageS.ID  = definition.Id;
                    imageS.InitializationFailed += Layer_InitializationFailed;
                    ParcelMap.Layers.Insert(layerIndex++, imageS);
                }
            }

            if (!xmlConfiguation.HasSpatialReferenceUnit)
            {
                xmlConfiguation.MapSpatialReferenceUnits = lastUnit;
            }

            ESRI.ArcGIS.Client.Geometry.Envelope extent = null;
            if (xmlConfiguation.IsExtentSet())
            {
                extent = new ESRI.ArcGIS.Client.Geometry.Envelope(xmlConfiguation.XMin, xmlConfiguation.YMin, xmlConfiguation.XMax, xmlConfiguation.YMax);
            }
            else
            {
                // Map will not zoom to, etc with out some value set.
                // Ideally we would like to set the extent to the full extent of the first
                // layer, but since they layer has hot been drawn yet null is returned.
                extent = new ESRI.ArcGIS.Client.Geometry.Envelope(100, 100, 100, 100);
            }

            // if zero, the first inserted layer is used
            if ((xmlConfiguation.SpatialReferenceWKT != null) && (xmlConfiguation.SpatialReferenceWKT != ""))
            {
                extent.SpatialReference = new ESRI.ArcGIS.Client.Geometry.SpatialReference(xmlConfiguation.SpatialReferenceWKT);
            }
            else if (xmlConfiguation.SpatialReferenceWKID != 0)
            {
                extent.SpatialReference = new ESRI.ArcGIS.Client.Geometry.SpatialReference(xmlConfiguation.SpatialReferenceWKID);
            }

            ParcelMap.Extent = extent;

            ParcelData parcelData = ParcelGridContainer.DataContext as ParcelData;

            parcelData.Configuration = xmlConfiguation;

            QueryLabel.Text = xmlConfiguation.QueryLabel;
        }
Example #40
0
 private bool OpenShapeFile()
 {
     System.Windows.Forms.OpenFileDialog ofd = new System.Windows.Forms.OpenFileDialog();
     ofd.Title            = App.Current.FindResource("tbSelectSHPFile").ToString();
     ofd.RestoreDirectory = true;
     ofd.Multiselect      = false;
     ofd.Filter           = "shape file (*.shp)|*.shp";
     if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
     {
         string shpFileName = ofd.FileName;
         string dbfFilename = Path.ChangeExtension(shpFileName, ".dbf");
         if (!ofd.CheckFileExists || !File.Exists(dbfFilename))
         {
             MessageBox.Show(App.Current.FindResource("msgSHPError").ToString(), App.Current.FindResource("msgError").ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
         else
         {
             try
             {
                 FileInfo  fiSHP     = new FileInfo(shpFileName);
                 FileInfo  fiDBF     = new FileInfo(dbfFilename);
                 ShapeFile shapeFile = new ShapeFile();
                 shapeFile.Read(fiSHP, fiDBF);
                 if (shapeFile.FileHeader.ShapeType != 5)
                 {
                     throw new Exception(App.Current.FindResource("msgSHPTypeError").ToString());
                 }
                 _graphicsLayer.ClearGraphics();
                 Envelope env = new Envelope();
                 foreach (ShapeFileRecord record in shapeFile.Records)
                 {
                     Graphic graphic = record.ToGraphic();
                     //if the coordinates is wgs 84,try to convert to 3857
                     if (Math.Abs(record.Points[0].X) < 300 || Math.Abs(record.Points[0].Y) < 300)
                     {
                         graphic.Geometry = _webMercator.FromGeographic(graphic.Geometry);
                     }
                     if (graphic != null)
                     {
                         graphic.Symbol = new SimpleFillSymbol()
                         {
                             BorderBrush = new SolidColorBrush(Colors.Red),
                             Fill        = new SolidColorBrush(Color.FromArgb(100, 255, 0, 0))
                         }
                     }
                     ;
                     _graphicsLayer.Graphics.Add(graphic);
                     env = env.Union(graphic.Geometry.Extent);
                 }
                 DownloadExtent   = _webMercator.ToGeographic(env).Extent;
                 _downloadPolygon = AppUtility.ConvertEsriPolygonToPBSPolygon(AppUtility.UnionEsriPolygon(_graphicsLayer.Graphics));
                 return(true);
             }
             catch (Exception e)
             {
                 MessageBox.Show(e.Message, App.Current.FindResource("msgError").ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
     }
     return(false);
 }
Example #41
0
        private void ConfigureApplication(ref Configuration xmlConfiguation)
        {
            Title = xmlConfiguation.Title;
              Width = xmlConfiguation.Width;
              Height = xmlConfiguation.Height;

              ParcelLines.MaxHeight = _xmlConfiguation.MaxGridHeight;

              // insert layer before [graphical] layers defined in xaml
              Int32 layerIndex = 0;
              String lastUnit = "";
              foreach (LayerDefinition definition in xmlConfiguation.DisplayLayers)
              {
            if (definition.Type == "dynamic")
            {
              ArcGISDynamicMapServiceLayer dynamicMS = new ArcGISDynamicMapServiceLayer();
              dynamicMS.Url = definition.Url;
              dynamicMS.ID = definition.Id;
              dynamicMS.InitializationFailed += Layer_InitializationFailed;
              ParcelMap.Layers.Insert(layerIndex++, dynamicMS);
              if ((dynamicMS.Units != null) && (dynamicMS.Units != "") && !xmlConfiguation.HasSpatialReferenceUnit)
            lastUnit = dynamicMS.Units;
            }

            if (definition.Type == "feature")
            {
              FeatureLayer featureMS = new FeatureLayer();
              featureMS.Url = definition.Url + "/" + definition.Id.ToString();
              featureMS.ID = definition.Id;
              featureMS.InitializationFailed += Layer_InitializationFailed;
              featureMS.Mode = FeatureLayer.QueryMode.OnDemand;
              ParcelMap.Layers.Insert(layerIndex++, featureMS);
              // FOOBAR FeatureLayer does not support unit?
            }

            if (definition.Type == "tiled")
            {
              ArcGISTiledMapServiceLayer tiledMS = new ArcGISTiledMapServiceLayer();
              tiledMS.Url = definition.Url;
              tiledMS.ID = definition.Id;
              tiledMS.InitializationFailed += Layer_InitializationFailed;
              ParcelMap.Layers.Insert(layerIndex++, tiledMS);
              if ((tiledMS.Units != null) && (tiledMS.Units != "") && !xmlConfiguation.HasSpatialReferenceUnit)
            lastUnit = tiledMS.Units;
            }

            if (definition.Type == "image")
            {
              ArcGISImageServiceLayer imageS = new ArcGISImageServiceLayer();
              imageS.Url = definition.Url;
              imageS.ID = definition.Id;
              imageS.InitializationFailed += Layer_InitializationFailed;
              ParcelMap.Layers.Insert(layerIndex++, imageS);
            }
              }

              if (!xmlConfiguation.HasSpatialReferenceUnit)
            xmlConfiguation.MapSpatialReferenceUnits = lastUnit;

              ESRI.ArcGIS.Client.Geometry.Envelope extent = null;
              if (xmlConfiguation.IsExtentSet())
            extent = new ESRI.ArcGIS.Client.Geometry.Envelope(xmlConfiguation.XMin, xmlConfiguation.YMin, xmlConfiguation.XMax, xmlConfiguation.YMax);
              else
            // Map will not zoom to, etc with out some value set.
            // Ideally we would like to set the extent to the full extent of the first
            // layer, but since they layer has hot been drawn yet null is returned.
            extent = new ESRI.ArcGIS.Client.Geometry.Envelope(100, 100, 100, 100);

              // if zero, the first inserted layer is used
              if ((xmlConfiguation.SpatialReferenceWKT != null) && (xmlConfiguation.SpatialReferenceWKT != ""))
            extent.SpatialReference = new ESRI.ArcGIS.Client.Geometry.SpatialReference(xmlConfiguation.SpatialReferenceWKT);
              else if (xmlConfiguation.SpatialReferenceWKID != 0)
            extent.SpatialReference = new ESRI.ArcGIS.Client.Geometry.SpatialReference(xmlConfiguation.SpatialReferenceWKID);

              ParcelMap.Extent = extent;

              ParcelData parcelData = ParcelGridContainer.DataContext as ParcelData;
              parcelData.Configuration = xmlConfiguation;

              QueryLabel.Text = xmlConfiguation.QueryLabel;
        }
        private void LoadMapButton_Click(object sender, RoutedEventArgs e)
        {
            WebClient webClient = new WebClient();
            string    uri       = string.Format("http://dev.virtualearth.net/REST/v1/Imagery/Metadata/Aerial?supressStatus=true&key={0}", BingKeyTextBox.Text);

            webClient.OpenReadCompleted += (s, a) =>
            {
                if (a.Error == null)
                {
                    DataContractJsonSerializer serializer         = new DataContractJsonSerializer(typeof(BingAuthentication));
                    BingAuthentication         bingAuthentication = serializer.ReadObject(a.Result) as BingAuthentication;
                    a.Result.Close();
                    string authenticationResult = bingAuthentication.AuthenticationResultCode.ToString();

                    if (authenticationResult == "ValidCredentials")
                    {
                        ESRI.ArcGIS.Client.Bing.TileLayer tileLayer = new TileLayer()
                        {
                            ID         = "BingLayer",
                            LayerStyle = TileLayer.LayerType.Road,
                            ServerType = ServerType.Production,
                            Token      = BingKeyTextBox.Text
                        };

                        MyMap.Layers.Insert(0, tileLayer);

                        // Add your Bing Maps key in the constructor for the Routing class. Use http://www.bingmapsportal.com to generate a key.
                        routing            = new ESRI.ArcGIS.Client.Bing.Routing(BingKeyTextBox.Text);
                        routing.ServerType = ServerType.Production;

                        myDrawObject = new Draw(MyMap)
                        {
                            DrawMode  = DrawMode.Point,
                            IsEnabled = true
                        };

                        myDrawObject.DrawComplete += MyDrawObject_DrawComplete;
                        waypointGraphicsLayer      = MyMap.Layers["WaypointGraphicsLayer"] as GraphicsLayer;
                        routeResultsGraphicsLayer  = MyMap.Layers["RouteResultsGraphicsLayer"] as GraphicsLayer;

                        ESRI.ArcGIS.Client.Geometry.Envelope initialExtent =
                            new ESRI.ArcGIS.Client.Geometry.Envelope(
                                mercator.FromGeographic(
                                    new ESRI.ArcGIS.Client.Geometry.MapPoint(-130, 20)) as MapPoint,
                                mercator.FromGeographic(
                                    new ESRI.ArcGIS.Client.Geometry.MapPoint(-65, 55)) as MapPoint);

                        initialExtent.SpatialReference = new SpatialReference(102100);

                        MyMap.Extent = initialExtent;

                        BingKeyGrid.Visibility = System.Windows.Visibility.Collapsed;
                        RouteGrid.Visibility   = System.Windows.Visibility.Visible;

                        InvalidBingKeyTextBlock.Visibility = System.Windows.Visibility.Collapsed;
                    }
                    else
                    {
                        InvalidBingKeyTextBlock.Visibility = System.Windows.Visibility.Visible;
                    }
                }
                else
                {
                    InvalidBingKeyTextBlock.Visibility = System.Windows.Visibility.Visible;
                }
            };

            webClient.OpenReadAsync(new System.Uri(uri));
        }
        private void LoadMapButton_Click(object sender, RoutedEventArgs e)
        {
            WebClient webClient = new WebClient();
            string uri = string.Format("http://dev.virtualearth.net/REST/v1/Imagery/Metadata/Aerial?supressStatus=true&key={0}", BingKeyTextBox.Text);

            webClient.OpenReadCompleted += (s, a) =>
            {
                if (a.Error == null)
                {
                    DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(BingAuthentication));
                    BingAuthentication bingAuthentication = serializer.ReadObject(a.Result) as BingAuthentication;
                    a.Result.Close();

                    if (bingAuthentication.authenticationResultCode == "ValidCredentials")
                    {
                        ESRI.ArcGIS.Client.Bing.TileLayer tileLayer = new TileLayer()
                        {
                            ID = "BingLayer",
                            LayerStyle = TileLayer.LayerType.Road,
                            ServerType = ServerType.Production,
                            Token = BingKeyTextBox.Text
                        };

                        MyMap.Layers.Insert(0, tileLayer);

                        // Add your Bing Maps key in the constructor for the Routing class. Use http://www.bingmapsportal.com to generate a key.
                        routing = new ESRI.ArcGIS.Client.Bing.Routing(BingKeyTextBox.Text);
                        routing.ServerType = ServerType.Production;

                        myDrawObject = new Draw(MyMap)
                        {
                            DrawMode = DrawMode.Point,
                            IsEnabled = true
                        };

                        myDrawObject.DrawComplete += MyDrawObject_DrawComplete;
                        waypointGraphicsLayer = MyMap.Layers["WaypointGraphicsLayer"] as GraphicsLayer;
                        routeResultsGraphicsLayer = MyMap.Layers["RouteResultsGraphicsLayer"] as GraphicsLayer;

                        ESRI.ArcGIS.Client.Geometry.Envelope initialExtent =
                            new ESRI.ArcGIS.Client.Geometry.Envelope(-13064142.2218876, 3831722.30101942, -13023209.4358361, 3878454.82787388);

                        initialExtent.SpatialReference = new SpatialReference(102100);

                        MyMap.Extent = initialExtent;

                        BingKeyGrid.Visibility = System.Windows.Visibility.Collapsed;
                        DialogsGrid.Visibility = System.Windows.Visibility.Visible;

                        InvalidBingKeyTextBlock.Visibility = System.Windows.Visibility.Collapsed;

                    }
                    else InvalidBingKeyTextBlock.Visibility = System.Windows.Visibility.Visible;
                }
                else InvalidBingKeyTextBlock.Visibility = System.Windows.Visibility.Visible;
            };

            webClient.OpenReadAsync(new System.Uri(uri));
        }
Example #44
0
        /// <summary>
        /// Gets the URL. Override from DynamicMapServiceLayer
        /// </summary>
        /// <param name="extent">The extent.</param>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="onComplete">OnUrlComplete delegate.</param>
        /// <remarks>
        /// The Map has a private method loadLayerInView which calls Layer.Draw.
        /// The DynamicMapServiceLayer abstract class overrides the Draw method and calls
        /// DynamicMapServiceLayer.GetUrl which must be implemented in a subclass.
        /// The last parameter is the OnUrlComplete delegate, which is used to pass the appropriate values
        /// (url, width, height, envelope) to the private DynamicMapServiceLayer.getUrlComplete method.
        /// </remarks>
        public void GetUrl(ESRI.ArcGIS.Client.Geometry.Envelope extent, int width, int height,
                           DynamicMapServiceLayer.OnUrlComplete onComplete)
        {
            int           extentWKID = extent.SpatialReference.WKID;
            string        baseUrl    = httpGetResource ?? Url;
            StringBuilder mapURL     = new StringBuilder(baseUrl);

            if (!baseUrl.Contains("?"))
            {
                mapURL.Append("?");
            }
            else if (!baseUrl.EndsWith("&"))
            {
                mapURL.Append("&");
            }
            mapURL.Append("SERVICE=WMS");
            mapURL.Append("&REQUEST=GetMap");
            mapURL.AppendFormat("&WIDTH={0}", width);
            mapURL.AppendFormat("&HEIGHT={0}", height);
            mapURL.AppendFormat("&FORMAT={0}", "image/png");
            mapURL.AppendFormat("&LAYERS={0}", String.Join(",", Layers));
            mapURL.Append("&STYLE=");
            mapURL.AppendFormat("&BGCOLOR={0}", "0xFFFFFF");
            mapURL.AppendFormat("&TRANSPARENT={0}", "true");

            mapURL.AppendFormat("&VERSION={0}", Version);

            switch (Version)
            {
            case ("1.1.1"):
                mapURL.AppendFormat("&SRS=EPSG:{0}", extentWKID);
                mapURL.AppendFormat("&bbox={0},{1},{2},{3}", extent.XMin, extent.YMin, extent.XMax, extent.YMax);
                break;

            case ("1.3"):
            case ("1.3.0"):
                mapURL.AppendFormat("&CRS=EPSG:{0}", extentWKID);

                bool useLatLong = false;
                int  length     = LatLongCRSRanges.Length / 2;
                for (int count = 0; count < length; count++)
                {
                    if (extentWKID >= LatLongCRSRanges[count, 0] && extentWKID <= LatLongCRSRanges[count, 1])
                    {
                        useLatLong = true;
                        break;
                    }
                }

                if (useLatLong)
                {
                    mapURL.AppendFormat(CultureInfo.InvariantCulture,
                                        "&BBOX={0},{1},{2},{3}", extent.YMin, extent.XMin, extent.YMax, extent.XMax);
                }
                else
                {
                    mapURL.AppendFormat(CultureInfo.InvariantCulture,
                                        "&BBOX={0},{1},{2},{3}", extent.XMin, extent.YMin, extent.XMax, extent.YMax);
                }
                break;
            }

            onComplete(PrefixProxy(mapURL.ToString()).AbsoluteUri, new ImageResult(new ESRI.ArcGIS.Client.Geometry.Envelope()
            {
                XMin = extent.XMin,
                YMin = extent.YMin,
                XMax = extent.XMax,
                YMax = extent.YMax
            }));
        }
Example #45
0
        protected virtual void StartButtonClicked(object parameters)
        {
            if (!PBS.Util.Utility.IsValidFilename(Output))
            {
                MessageBox.Show(App.Current.FindResource("msgOutputPathError").ToString(), App.Current.FindResource("msgError").ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (File.Exists(Output))
            {
                if (MessageBox.Show(App.Current.FindResource("msgOverwrite").ToString(), App.Current.FindResource("msgWarning").ToString(), MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No)
                {
                    return;
                }
                else
                {
                    try
                    {
                        File.Delete(Output);
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show(e.Message, App.Current.FindResource("msgError").ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }
            }
            try
            {
                Datasource = new DataSourceCustomOnlineMaps(SelectedDatasourceType);

                Datasource.ConvertCompleted += (s, a) =>
                {
                    if (a.Successful)
                    {
                        string str = App.Current.FindResource("msgConvertComplete").ToString();
                        if (DoCompact)
                        {
                            str += "\r\n" + App.Current.FindResource("msgCompactResult").ToString() + (Datasource.ConvertingStatus.SizeBeforeCompact / 1024).ToString("N0") + "KB --> " + (Datasource.ConvertingStatus.SizeAfterCompact / 1024).ToString("N0") + "KB";
                        }
                        MessageBox.Show(str, "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                };
                Datasource.ConvertCancelled += (s, a) =>
                {
                };
                BackgroundWorker bw = new BackgroundWorker();
                bw.DoWork += (s, a) =>
                {
                    IsIdle = false;
                    App.Current.Dispatcher.Invoke(new Action(() =>
                    {
                        (CMDClickStartButton as DelegateCommand).RaiseCanExecuteChanged();
                    }));
                    Envelope extent = (Envelope)_webMercator.FromGeographic(DownloadExtent);
                    try
                    {
                        PBS.Util.Geometry g = _downloadPolygon == null ? (PBS.Util.Geometry) new PBS.Util.Envelope(extent.XMin, extent.YMin, extent.XMax, extent.YMax) : _downloadPolygon;
                        if (_downloadPolygon != null)
                        {
                            MessageBox.Show(App.Current.FindResource("msgDownloadByPolygonIntro").ToString(), "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        Datasource.ConvertToMBTiles(Output, Name, Description, Attribution, Levels, g, DoCompact);
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show(e.Message, App.Current.FindResource("msgError").ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    IsIdle = true;
                    App.Current.Dispatcher.Invoke(new Action(() =>
                    {
                        (CMDClickStartButton as DelegateCommand).RaiseCanExecuteChanged();
                    }));
                };
                bw.RunWorkerAsync();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }