Example #1
0
        private int Add(AxMap map, object layer, bool Visible)
        {
            if (layer == null)
            {
                return(-1);
            }
            if (map == null)
            {
                throw new System.Exception("MapWinGIS.Map Object not yet set. Set Map Property before adding layers");
            }

            map.LockWindow(MapWinGIS.tkLockMode.lmLock);
            int MapLayerHandle = map.AddLayer(layer, Visible);

            if (MapLayerHandle < 0)
            {
                map.LockWindow(MapWinGIS.tkLockMode.lmUnlock);
                return(MapLayerHandle);
            }

            MapWinGIS.Shapefile sf = (layer as MapWinGIS.Shapefile);

            map.LockWindow(MapWinGIS.tkLockMode.lmUnlock);

            // FireLayerAdded(MapLayerHandle);

            return(MapLayerHandle);
        }
Example #2
0
        /// <summary>
        /// Redraw the LegendControl if not locked - See 'Locked' Property for more details
        /// </summary>
        public void Redraw(LegendRedraw redrawType = LegendRedraw.LegendOnly)
        {
            switch (redrawType)
            {
            case LegendRedraw.LegendOnly:
                RedrawCore();
                break;

            case LegendRedraw.LegendAndMap:
                _map.Redraw();
                RedrawCore();
                break;

            case LegendRedraw.LegendAndMapForce:
                bool locked = _map.IsLocked == tkLockMode.lmLock;
                if (locked)
                {
                    _map.LockWindow(tkLockMode.lmUnlock);
                }

                _map.Redraw();

                if (locked)
                {
                    _map.LockWindow(tkLockMode.lmLock);
                }

                RedrawCore();
                break;
            }
        }
Example #3
0
        // <summary>
        // Adds all the shapefiles and images with .tif and .png extentions from the specified folder to the map
        // </summary>
        public bool AddLayers(AxMap axMap1, string dataPath)
        {
            axMap1.RemoveAllLayers();
            axMap1.LockWindow(tkLockMode.lmLock);

            try
            {
                string[] files = Directory.GetFiles(dataPath);
                foreach (string file in files)
                {
                    int layerHandle = -1;
                    if (file.ToLower().EndsWith(".shp"))
                    {
                        Shapefile sf = new Shapefile();
                        if (sf.Open(file, null))
                        {
                            layerHandle = axMap1.AddLayer(sf, true);
                        }
                        else
                        {
                            MessageBox.Show(sf.ErrorMsg[sf.LastErrorCode]);
                        }
                    }
                    else if (file.ToLower().EndsWith(".tif") ||
                             file.ToLower().EndsWith(".png"))
                    {
                        Image img = new Image();
                        if (img.Open(file, ImageType.TIFF_FILE, false, null))
                        {
                            layerHandle = axMap1.AddLayer(img, true);
                        }
                        else
                        {
                            MessageBox.Show(img.ErrorMsg[img.LastErrorCode]);
                        }
                    }

                    if (layerHandle != -1)
                    {
                        axMap1.set_LayerName(layerHandle, Path.GetFileName(file));
                    }
                }
            }
            finally
            {
                axMap1.LockWindow(tkLockMode.lmUnlock);
                Debug.Print("Layers added to the map: " + axMap1.NumLayers);
            }
            return(axMap1.NumLayers > 0);
        }
Example #4
0
        public int AddLayer(AxMap map, string[] LayerRoute, string mapName)
        {
            int layerHandle = 1;

            map.LockWindow(tkLockMode.lmLock);

            string layerName = "";

            try
            {
                var fm = new FileManager();
                foreach (var name in LayerRoute)
                {
                    layerName = name;
                    string str_filename = layerName.Substring(layerName.LastIndexOf("\\") +
                                                              1, layerName.LastIndexOf(".") - (layerName.LastIndexOf("\\") + 1)); //文件名称
                    var layer = fm.Open(name);
                    if (layer == null)
                    {
                        string msg = string.Format("Failed to open datasource: {0} \n {1}", name, fm.ErrorMsg[fm.LastErrorCode]);
                        MessageHelper.Warn(msg);
                    }
                    else
                    {
                        if (str_filename == mapName)
                        {
                            layerHandle = Add(map, layer, true);
                        }
                        else
                        {
                            Add(map, layer, true);
                        }
                    }
                }
            }
            catch
            {
                MessageHelper.Warn("There was a problem opening layer: " + layerName);
            }
            finally
            {
                map.LockWindow(tkLockMode.lmUnlock);
            }
            return(layerHandle);
        }
 public void LockMap()
 {
     _mapcontrol.LockWindow(tkLockMode.lmLock);
 }
Example #6
0
        // <summary>
        // Creates a drawing layer from the specified shapefile.
        // </summary>
        public void ShapefileToDrawingLayer(AxMap axMap1, string dataPath)
        {
            axMap1.Projection             = tkMapProjection.PROJECTION_NONE;
            axMap1.GrabProjectionFromData = true;

            string[] filenames = new [] { "buildings.shp", "roads.shp", "points.shp" };
            for (int i = 0; i < filenames.Length; i++)
            {
                filenames[i] = dataPath + filenames[i];
            }
            Extents extents = null;

            var center = (axMap1.Extents as Extents).Center;

            try
            {
                for (int n = 0; n < filenames.Length; n++)
                {
                    Shapefile sf = new Shapefile();
                    if (sf.Open(filenames[n], null))
                    {
                        if (axMap1.Projection == tkMapProjection.PROJECTION_NONE)
                        {
                            axMap1.GeoProjection = sf.GeoProjection.Clone();
                        }

                        if (extents == null)
                        {
                            extents = sf.Extents;   // the extents of the fist shapefile will be used to setup display
                        }
                        int drawHandle = axMap1.NewDrawing(tkDrawReferenceList.dlSpatiallyReferencedList);
                        for (int i = 0; i < sf.NumShapes; i++)
                        {
                            Shape shp = sf.Shape[i];

                            if (shp.ShapeType == ShpfileType.SHP_POINT)
                            {
                                double x = 0.0;
                                double y = 0.0;
                                shp.get_XY(0, ref x, ref y);
                                axMap1.DrawPointEx(drawHandle, x, y, 5, 0);
                            }
                            else
                            {
                                for (int p = 0; p < shp.NumParts; p++)
                                {
                                    int initIndex = shp.Part[p];
                                    int numPoints = shp.EndOfPart[p] - shp.Part[p] + 1;
                                    if (numPoints > 0)
                                    {
                                        double[] x = new double[numPoints];
                                        double[] y = new double[numPoints];

                                        for (int j = 0; j < numPoints; j++)
                                        {
                                            shp.get_XY(j + initIndex, ref x[j], ref y[j]);
                                        }

                                        object xObj     = x;
                                        object yObj     = y;
                                        bool   drawFill = shp.ShapeType == ShpfileType.SHP_POLYGON;
                                        uint   color    = sf.ShapefileType == ShpfileType.SHP_POLYGON ? sf.DefaultDrawingOptions.FillColor :
                                                          sf.DefaultDrawingOptions.LineColor;
                                        axMap1.DrawPolygonEx(drawHandle, ref xObj, ref yObj, numPoints, color, drawFill);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            finally
            {
                if (extents != null)
                {
                    axMap1.Extents = extents;
                }
                axMap1.LockWindow(tkLockMode.lmUnlock);
                axMap1.Redraw();
            }
        }