private void StartButtonClicked(object parameters)
        {
            if (!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
            {
                TilingScheme tilingScheme = PBS.Service.SchemaProvider.Inst.getSchema("OtherMap", null, null);

                var   lods   = tilingScheme.LODs;
                int[] Levels = new int[lods.Count()];
                int   i      = 0;
                foreach (var lod in lods)
                {
                    Levels[i] = lod.LevelID;
                    i++;
                }

                PBS.Util.Envelope g        = PBS.Service.SchemaProvider.Inst.getDownloadExtend("OtherMap");
                string            fileDest = Output;
                Datasource = new DataSourceOtherMap("", true)
                {
                    OutputFileName = Output, downloadExtent = g
                };
                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;
                    try
                    {
                        Datasource.ConvertToMBTiles(fileDest, "", "", "", Levels, g, false);
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show(e.Message, App.Current.FindResource("msgError").ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    IsIdle = true;
                };
                bw.RunWorkerAsync();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
Exemple #2
0
        //public List<??> PendingTiles { get; set; }//arcgis silverlight api using this for only calculate progress
        /// <summary>
        ///
        /// </summary>
        /// <param name="serviceName"></param>
        /// <param name="dataSourcePath"></param>
        /// <param name="port"></param>
        /// <param name="strType">DataSourceType enum + custom online maps</param>
        /// <param name="disableClientCache"></param>
        /// <param name="displayNodataTile"></param>
        /// <param name="tilingSchemePath">Set this parameter only when type is ArcGISDynamicMapService||RasterDataset and do not use Google Maps's tiling scheme</param>
        public PBSService(string serviceName, string dataSourcePath, int port, string strType, string strSubType, bool allowmemcache, bool disableClientCache, bool displayNodataTile, VisualStyle style, string tilingSchemePath)
        {
            ServiceName = serviceName;
            string prefixName = "KGIS";

            if (!DataSourceBase.IsOnlineMaps(strType))
            {
                DataSourceTypePredefined type = (DataSourceTypePredefined)Enum.Parse(typeof(DataSourceTypePredefined), strType);
                switch (type)
                {
                case DataSourceTypePredefined.MobileAtlasCreator:
                    DataSource = new DataSourceMAC(dataSourcePath);
                    break;

                case DataSourceTypePredefined.BaiduMBTiles:
                    DataSource = new DataSourceBaiDuMBTiles(dataSourcePath);
                    break;

                case DataSourceTypePredefined.GoogleMBTiles:
                    DataSource = new DataSourceGoogleMBTiles(dataSourcePath);
                    break;

                case DataSourceTypePredefined.OtherMap:
                    if (String.IsNullOrEmpty(strSubType))
                    {
                        DataSource = new DataSourceOtherMap(dataSourcePath, false)
                        {
                            Path = dataSourcePath
                        };
                    }
                    else if (String.Equals("PGISRoad", strSubType))
                    {
                        DataSource = new DataSourceOtherMapProxy("PGISRoad")
                        {
                            Type    = strType,
                            subType = strSubType
                        };
                    }
                    else if (String.Equals("PGISRoadMark", strSubType))
                    {
                        DataSource = new DataSourceOtherMapProxy("PGISRoadMark")
                        {
                            Type    = strType,
                            subType = strSubType
                        };
                    }
                    else if (String.Equals("PGISImagery", strSubType))
                    {
                        DataSource = new DataSourceOtherMapProxy("PGISImagery")
                        {
                            Type    = strType,
                            subType = strSubType
                        };
                    }
                    else if (String.Equals("TaiZhou", strSubType))
                    {
                        DataSource = new DataSourceOtherMapProxy("TaiZhou")
                        {
                            Type    = strType,
                            subType = strSubType
                        };
                    }
                    else if (String.Equals("GanSu", strSubType))
                    {
                        DataSource = new DataSourceMultiMBTiles(strType, strSubType);
                    }
                    break;

                case DataSourceTypePredefined.MBTiles:
                    DataSource = new DataSourceMBTiles(dataSourcePath);
                    break;

                case DataSourceTypePredefined.ArcGISCache:
                    DataSource = new DataSourceArcGISCache(dataSourcePath);
                    break;

                case DataSourceTypePredefined.ArcGISTilePackage:
                    DataSource = new DataSourceArcGISTilePackage(dataSourcePath);
                    break;

                case DataSourceTypePredefined.RasterImage:
                    DataSource = new DataSourceRasterImage(dataSourcePath, tilingSchemePath, ServiceName);
                    break;

                case DataSourceTypePredefined.ArcGISDynamicMapService:
                    DataSource = new DataSourceArcGISDynamicMapService(dataSourcePath, tilingSchemePath);
                    break;

                case DataSourceTypePredefined.ArcGISTiledMapService:
                    DataSource = new DataSourceArcGISTiledMapService(dataSourcePath, tilingSchemePath);
                    break;

                case DataSourceTypePredefined.ArcGISImageService:
                    DataSource = new DataSourceArcGISImageService(dataSourcePath, tilingSchemePath);
                    break;

                case DataSourceTypePredefined.AutoNaviCache:
                    DataSource = new DataSourceAutoNaviCache(dataSourcePath);
                    break;

                case DataSourceTypePredefined.OGCWMSService:
                    DataSource = new DataSourceWMSService(dataSourcePath, tilingSchemePath);
                    break;

                case DataSourceTypePredefined.TianDiTuAnnotation:
                    DataSource = new DataSourceTianDiTuAnno();
                    break;

                case DataSourceTypePredefined.TianDiTuMap:
                    DataSource = new DataSourceTianDiTuMap();
                    break;

                case DataSourceTypePredefined.BaiDuOnline:
                    if (BaiDuMapManager.inst.RunMode == "ONLINE")
                    {
                        DataSource = new DataSourceBaiDuTileProxy(strType);
                    }
                    else
                    {
                        DataSource = new DataSourceBaiDuMBTiles(null);
                    }
                    break;

                default:
                    throw new Exception();
                }
                DataSource.IsOnlineMap = false;
            }
            else
            {
                bool known = false;
                foreach (var map in DataSourceCustomOnlineMaps.CustomOnlineMaps)
                {
                    if (map.Name == strType)
                    {
                        known = true;
                        break;
                    }
                }
                foreach (var map in DataSourceBaiduOnlineMap.CustomOnlineMaps)
                {
                    if (map.Name == strType)
                    {
                        known = true;
                        break;
                    }
                }
                if (!known)
                {
                    throw new Exception(strType + " is not a known data source type.");
                }
                switch (strType)
                {
                //this options is a list of preview of baidu map download window, except BaiduPanoMark
                case "BaiduTrafficHis":
                case "BaiduBase":
                case "BaiduHot":
                case "BaiduSate":
                case "BaiduTraffic":
                case "BaiduPanoMark":
                    DataSource = new DataSourceBaiDuTileProxy("BaiDuOnline")
                    {
                        IsOnlineMap = true,
                        SubType     = strType
                    };
                    break;

                default:
                    DataSource = new DataSourceCustomOnlineMaps(strType)
                    {
                        IsOnlineMap = true
                    };
                    break;
                }
            }


            Port               = port;
            AllowMemCache      = allowmemcache;
            DisableClientCache = disableClientCache;
            DisplayNoDataTile  = displayNodataTile;
            Style              = style;
            LogInfo            = new Log();
            if (string.IsNullOrEmpty(ServiceManager.IPAddress))
            {
                throw new Exception("IPAddress is null or empty when creating PBS service!");
            }
            UrlArcGIS = "http://" + ServiceManager.IPAddress + ":" + Port + "/" + prefixName + "/rest/services/" + ServiceName + "/MapServer";
        }