Example #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);
                }
            }
        }
Example #2
0
        protected override RasterLayer GetRasterLayer(Uri uri, WorldFileInfo wInfo)
        {
            RasterLayer layer = null;

            if (File.Exists(wInfo.WorldFilePath))
            {
                layer = new Jpeg2000RasterLayer(Path.GetFullPath(uri.LocalPath), wInfo.WorldFilePath);
            }
            else if (wInfo.ImageExtent != null)
            {
                layer = new Jpeg2000RasterLayer(Path.GetFullPath(uri.LocalPath), wInfo.ImageExtent);
            }
            return(layer);
        }
        private void MainForm_Load(object sender, EventArgs e)
        {
            winformsMap1.MapUnit = GeographyUnit.Meter;

            LayerOverlay overlay = new LayerOverlay();


            //To resolve issue that we cannot run the executable by double click it on linux, we need to find out the absolute path by reflection.
            string baseDirectory         = System.AppDomain.CurrentDomain.BaseDirectory;
            string jpeg2000LayerFileName = Path.GetFullPath(Path.Combine(baseDirectory, "../../App_Data/World.jp2"));

            Jpeg2000RasterLayer jpeg2000RasterLayer = new Jpeg2000RasterLayer(jpeg2000LayerFileName);

            overlay.Layers.Add(jpeg2000RasterLayer);

            winformsMap1.Overlays.Add(overlay);

            jpeg2000RasterLayer.Open();
            winformsMap1.CurrentExtent = jpeg2000RasterLayer.GetBoundingBox();

            winformsMap1.Refresh();
        }
        protected override RasterLayer GetRasterLayer(Uri uri)
        {
            RasterLayer layer = new Jpeg2000RasterLayer(Path.GetFullPath(uri.LocalPath));

            return(layer);
        }