Exemplo n.º 1
0
        private void MarkAllVertices(double curX, double curY)
        {
            try
            {
                int handle;

                if (m_globals.CurrentLayer == null)
                {
                    return;
                }
                handle = m_MapWin.Layers.CurrentLayer;
                MapWinGIS.Shapefile shpFile = m_globals.CurrentLayer;
                int numShp = shpFile.NumShapes;
                int shpIndex;

                if (m_prevShape != -1)
                {
                    if (!m_MapWin.Layers[m_MapWin.Layers.CurrentLayer].VerticesVisible)
                    {
                        m_MapWin.Layers[m_MapWin.Layers.CurrentLayer].HideVertices();
                    }
                }

                if (m_MapWin.Layers[m_MapWin.Layers.CurrentLayer].LayerType == MapWindow.Interfaces.eLayerType.PolygonShapefile)
                {
                    shpFile.BeginPointInShapefile();
                    shpIndex = shpFile.PointInShapefile(curX, curY);
                    shpFile.EndPointInShapefile();
                }
                else
                {
                    MapWinGIS.Extents bounds = new MapWinGIS.ExtentsClass();
                    bounds.SetBounds(curX, curY, 0, curX, curY, 0);
                    object resArray = null;
                    if (shpFile.SelectShapes(bounds, m_globals.CurrentTolerance * 2, MapWinGIS.SelectMode.INTERSECTION, ref resArray))
                    {
                        shpIndex = (int)((System.Array)resArray).GetValue(0);
                    }
                    else
                    {
                        shpIndex = -1;
                    }
                }

                if (shpIndex >= 0)
                {
                    m_MapWin.Layers[handle].Shapes[shpIndex].ShowVertices(System.Drawing.Color.Red, m_globals.VertexSize);
                    m_prevShape = shpIndex;
                }
                else
                {
                    m_prevShape = -1;
                }
            }
            catch (System.Exception ex)
            {
                m_MapWin.ShowErrorDialog(ex);
            }
        }
Exemplo n.º 2
0
        private void MapMouseMove(int ScreenX, int ScreenY, ref bool Handled)
        {
            try
            {
                double projX = 0, projY = 0, newX = 0, newY = 0;
                int    insertIndex = -1, shpIndex = -1;
                MapWinGIS.Shapefile shpFile;

                if (m_Globals.CurrentMode == GlobalFunctions.Modes.AddVertex)
                {
                    m_MapWin.View.PixelToProj((double)ScreenX, (double)ScreenY, ref projX, ref projY);
                    if (m_Globals.CurrentLayer == null)
                    {
                        return;
                    }
                    shpFile = m_Globals.CurrentLayer;

                    //clear all previous drawings and create a new drawing suface
                    ClearDrawings();

                    //draw all the vertices that this point is in
                    if (m_Globals.ShowVertices)
                    {
                        MarkAllVertices(projX, projY);
                    }

                    for (int i = 0; i < shpFile.NumShapes; i++)
                    {
                        if (m_MapWin.Layers[m_MapWin.Layers.CurrentLayer].LayerType == MapWindow.Interfaces.eLayerType.PolygonShapefile)
                        {
                            shpFile.BeginPointInShapefile();
                            shpIndex = shpFile.PointInShapefile(projX, projY);
                            shpFile.EndPointInShapefile();
                        }
                        else
                        {
                            MapWinGIS.Extents bounds = new MapWinGIS.ExtentsClass();
                            bounds.SetBounds(projX, projY, 0, projX, projY, 0);
                            object resArray = null;
                            if (shpFile.SelectShapes(bounds, m_Globals.CurrentTolerance, MapWinGIS.SelectMode.INTERSECTION, ref resArray))
                            {
                                shpIndex = (int)((System.Array)resArray).GetValue(0);
                            }
                            else
                            {
                                shpIndex = -1;
                            }
                        }

                        if (shpIndex != -1)
                        {
                            //draw the location of the point if it is within the tolerance
                            if (WithinTolerance(projX, projY, shpIndex, m_Globals.CurrentTolerance, ref newX, ref newY, ref insertIndex))
                            {
                                m_MapWin.View.Draw.DrawPoint(newX, newY, m_Globals.VertexSize, System.Drawing.Color.Blue);
                                break;
                            }
                        }
                    }

                    //handled this event
                    Handled = true;
                }
            }
            catch (System.Exception ex)
            {
                m_MapWin.ShowErrorDialog(ex);
            }
        }