コード例 #1
0
        public MapLayer set_MapLayer(int layerHandle, bool noSelectedShapes = true, bool refreshLayerList = false)
        {
            _currentMapLayer = MapLayerDictionary[layerHandle];
            if (_currentMapLayer.LayerType == "ShapefileClass")
            {
                _sfLabelHandler     = new ShapefileLabelHandler(_currentMapLayer);
                _sfSymbologyHandler = new PointLayerSymbologyHandler(_currentMapLayer);
                if (noSelectedShapes)
                {
                    ((Shapefile)_currentMapLayer.LayerObject).SelectNone();
                }
            }

            //if there are listeners to the event
            if (CurrentLayer != null)
            {
                //fill up the event argument class with the layer item
                LayerEventArg lp = new LayerEventArg(_currentMapLayer.Handle, _currentMapLayer.Name, _currentMapLayer.Visible, _currentMapLayer.VisibleInLayersUI, _currentMapLayer.LayerType);
                CurrentLayer(this, lp);
            }

            if (refreshLayerList)
            {
                RefreshLayers();
            }
            return(_currentMapLayer);
        }
コード例 #2
0
 /// <summary>
 /// save additional map options including AvoidCollision which is not saved by SaveMapState
 /// </summary>
 private void SaveOtherMapOptions()
 {
     for (int n = 0; n < _axmap.NumLayers; n++)
     {
         var h = _axmap.get_LayerHandle(n);
         if (MapLayerDictionary[h].LayerType == "ShapefileClass")
         {
             var sf = _axmap.get_Shapefile(h);
             if (sf.Labels.Count > 0)
             {
                 ShapefileLabelHandler.SaveLabelParameters(_fileMapState, h, sf.Labels.AvoidCollisions);
             }
         }
     }
 }
コード例 #3
0
        /// <summary>
        /// Load map layers from XML file generated by axmap.SaveMapState.
        ///
        /// Layers are added to the map and is followed by restoring the map extent.
        /// The first added layer automatically sets the map control's projection.
        /// </summary>
        /// <param name="restoreMapState">
        /// When restoreMapState:true, map state is restored
        /// We use restoreMapState:false to load the layers but not restore axMap extent.
        /// </param>
        public void LoadMapState(bool restoreMapState = true)
        {
            _fileMapState = $@"{globalMapping.ApplicationPath}\mapstate";
            if (File.Exists(_fileMapState))
            {
                var doc      = new XmlDocument();
                var proceed  = true;
                var fileName = "";
                try
                {
                    doc.Load(_fileMapState);
                }
                catch (XmlException ex)
                {
                    Logger.Log(ex.Message);
                    proceed = false;
                }
                if (proceed)
                {
                    foreach (XmlNode ly in doc.DocumentElement.SelectNodes("//Layer"))
                    {
                        fileName = ly.Attributes["Filename"].Value;
                        var isVisible = true;
                        isVisible = ly.Attributes["LayerVisible"]?.Value == "1";
                        if (ly.Attributes["LayerType"].Value == "Shapefile")
                        {
                            var sf = new Shapefile();
                            if (sf.Open(fileName))
                            {
                                var h = AddLayer(sf, ly.Attributes["LayerName"].Value, isVisible);
                                _sfSymbologyHandler.SymbolizeLayer(ly.InnerXml);
                                _currentMapLayer.Visible = ly.Attributes["LayerVisible"].Value == "1";
                                _sfLabelHandler          = new ShapefileLabelHandler(_currentMapLayer);

                                if (ly.FirstChild.Name == "ShapefileClass")
                                {
                                    foreach (XmlNode child in ly.FirstChild.ChildNodes)
                                    {
                                        if (child.Name == "LabelsClass" && child.Attributes["Generated"].Value == "1")
                                        {
                                            _currentMapLayer.IsLabeled = child.Attributes["Generated"].Value == "1";
                                            _sfLabelHandler.LabelShapefile(child.OuterXml);
                                        }
                                    }
                                }
                            }
                        }
                        else if (ly.Attributes["LayerType"].Value == "Image")
                        {
                            //code when layertype is image
                            var img = new MapWinGIS.Image();
                            if (img.Open(fileName))
                            {
                                var h = AddLayer(img, ly.Attributes["LayerName"].Value, isVisible);
                            }
                        }
                    }
                    if (restoreMapState)
                    {
                        //We restore saved extent of the map but not the projection. Since layers
                        //were already added to the map, the first layer sets the map's projection.
                        foreach (XmlNode ms in doc.DocumentElement.SelectNodes("//MapState "))
                        {
                            var ext = new Extents();
                            ext.SetBounds(
                                double.Parse(ms.Attributes["ExtentsLeft"].Value),
                                double.Parse(ms.Attributes["ExtentsBottom"].Value),
                                0,
                                double.Parse(ms.Attributes["ExtentsRight"].Value),
                                double.Parse(ms.Attributes["ExtentsTop"].Value),
                                0);
                            _axmap.Extents   = ext;
                            _axmap.ExtentPad = double.Parse(ms.Attributes["ExtentsPad"].Value);
                        }
                    }
                }
            }
            else
            {
                File.Create(_fileMapState);
            }
        }