示例#1
0
        protected override 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
            {
                string version = null;
                if (SelectedDatasourceType == "BaiduSate" || SelectedDatasourceType == "BaiduBase")
                {
                    version = "009";
                }
                else if (SelectedDatasourceType == "BaiduPanoMark")
                {
                    version = BaiDuMapManager.inst.streetudt;
                }
                else
                {
                    version = BaiDuMapManager.inst.cp.getLastVersion();
                }
                Datasource = new DataSourceBaiduOnlineMap(SelectedDatasourceType)
                {
                    OutputFileName = Output, Version = version, autoCorrectCoord = true
                };

                (Datasource as DataSourceBaiduOnlineMap).ConvertCompleted += (s, a) =>
                {
                    if (a.Successful)
                    {
                        if (!AutoConfirm)
                        {
                            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);
                        }


                        DataSourceAdjustCoord transferSource = new DataSourceAdjustCoord(Output);
                        Datasource = transferSource;
                        (transferSource as DataSourceAdjustCoord).ConvertCompleted += (s1, a1) =>
                        {
                            string str1 = App.Current.FindResource("msgAdjustComplete").ToString();
                            MessageBox.Show(str1, "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        };
                        transferSource.ConvertToMBTiles(Output, "", "", "", Levels, null, false);
                    }
                };
                Datasource.ConvertCancelled += (s, a) =>
                {
                };
                BackgroundWorker bw = new BackgroundWorker();
                bw.DoWork += (s, a) =>
                {
                    IsIdle = false;
                    App.Current.Dispatcher.Invoke(new Action(() =>
                    {
                        (CMDClickStartButton as DelegateCommand).RaiseCanExecuteChanged();
                    }));
                    ESRI.ArcGIS.Client.Geometry.Envelope extent = (ESRI.ArcGIS.Client.Geometry.Envelope)_webMercator.FromGeographic(DownloadExtent);
                    try
                    {
                        PBS.Util.Geometry g = _downloadPolygon == null ? (PBS.Util.Geometry) new PBS.Util.Envelope(DownloadExtent.XMin, DownloadExtent.YMin, DownloadExtent.XMax, DownloadExtent.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);
            }
        }
 private 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) =>
         {
             //try
             //{
             //    //aa.mbtiles and aa.mbtiles-journal
             //    if (File.Exists(Output))
             //    {
             //        File.Delete(Output);
             //    }
             //    if (File.Exists(Output + "-journal"))
             //    {
             //        File.Delete(Output + "-journal");
             //    }
             //}
             //catch (Exception e)
             //{
             //    throw new Exception(".mbtiles and .mbtiles-journal files could not be deleted.\r\n" + e.Message);
             //}
         };
         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);
     }
 }