Exemple #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            extent.Add(double.Parse(textBox3.Text));
            extent.Add(double.Parse(textBox4.Text));
            extent.Add(double.Parse(textBox5.Text));
            extent.Add(double.Parse(textBox2.Text));

            var tile = comboBox1.SelectedItem;

            if (tile == null)
            {
                MessageBox.Show("请选择至少一种地图");
                return;
            }
            EnumBruTileLayer enumBruTileLayer = (EnumBruTileLayer)Enum.Parse(typeof(EnumBruTileLayer), tile.ToString());
            IConfig          config           = ConfigHelper.GetConfig(enumBruTileLayer);
            string           cacheDir         = CacheSettings.GetCacheFolder();

            tileSource   = config.CreateTileSource();
            schema       = tileSource.Schema;
            tileProvider = (WebTileProvider)tileSource.Provider;
            fileCache    = CacheDirectory.GetFileCache(cacheDir, config, enumBruTileLayer);

            _tiles = GetTile();


            if (_tiles.ToList().Count > 0)
            {
                DownloadTiles();
            }
        }
        public void ProcessRequest(HttpContext context)
        {
            RuntimeManager.BindLicense(ProductCode.EngineOrDesktop);
            extent  = context.Request.QueryString["Extent"].Split(new[] { ',' }).Select(Convert.ToDouble).ToList();
            level   = double.Parse(context.Request.QueryString["level"]);
            _config = ConfigHelper.GetConfig(EnumBruTileLayer.OSM);

            _tileSource   = _config.CreateTileSource();
            _tileProvider = (WebTileProvider)_tileSource.Provider;


            _cacheDir = CacheSettings.GetCacheFolder();

            _fileCache = CacheDirectory.GetFileCache(_cacheDir, _config, EnumBruTileLayer.OSM);
            Draw();
            //using (Bitmap map = new Bitmap(@"D:\我的文件\天津师大切片解决方案\DownloadTiles\DownloadTiles\bin\Debug\p.png"))
            using (Bitmap map = mosaicImage())
            {
                using (MemoryStream mem = new MemoryStream())
                {
                    map.Save(mem, ImageFormat.Png);
                    mem.Seek(0, SeekOrigin.Begin);

                    context.Response.ContentType = "image/png";

                    mem.CopyTo(context.Response.OutputStream, 4096);
                    context.Response.Flush();
                }
            }
        }
        public void DoMainTask(DateTime time, string _extent, string basePath, string tileDir, string csv)
        {
            this.basePath = basePath;
            this.csv      = csv;

            extent        = _extent.Split(new[] { ',' }).Select(Convert.ToDouble).ToList();
            _config       = ConfigHelper.GetConfig(EnumBruTileLayer.OSM);
            _tileSource   = _config.CreateTileSource();
            _tileProvider = (WebTileProvider)_tileSource.Provider;


            _cacheDir = CacheSettings.GetCacheFolder(tileDir);


            while (true)
            {
                try
                {
                    DeleteDirectory(_cacheDir);
                    break;
                }
                catch (Exception ex)
                {
                    LogManager.LogPath = AppDomain.CurrentDomain.BaseDirectory + "\\log\\";
                    LogManager.WriteLog("error", ex.Message);
                }
            }


            _fileCache = CacheDirectory.GetFileCache(_cacheDir, _config, EnumBruTileLayer.OSM);
            Draw();
            var           map       = mosaicImage();
            DirectoryInfo directory =
                new DirectoryInfo(basePath + time.ToString("yyyy") + "\\" + time.ToString("yyyyMMdd") + "\\" +
                                  time.ToString("yyyyMMddHHmm"));

            if (!directory.Exists)
            {
                directory.Create();
            }
            map.Save(directory.FullName + "\\traffic.png");
            CreateTrafficCsv(directory);
        }
        public void Draw(esriDrawPhase drawPhase, IDisplay display, ITrackCancel trackCancel)
        {
            switch (drawPhase)
            {
            case esriDrawPhase.esriDPGeography:
                if (Valid)
                {
                    if (Visible)
                    {
                        try
                        {
                            var clipEnvelope = display.ClipEnvelope;

                            // when loading from a file the active map doesn't exist yet
                            // so just deal with it here.
                            if (_map == null)
                            {
                                var mxdoc = (IMxDocument)_application.Document;
                                _map = mxdoc.FocusMap;
                            }

                            Debug.WriteLine("Draw event");
                            var activeView = _map as IActiveView;
                            Logger.Debug("Layer name: " + Name);

                            if (activeView != null)
                            {
                                //_envelope = activeView.Extent;
                                //_envelope = clipEnvelope;

                                Logger.Debug("Draw extent: xmin:" + clipEnvelope.XMin +
                                             ", ymin:" + clipEnvelope.YMin +
                                             ", xmax:" + clipEnvelope.XMax +
                                             ", ymax:" + clipEnvelope.YMax
                                             );
                                if (SpatialReference != null)
                                {
                                    Logger.Debug("Layer spatial reference: " + SpatialReference.FactoryCode);
                                }
                                if (_map.SpatialReference != null)
                                {
                                    Logger.Debug("Map spatial reference: " + _map.SpatialReference.FactoryCode);
                                }

                                var bruTileHelper = new BruTileHelper(_tileTimeOut);
                                _displayFilter.Transparency = (short)(255 - ((_transparency * 255) / 100));
                                if (display.Filter == null)
                                {
                                    display.Filter = _displayFilter;
                                }

                                FileCache fileCache;

                                if (_config != null)
                                {
                                    fileCache = CacheDirectory.GetFileCache(_cacheDir, _config, _enumBruTileLayer);
                                }
                                else
                                {
                                    fileCache = CacheDirectory.GetFileCache(_cacheDir, _tileSource, _enumBruTileLayer);
                                }

                                if (_enumBruTileLayer == EnumBruTileLayer.Giscloud &&
                                    _config.CreateTileSource().Schema.Format == "jpg")
                                {
                                    // potential black borders: need to add a check for clip....
                                    bruTileHelper.ClipTilesEnvelope = _envelope;
                                }
                                bruTileHelper.Draw(_application.StatusBar.ProgressBar, activeView, fileCache, trackCancel, SpatialReference, ref _currentLevel, _tileSource, display, _auth);
                            }
                        }
                        catch (Exception ex)
                        {
                            var mbox = new ExceptionMessageBox(ex);
                            mbox.Show(null);
                        }
                    }  // isVisible
                }      // isValid
                break;

            case esriDrawPhase.esriDPAnnotation:
                break;
            }
        }