Example #1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="name"></param>
 /// <param name="levels"></param>
 /// <param name="env">wkid of envelope must be 4326</param>
 /// <param name="polygon">If null, means download extent is rectangle and drawed by using mouse by user; if not null, means download extent is a polygon by importing a shapefile.</param>
 public DownloadProfile(string name, int[] levels, PBS.Util.Envelope env, PBS.Util.Polygon polygon)
 {
     Name     = name;
     Levels   = levels;
     Envelope = env;
     Polygon  = polygon;
 }
Example #2
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 #3
0
 protected void MouseRightButtonDown(object sender, MouseButtonEventArgs e)
 {
     if (!IsIdle || SelectedIndexOfDrawExtentMethod != 0)
     {
         return;
     }
     _startPoint             = _map.ScreenToMap(e.GetPosition(_map));
     _isRightMouseButtonDown = true;
     _graphicsLayer.ClearGraphics();
     _graphicsLayer.Graphics.Add(new Graphic()
     {
         Symbol = new SimpleFillSymbol()
         {
             BorderBrush = new SolidColorBrush(Colors.Red),
             Fill        = new SolidColorBrush(Color.FromArgb(100, 255, 0, 0))
         }
     });
     _downloadPolygon = null;
 }
Example #4
0
 public static ESRI.ArcGIS.Client.Geometry.Polygon ConvertPBSPolygonToEsriPolygon(PBS.Util.Polygon pPolygon)
 {
     ESRI.ArcGIS.Client.Geometry.Polygon ePolygon = new ESRI.ArcGIS.Client.Geometry.Polygon();
     foreach (PBS.Util.PointCollection pPC in pPolygon.Rings)
     {
         ESRI.ArcGIS.Client.Geometry.PointCollection ePC = new ESRI.ArcGIS.Client.Geometry.PointCollection();
         foreach (PBS.Util.Point pPoint in pPC)
         {
             ePC.Add(new MapPoint(pPoint.X, pPoint.Y));
         }
         ePolygon.Rings.Add(ePC);
     }
     return(ePolygon);
 }
Example #5
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);
 }