示例#1
0
        public void 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();
            }
        }
示例#2
0
        private void TestExpression(string expression)
        {
            var result = ShapefileLabelHandler.TestExpression(expression, (Shapefile)_mapLayer.LayerObject);

            if (result.isValid)
            {
                lblResult.Text      = "Valid expression";
                lblResult.ForeColor = Color.Green;
            }
            else
            {
                lblResult.Text      = result.message;
                lblResult.ForeColor = Color.Red;
            }
        }
示例#3
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);
             }
         }
     }
 }
示例#4
0
        private void ApplyLabelProperties()
        {
            if (!chkLayerIsLabeled.Checked)
            {
                _shapeFile.Labels.Clear();
            }
            else
            {
                if (!chkLabelsVisible.Checked)
                {
                    _shapeFile.Labels.Visible = false;
                }
                else
                {
                    _shapeFile.Labels.Visible          = true;
                    _shapeFile.Labels.Expression       = txtLabelSourceField.Text;
                    _shapeFile.Labels.RemoveDuplicates = chkRemoveDuplicates.Checked;
                    _shapeFile.Labels.AvoidCollisions  = chkAvoidCollision.Checked;
                    _shapeFile.Labels.CollisionBuffer  = int.Parse(txtCollisionBuffer.Text);
                    _shapeFile.Labels.AutoOffset       = chkAutoOffset.Checked;
                    _shapeFile.Labels.OffsetX          = double.Parse(txtFontOffsetX.Text);
                    _shapeFile.Labels.OffsetY          = double.Parse(txtFontOffsetY.Text);
                    _shapeFile.Labels.VerticalPosition = ((KeyValuePair <tkVerticalPosition, string>)comboVerticalPosition.SelectedItem).Key;

                    _shapeFile.Labels.FontName           = _fontComboBox.Text;
                    _shapeFile.Labels.FontTransparency   = int.Parse(txtFrameTransparency.Text);
                    _shapeFile.Labels.FontSize           = int.Parse(txtFontSize.Text);
                    _shapeFile.Labels.FontBold           = chkBold.Checked;
                    _shapeFile.Labels.FontItalic         = chkItalic.Checked;
                    _shapeFile.Labels.FontUnderline      = chkUnderline.Checked;
                    _shapeFile.Labels.FontOutlineVisible = chkOutlineVisible.Checked;
                    _shapeFile.Labels.FontOutlineColor   = FADColors.ColorToUInteger(rectOutlineColor.FillColor);
                    _shapeFile.Labels.FontColor          = FADColors.ColorToUInteger(rectFontColor.FillColor);

                    if (optionTL.Checked)
                    {
                        _shapeFile.Labels.Alignment = tkLabelAlignment.laTopLeft;
                    }
                    else if (optionTC.Checked)
                    {
                        _shapeFile.Labels.Alignment = tkLabelAlignment.laTopCenter;
                    }
                    else if (optionTR.Checked)
                    {
                        _shapeFile.Labels.Alignment = tkLabelAlignment.laTopRight;
                    }
                    else if (optionCL.Checked)
                    {
                        _shapeFile.Labels.Alignment = tkLabelAlignment.laCenterLeft;
                    }
                    else if (optionCC.Checked)
                    {
                        _shapeFile.Labels.Alignment = tkLabelAlignment.laCenter;
                    }
                    else if (optionCR.Checked)
                    {
                        _shapeFile.Labels.Alignment = tkLabelAlignment.laCenterRight;
                    }
                    else if (optionBL.Checked)
                    {
                        _shapeFile.Labels.Alignment = tkLabelAlignment.laBottomLeft;
                    }
                    else if (optionBC.Checked)
                    {
                        _shapeFile.Labels.Alignment = tkLabelAlignment.laBottomCenter;
                    }
                    else if (optionBR.Checked)
                    {
                        _shapeFile.Labels.Alignment = tkLabelAlignment.laBottomRight;
                    }

                    _shapeFile.Labels.FrameVisible      = chkFrameVisible.Checked;
                    _shapeFile.Labels.FrameTransparency = int.Parse(txtFrameTransparency.Text);
                    _shapeFile.Labels.FrameOutlineWidth = int.Parse(txtFrameLineWidth.Text);
                    _shapeFile.Labels.FrameType         = ((KeyValuePair <tkLabelFrameType, string>)comboFrameType.SelectedItem).Key;
                    _shapeFile.Labels.FrameBackColor    = FADColors.ColorToUInteger(rectFrameFillColor.FillColor);
                    _shapeFile.Labels.FrameOutlineColor = FADColors.ColorToUInteger(rectFrameLineColor.FillColor);
                    _shapeFile.Labels.FramePaddingX     = int.Parse(txtFramePaddingX.Text);
                    _shapeFile.Labels.FramePaddingY     = int.Parse(txtFramePaddingY.Text);

                    if (optionFrameTL.Checked)
                    {
                        _shapeFile.Labels.InboxAlignment = tkLabelAlignment.laTopLeft;
                    }
                    else if (optionFrameTC.Checked)
                    {
                        _shapeFile.Labels.InboxAlignment = tkLabelAlignment.laTopCenter;
                    }
                    else if (optionFrameTR.Checked)
                    {
                        _shapeFile.Labels.InboxAlignment = tkLabelAlignment.laTopRight;
                    }
                    else if (optionFrameCL.Checked)
                    {
                        _shapeFile.Labels.InboxAlignment = tkLabelAlignment.laCenterLeft;
                    }
                    else if (optionFrameCC.Checked)
                    {
                        _shapeFile.Labels.InboxAlignment = tkLabelAlignment.laCenter;
                    }
                    else if (optionFrameCR.Checked)
                    {
                        _shapeFile.Labels.InboxAlignment = tkLabelAlignment.laCenterRight;
                    }
                    else if (optionFrameBL.Checked)
                    {
                        _shapeFile.Labels.InboxAlignment = tkLabelAlignment.laBottomLeft;
                    }
                    else if (optionFrameBC.Checked)
                    {
                        _shapeFile.Labels.InboxAlignment = tkLabelAlignment.laBottomCenter;
                    }
                    else if (optionFrameBR.Checked)
                    {
                        _shapeFile.Labels.InboxAlignment = tkLabelAlignment.laBottomRight;
                    }

                    _shapeFile.Labels.HaloVisible = chkHaloVisible.Checked;
                    _shapeFile.Labels.HaloSize    = int.Parse(txtHaloSize.Text);
                    _shapeFile.Labels.HaloColor   = FADColors.ColorToUInteger(rectHaloColor.FillColor);

                    _shapeFile.Labels.ShadowVisible = chkShadowVisible.Checked;
                    _shapeFile.Labels.ShadowColor   = FADColors.ColorToUInteger(rectShadowColor.FillColor);
                    _shapeFile.Labels.ShadowOffsetX = int.Parse(txtShadowOffsetX.Text);
                    _shapeFile.Labels.ShadowOffsetY = int.Parse(txtShadowOffsetY.Text);

                    if (_mapLayer.LabelsVisibilityExpression?.Length > 0)
                    {
                        _shapeFile.Labels.VisibilityExpression = _mapLayer.LabelsVisibilityExpression;
                    }

                    if (_shapeFile.Labels.Count == 0)
                    {
                        _shapeFile.Labels.Generate(_shapeFile.Labels.Expression, tkLabelPositioning.lpCenter, true);
                    }
                    else
                    {
                        if (_shapeFile.Labels.Expression != txtLabelSourceField.Text)
                        {
                            _shapeFile.Labels.Expression = ShapefileLabelHandler.FixExpression(txtLabelSourceField.Text);
                        }
                    }
                }
            }
            global.MappingForm.MapControl.Redraw();
        }
示例#5
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 = $@"{global.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, "MapLayersHandler", "LoadMapState");
                    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);
            }
        }