/// <summary>
        /// processes selection made using a mouse drag selection box
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnMapSelectBoxFinal(object sender, _DMapEvents_SelectBoxFinalEvent e)
        {
            if (EnableMapInteraction && _axMap.CursorMode == tkCursorMode.cmSelection)
            {
                var     extL = 0D;
                var     extR = 0D;
                var     extT = 0D;
                var     extB = 0D;
                Extents selectionBoxExtent = new Extents();

                _axMap.PixelToProj(e.left, e.top, ref extL, ref extT);
                _axMap.PixelToProj(e.right, e.bottom, ref extR, ref extB);
                selectionBoxExtent.SetBounds(extL, extB, 0, extR, extT, 0);
                Select(selectionBoxExtent, selectionFromSelectBox: true);
                SelectionExtent = selectionBoxExtent;
                var lyArg = new LayerEventArg(selectionExtent: SelectionExtent);
                ExtentCreated?.Invoke(this, lyArg);
            }
        }
Exemple #2
0
        /// <summary>
        /// gets the layer in the map and retrieves the corresponding layer item in the dictionary. Fires an event after a layer item is read
        /// </summary>
        public void ReadLayers()
        {
            for (int n = 0; n < _axmap.NumLayers; n++)
            {
                var h = _axmap.get_LayerHandle(n);
                if (MapLayerDictionary.ContainsKey(h) && MapLayerDictionary[h].VisibleInLayersUI)
                {
                    //if there is a listener to the event
                    if (LayerRead != null)
                    {
                        //get the corresponding layer item in the dictionary
                        var item = MapLayerDictionary[h];

                        //fill up the event argument class with the layer item
                        LayerEventArg lp = new LayerEventArg(item.Handle, item.Name, item.Visible, item.VisibleInLayersUI, item.LayerType);
                        LayerRead(this, lp);
                    }
                }
            }
        }
Exemple #3
0
        private void MaplayersHandler_LayerRemoved(MapLayersHandler s, LayerEventArg e)
        {
            int index = 0;

            while (index < MapLayerCollection.Count)
            {
                if (MapLayerCollection[index].Handle == e.LayerHandle)
                {
                    MapLayerCollection.RemoveAt(index);

                    if (LayerRemoved != null)
                    {
                        LayerEventArg lp = new LayerEventArg(e.LayerHandle, layerRemoved: true);
                        LayerRemoved(this, lp);
                    }
                    break;
                }
                index++;
            }
        }
Exemple #4
0
        /// <summary>
        /// handles editing of layer name and layer visibility
        /// </summary>
        /// <param name="layerHandle"></param>
        /// <param name="layerName"></param>
        /// <param name="visible"></param>
        /// <param name="isShown"></param>
        public void EditLayer(int layerHandle, string layerName, bool visible, bool isShown = true)
        {
            if (MapLayerDictionary.ContainsKey(layerHandle))
            {
                var ly = MapLayerDictionary[layerHandle];
                ly.Name              = layerName;
                ly.Visible           = visible;
                ly.VisibleInLayersUI = isShown;
            }

            _axmap.set_LayerName(layerHandle, layerName);
            _axmap.set_LayerVisible(layerHandle, visible);
            if (OnLayerVisibilityChanged != null)
            {
                LayerEventArg lp = new LayerEventArg(layerHandle);
                lp.LayerVisible = visible;
                lp.LayerName    = layerName;
                OnLayerVisibilityChanged(this, lp);
            }
            _axmap.Redraw();
        }
 private void OnMapSelectionChanged(object sender, _DMapEvents_SelectionChangedEvent e)
 {
     if (ShapesSelected != null)
     {
         var sf = MapControl.get_GetObject(e.layerHandle) as Shapefile;
         _selectedShapeIndexes = new int[sf.NumSelected];
         int y = 0;
         for (int x = 0; x < sf.NumShapes; x++)
         {
             if (sf.ShapeSelected[x])
             {
                 _selectedShapeIndexes[y] = x;
                 y++;
             }
         }
         if (ShapesSelected != null)
         {
             var lyArg = new LayerEventArg(_currentMapLayer.Handle, _selectedShapeIndexes);
             ShapesSelected(this, lyArg);
         }
     }
 }
Exemple #6
0
        public bool RemoveLayerByKey(string layerKey)
        {
            if (LayerDictionary.Count > 0)
            {
                List <int> layerHandles = new List <int>();
                int        counter      = 0;
                foreach (var item in LayerDictionary.Values)
                {
                    if (item.LayerKey == layerKey)
                    {
                        layerHandles.Add(item.Handle);
                    }
                }

                foreach (var h in layerHandles)
                {
                    MapLayerDictionary[h].Dispose();
                    MapLayerDictionary.Remove(h);
                    _axmap.RemoveLayer(h);


                    if (LayerRemoved != null)
                    {
                        LayerEventArg lp = new LayerEventArg(h, layerRemoved: true);
                        LayerRemoved(this, lp);
                    }
                    counter++;
                }


                if (counter > 0)
                {
                    _axmap.Redraw();
                }
                return(counter > 0);
            }
            return(false);
        }
Exemple #7
0
        /// <summary>
        /// handles an image added to the map using file open dialog
        /// </summary>
        /// <param name="image"></param>
        /// <returns></returns>
        public int AddLayer(MapWinGIS.Image image, string layerName = "", bool isVisible = true, string layerKey = "")
        {
            var h = _axmap.AddLayer(image, isVisible);

            if (h >= 0)
            {
                if (layerName.Length == 0)
                {
                    layerName = Path.GetFileName(image.Filename);
                }

                _axmap.set_LayerName(h, layerName);
                _currentMapLayer          = SetMapLayer(h, layerName, isVisible, true, image.GeoProjection, "ImageClass", image.Filename);
                _currentMapLayer.LayerKey = layerKey;

                if (LayerRead != null)
                {
                    LayerEventArg lp = new LayerEventArg(h, layerName, true, true, _currentMapLayer.LayerType);
                    LayerRead(this, lp);
                }
            }
            return(h);
        }
Exemple #8
0
        public void VisibilityExpression(string expression, VisibilityExpressionTarget expressiontarget)
        {
            var sf = (Shapefile)_currentMapLayer.LayerObject;

            if (expressiontarget == VisibilityExpressionTarget.ExpressionTargetLabel)
            {
                _currentMapLayer.LabelsVisibilityExpression = expression;
                sf.Labels.VisibilityExpression = expression;
            }
            else
            {
                _currentMapLayer.ShapesVisibilityExpression = expression;
                sf.VisibilityExpression = expression;
            }
            MapControl.Redraw();
            if (OnVisibilityExpressionSet != null)
            {
                //fill up the event argument class with the layer item
                LayerEventArg lp = new LayerEventArg(_currentMapLayer.Handle, expressiontarget, expression);
                lp.Shapefile = sf;
                OnVisibilityExpressionSet(this, lp);
            }
        }
        /// <summary>
        /// Receives the extent made by selection box or a click select to select shapes in a shapefile using intersection.
        /// Afterwards, a Selection event is raised
        /// </summary>
        /// <param name="selectExtents"></param>
        /// <param name="selectionFromSelectBox"></param>
        private void Select(Extents selectExtents, bool selectionFromSelectBox = false)
        {
            if (_currentMapLayer != null)
            {
                _selectedShapeIndexes   = null;
                _selectionFromSelectBox = selectionFromSelectBox;
                if (_currentMapLayer.LayerType == "ShapefileClass")
                {
                    var sf = _axMap.get_Shapefile(_currentMapLayer.Handle);
                    if (sf != null)
                    {
                        _currentMapLayer.SelectedIndexes = null;
                        sf.SelectNone();
                        sf.SelectionAppearance = tkSelectionAppearance.saDrawingOptions;

                        switch (sf.ShapefileType)
                        {
                        case ShpfileType.SHP_POINT:
                            if (sf.Categories.Count > 0)
                            {
                                sf.SelectionAppearance = tkSelectionAppearance.saSelectionColor;
                            }
                            else
                            {
                                sf.SelectionAppearance = tkSelectionAppearance.saDrawingOptions;
                                sf.SelectionDrawingOptions.PointSize     = sf.DefaultDrawingOptions.PointSize;
                                sf.SelectionDrawingOptions.PointRotation = sf.DefaultDrawingOptions.PointRotation;
                                sf.SelectionDrawingOptions.PointShape    = sf.DefaultDrawingOptions.PointShape;
                            }
                            break;

                        case ShpfileType.SHP_POLYGON:
                            break;

                        case ShpfileType.SHP_POLYLINE:

                            break;
                        }

                        var objSelection = new object();
                        if (sf.SelectShapes(selectExtents, 0, SelectMode.INTERSECTION, ref objSelection))
                        {
                            _selectedShapeIndexes            = (int[])objSelection;
                            _currentMapLayer.SelectedIndexes = _selectedShapeIndexes;
                            for (int n = 0; n < _selectedShapeIndexes.Length; n++)
                            {
                                sf.ShapeSelected[_selectedShapeIndexes[n]] = true;
                            }
                            if (ShapesSelected != null)
                            {
                                var lyArg = new LayerEventArg(_currentMapLayer.Handle, _selectedShapeIndexes);
                                ShapesSelected(this, lyArg);
                            }
                        }
                        else
                        {
                            SelectionCleared?.Invoke(this, EventArgs.Empty);
                        }
                        _axMap.Redraw();
                        Selection?.Invoke(this, EventArgs.Empty);
                    }
                }
                else if (_currentMapLayer.LayerType == "ImageClass")
                {
                }
            }
        }
Exemple #10
0
 private static void _mapInterActionHandler_ShapesSelected(MapInterActionHandler s, LayerEventArg e)
 {
 }
Exemple #11
0
        /// <summary>
        /// handles a shapefile added to the map using file open dialog
        /// </summary>
        /// <param name="sf"></param>
        /// <returns></returns>
        public int AddLayer(Shapefile sf, string layerName = "", bool isVisible = true, bool uniqueLayer = false,
                            fad3MappingMode mappingMode    = fad3MappingMode.defaultMode, string layerKey = "", bool rejectIfExisting = false)
        {
            if (rejectIfExisting && layerName.Length > 0 && Exists(layerName))
            {
                var handle = get_MapLayer(layerName).Handle;
                MapLayerDictionary[handle].LayerObject = sf;
                return(handle);
            }
            if (uniqueLayer)
            {
                RemoveLayer(layerName);
            }
            var h = _axmap.AddLayer(sf, isVisible);

            if (h >= 0)
            {
                if (layerName.Length == 0)
                {
                    layerName = Path.GetFileName(sf.Filename);
                }
                _axmap.set_LayerName(h, layerName);
                _axmap.set_LayerKey(h, layerKey);
                _currentMapLayer             = SetMapLayer(h, layerName, isVisible, true, sf.GeoProjection, "ShapefileClass", sf.Filename);
                _currentMapLayer.LayerKey    = layerKey;
                _currentMapLayer.MappingMode = mappingMode;


                if (LayerRead != null)
                {
                    LayerEventArg lp = new LayerEventArg(h, layerName, true, true, _currentMapLayer.LayerType);
                    LayerRead(this, lp);
                }
                //LineWidthFix.FixLineWidth(sf);
            }
            else
            {
                int reprojectedCount = 0;

                //if(sf.ReprojectInPlace(_axmap.GeoProjection,ref reprojectedCount))
                var sfr = sf.Reproject(_axmap.GeoProjection, reprojectedCount);
                if (reprojectedCount > 0)
                {
                    h = _axmap.AddLayer(sfr, isVisible);
                    if (h > 0)
                    {
                        if (layerName.Length == 0)
                        {
                            layerName = Path.GetFileName(sf.Filename);
                        }
                        _axmap.set_LayerName(h, layerName);
                        _currentMapLayer             = SetMapLayer(h, layerName, isVisible, true, sf.GeoProjection, "ShapefileClass", sf.Filename);
                        _currentMapLayer.LayerKey    = layerKey;
                        _currentMapLayer.MappingMode = mappingMode;

                        if (LayerRead != null)
                        {
                            LayerEventArg lp = new LayerEventArg(h, layerName, true, true, _currentMapLayer.LayerType);
                            LayerRead(this, lp);
                        }
                        //LineWidthFix.FixLineWidth(sf);
                    }
                }
            }
            return(h);
        }