예제 #1
0
        private void AddRasterLayers(IEnumerable <string> fileNames)
        {
            foreach (string fileName in fileNames)
            {
                try
                {
                    string layerName = new FileInfo(fileName).Name;

                    if (!((LayerOverlay)winformsMap1.Overlays[0]).Layers.Contains(layerName))
                    {
                        RasterLayer rasterLayer = null;
                        switch (Path.GetExtension(fileName).ToUpperInvariant())
                        {
                        case ".SID":
                            rasterLayer = new MrSidRasterLayer(fileName);
                            break;

                        case ".ECW":
                            rasterLayer = new EcwRasterLayer(fileName);
                            break;

                        case ".JP2":
                            rasterLayer = new Jpeg2000RasterLayer(fileName);
                            break;

                        case ".BMP":
                        case ".JPG":
                        case ".JPEG":
                        case ".GIF":
                        case ".TIFF":
                        case ".TIF":
                            rasterLayer = new GdiPlusRasterLayer(fileName);
                            break;

                        default:
                            break;
                        }

                        if (rasterLayer != null && ExplorerHelper.ValidateRasterLayer(rasterLayer))
                        {
                            rasterLayer.Name = layerName;
                            winformsMap1.Overlays[0].Lock.EnterWriteLock();
                            try
                            {
                                ((LayerOverlay)winformsMap1.Overlays[0]).Layers.Add(layerName, rasterLayer);
                            }
                            finally
                            {
                                winformsMap1.Overlays[0].Lock.ExitWriteLock();
                            }
                            SetupThemeItem(rasterLayer);
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, ex.GetType().ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, (MessageBoxOptions)0);
                }
            }
        }
예제 #2
0
        private void MainForm_DragDrop(object sender, DragEventArgs e)
        {
            string[] draggedPaths = (string[])e.Data.GetData(DataFormats.FileDrop);
            if ((draggedPaths != null) && (draggedPaths.Length > 0))
            {
                filesWithoutIndex.Clear();
                addedFiles.Clear();

                foreach (string draggedPath in draggedPaths)
                {
                    if (draggedPath.EndsWith(".shp", StringComparison.OrdinalIgnoreCase) && File.Exists(draggedPath))
                    {
                        AddShapeFileFeatureLayers(new string[] { draggedPath });
                    }
                    else if (ExplorerHelper.IsRasterLayerFile(draggedPath) && File.Exists(draggedPath))
                    {
                        AddRasterLayers(new string[] { draggedPath });
                    }
                    else if (Directory.Exists(draggedPath))
                    {
                        AddLayersByFolder(draggedPath);
                    }
                }

                if (filesWithoutIndex.Count > 0)
                {
                    CancelAddingLayer();
                }

                SetCurrentExtent();

                themeView.SetupItems();
                DrawImage();
            }
        }
예제 #3
0
        private void EditLayerStyle(FeatureLayer layer)
        {
            if (layer != null)
            {
                FormStyleEditor frmStyleEditor = new FormStyleEditor();

                frmStyleEditor.CurrentStyleType = themeView.Items[selectedOrder].StyleType;
                frmStyleEditor.ColumnNames      = ExplorerHelper.GetColumnNames(layer);

                frmStyleEditor.BaseLayer = layer;

                // store layer status and will recover it after serialize/deserialize
                bool isOpened = layer.IsOpen;
                // close layer to avoid serialize exception
                layer.Close();

                //  clone layer
                Layer clonedLayer = layer.CloneDeep();

                DialogResult isStyleChanged;
                winformsMap1.Overlays[0].Lock.EnterWriteLock();
                try
                {
                    isStyleChanged = frmStyleEditor.ShowDialog();
                }
                finally
                {
                    winformsMap1.Overlays[0].Lock.ExitWriteLock();
                }
                if (isStyleChanged == DialogResult.OK)
                {
                    themeView.Items[selectedOrder].StyleType = frmStyleEditor.CurrentStyleType;
                    winformsMap1.Refresh();
                }
                else
                {
                    // because user cancel modify style, so restore layer
                    ((LayerOverlay)winformsMap1.Overlays[0]).Layers[selectedOrder] = clonedLayer;
                }

                // recover layer status
                if (isOpened)
                {
                    layer.Open();
                }
            }
        }
예제 #4
0
        private void AddShapeFileFeatureLayers(IEnumerable <string> fileNames)
        {
            foreach (string fileName in fileNames)
            {
                try
                {
                    string layerName = new FileInfo(fileName).Name;
                    if (!((LayerOverlay)winformsMap1.Overlays[0]).Layers.Contains(layerName))
                    {
                        ShapeFileFeatureLayer layer = new ShapeFileFeatureLayer(fileName);
                        layer.Name = layerName;
                        ExplorerHelper.SetStyleByWellKnownType(layer);
                        layer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
                        winformsMap1.Overlays[0].Lock.EnterWriteLock();
                        try
                        {
                            ((LayerOverlay)winformsMap1.Overlays[0]).Layers.Add(layerName, layer);
                        }
                        finally
                        {
                            winformsMap1.Overlays[0].Lock.ExitWriteLock();
                        }

                        SetupThemeItem(layer);

                        if ((!File.Exists(layer.IndexPathFileName)) || (!File.Exists(layer.IndexPathFileName.ToUpper().Replace(".IDX", ".IDS"))))
                        {
                            filesWithoutIndex.Add(fileName);
                        }
                        addedFiles.Add(fileName);
                    }
                }
                catch (FileLoadException fle)
                {
                    RemoveShapefile((FileNotFoundException)fle.InnerException);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, ex.GetType().ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, (MessageBoxOptions)0);
                }
            }
        }
예제 #5
0
        private void AddLayersByFolder(string folderName)
        {
            string[] fileNames = Directory.GetFiles(folderName, "*.*", SearchOption.AllDirectories);

            Collection <string> rasterFilenames  = new Collection <string>();
            Collection <string> featureFilenames = new Collection <string>();

            foreach (string filename in fileNames)
            {
                if (ExplorerHelper.IsRasterLayerFile(filename))
                {
                    rasterFilenames.Add(filename);
                }
                else if (filename.ToUpperInvariant().Contains(".SHP"))
                {
                    featureFilenames.Add(filename);
                }
            }

            AddShapeFileFeatureLayers(featureFilenames);
            AddRasterLayers(rasterFilenames);
        }
예제 #6
0
        // use OpenFileDialog
        private void AddLayersByOpenFileDialog()
        {
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                filesWithoutIndex.Clear();
                addedFiles.Clear();

                Collection <string> rasterFilenames  = new Collection <string>();
                Collection <string> featureFilenames = new Collection <string>();

                foreach (string filename in openFileDialog.FileNames)
                {
                    if (ExplorerHelper.IsRasterLayerFile(filename))
                    {
                        rasterFilenames.Add(filename);
                    }
                    else
                    {
                        featureFilenames.Add(filename);
                    }
                }

                AddShapeFileFeatureLayers(featureFilenames);
                AddRasterLayers(rasterFilenames);

                if (filesWithoutIndex.Count > 0)
                {
                    CancelAddingLayer();
                }

                SetCurrentExtent();

                themeView.SetupItems();

                DrawImage();
            }
        }