Example #1
0
        private void SelectCombo_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            GeoPoint newCenter = GetMapCenter();

            switch (selectCombo.SelectedIndex)
            {
            case 0:     // Bing
                _downloadAerial = new BingAerialRepository();
                if (_isMapLoaded)
                {
                    map.Center    = new Location(newCenter.lat, newCenter.lng);
                    map.ZoomLevel = Convert.ToInt32(wbMain.InvokeScript("getZoomLevel"));
                }
                map.Visibility    = Visibility.Visible;
                wbMain.Visibility = Visibility.Hidden;
                _mapSource        = MapSource.Bing;
                break;

            case 1:     // Google Maps
                _downloadAerial = new GoogleMapsAerialRepository();
                if (_isMapLoaded)
                {
                    wbMain.InvokeScript("setCenter", $"{newCenter.lat},{newCenter.lng}");
                    wbMain.InvokeScript("setZoom", map.ZoomLevel);
                }
                wbMain.Visibility = Visibility.Visible;
                map.Visibility    = Visibility.Hidden;
                _mapSource        = MapSource.Google;
                break;
            }
        }
Example #2
0
        private void DownloadImage(string requestUrl, MapType mapType)
        {
            SaveFileDialog fileDialog = new SaveFileDialog();
            string         format     = AerialRepository.GetFormatForMapType(mapType);

            if (_currentDirectory != null)
            {
                fileDialog.InitialDirectory = _currentDirectory;
            }

            fileDialog.Filter = $"Image File (*.{format})|*.{format}";
            if (fileDialog.ShowDialog() == true)
            {
                string fileName = fileDialog.FileName;
                try
                {
                    AerialRepository.DownloadImage(requestUrl, fileName);

                    Close();

                    _imageData.FileName = fileName;
                    _callback?.Invoke(_mapSource, _imageData);
                }
                catch (Exception ex)
                {
                    string msg = "An error occurred saving the image.\n" + ex.Message + "\nPlease try again.";
                    MessageBox.Show(msg);
                }
            }
        }
Example #3
0
        public void UpdateAerial()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;

            if (doc == null)
            {
                return;
            }

            Editor ed = doc.Editor;

            // Select an aerial entity to update
            PromptEntityResult entityResult = ed.GetEntity("Pick an aerial to update : ");

            if (entityResult.Status == PromptStatus.OK)
            {
                // Create a new transaction to contain the update
                Transaction tx = doc.TransactionManager.StartTransaction();

                try
                {
                    // Get the aerial entity object and try to read its extension dictionary
                    RasterImage aerialEnt = tx.GetObject(entityResult.ObjectId, OpenMode.ForRead) as RasterImage;

                    if (aerialEnt.ExtensionDictionary.IsNull)
                    {
                        throw new Exception(ErrorStatus.InvalidInput, "Unrecognized aerial image.");
                    }

                    // Get the extension dictionary object
                    DBDictionary extDict = tx.GetObject(aerialEnt.ExtensionDictionary, OpenMode.ForRead) as DBDictionary;

                    if (!extDict.Contains("ImageData"))
                    {
                        throw new Exception(ErrorStatus.InvalidInput, "Unrecognized aerial image.");
                    }

                    // Get the associated image data
                    ObjectId boundsEntryId = extDict.GetAt("ImageData");
                    Xrecord  boundsRecord  = tx.GetObject(boundsEntryId, OpenMode.ForRead) as Xrecord;

                    TypedValue[] resBuff = boundsRecord.Data.AsArray();

                    GeoPoint center   = new GeoPoint((resBuff[0].Value as double?).Value, (resBuff[1].Value as double?).Value);
                    GeoPoint neCorner = new GeoPoint((resBuff[2].Value as double?).Value, (resBuff[3].Value as double?).Value);
                    GeoPoint swCorner = new GeoPoint((resBuff[4].Value as double?).Value, (resBuff[5].Value as double?).Value);

                    int zoom         = (resBuff[6].Value as int?).Value;
                    int mapTypeInt   = (resBuff[7].Value as int?).Value;
                    int mapSourceInt = (resBuff[8].Value as int?).Value;

                    MapType          mapType = (MapType)mapTypeInt;
                    AerialRepository repository;

                    if (mapSourceInt == 0)
                    {
                        repository = new BingAerialRepository();
                    }
                    else
                    {
                        repository = new GoogleMapsAerialRepository();
                    }

                    // Get the current filename using the aerial's RasterImageDef
                    ObjectId       aerialImgDefId = aerialEnt.ImageDefId;
                    RasterImageDef aerialImgDef   = tx.GetObject(aerialImgDefId, OpenMode.ForRead) as RasterImageDef;

                    string filename = aerialImgDef.SourceFileName;

                    // Get the image width and height

                    int width  = (int)aerialImgDef.Size.X;
                    int height = (int)aerialImgDef.Size.Y;

                    // Get the request details for the image downlaod
                    AerialImageData imageData = new AerialImageData(center, neCorner,
                                                                    swCorner, width, height, zoom, mapType, filename);
                    string requestUrl = repository.BuildImageRequestUrl(imageData, update: true);

                    // Delete the current entity
                    aerialImgDef.UpgradeOpen();
                    aerialImgDef.Unload(true);

                    // Download the new aerial photo to replace the old
                    AerialRepository.DownloadImage(requestUrl, filename);

                    // Reload the image entity
                    aerialImgDef.Load();

                    // Commit the transaction
                    tx.Commit();
                } catch (Exception ex)
                {
                    ed.WriteMessage("Error updating aerial: " + ex.Message + '\n');
                    ed.WriteMessage("Please try again.\n");
                } finally
                {
                    tx.Dispose();
                }
            }
        }