public bool AddSHPLayer()
        {
            string    filename = @"c:\users\suter\documents\test.shp";
            Shapefile sf       = new Shapefile();

            if (sf.Open(filename))
            {
                int m_layerHandle = AxMap.AddLayer(sf, true);
                sf = AxMap.get_Shapefile(m_layerHandle);     // in case a copy of shapefile was created by GlobalSettings.ReprojectLayersOnAdding

                ShpLayer sl = new ShpLayer();
                sl.LayerType = LayerType.CustomLayerSHP;
                sl.Name      = "Gefahrenkarte";
                sl.Shapefile = sf;
                sl.Handle    = m_layerHandle;

                MapControlTools.Layers.Add(sl);
                Events.MapControl_LayerChange layerchange = new Events.MapControl_LayerChange()
                {
                    LayerChangeReason = Events.LayerChangeReason.AddLayer, Layer = sl
                };
                On_LayerChange(layerchange);
                return(true);
            }
            else
            {
                Events.MapControl_Error error = new Events.MapControl_Error()
                {
                    ErrorCode = Events.ErrorCodes.CouldNotLoadLayer, InMethod = "AddShpLayer", AxMapError = sf.ErrorMsg[sf.LastErrorCode]
                };
                On_Error(error);
                return(false);
            }
        }
        /// <summary>
        /// On_LayerChange when a Layer is added, removed oder changed
        /// </summary>
        public virtual void On_LayerChange(Events.MapControl_LayerChange e) //protected virtual method
        {
            var layer = e.Layer;

            if (layer != null)
            {
                if (layer.GetType() == typeof(ResTBDamagePotentialLayer))
                {
                    layer.LayerPosition = AxMap.get_LayerPosition(((ResTBDamagePotentialLayer)layer).PointHandle);
                    layer.IsVisible     = AxMap.get_LayerVisible(((ResTBDamagePotentialLayer)layer).PointHandle);
                }
                else if (layer.GetType() == typeof(ResTBRiskMapLayer))
                {
                    layer.LayerPosition = AxMap.get_LayerPosition(((ResTBRiskMapLayer)layer).PointHandle);
                    layer.IsVisible     = AxMap.get_LayerVisible(((ResTBRiskMapLayer)layer).PointHandle);
                }
                else
                {
                    layer.LayerPosition = AxMap.get_LayerPosition(layer.Handle);
                    layer.IsVisible     = AxMap.get_LayerVisible(layer.Handle);
                }
                layer.ShapeCount = ShapesCount(layer.Name);
            }

            MapControl_LayerChange?.Invoke(this, e);
        }
Пример #3
0
        public classDrawLine(AxMap map)
        {
            sf = new Shapefile();
            sf.CreateNew("", ShpfileType.SHP_POLYLINE);

            this.map = map;
        }
        public bool AddWMSLayer(string baseUrl, string layers, string name, Extents extents, int Epsg, string Format)
        {
            WmsLayer wmsLayer = new WmsLayer();

            wmsLayer.BaseUrl     = baseUrl;
            wmsLayer.BoundingBox = extents;
            wmsLayer.DoCaching   = false;
            wmsLayer.Epsg        = Epsg;
            wmsLayer.Format      = Format;
            wmsLayer.Layers      = layers;
            wmsLayer.Name        = name;
            wmsLayer.UseCache    = false;
            wmsLayer.Id          = 1;
            wmsLayer.Key         = "1";
            wmsLayer.Version     = tkWmsVersion.wv111;

            WmsLayerLayer layer = new WmsLayerLayer();

            layer.WmsLayerObj = wmsLayer;
            layer.Name        = name;
            layer.Handle      = AxMap.AddLayer(wmsLayer, true);
            layer.LayerType   = LayerType.CustomLayerWMS;

            MapControlTools.Layers.Add(layer);
            Events.MapControl_LayerChange layerchange = new Events.MapControl_LayerChange()
            {
                LayerChangeReason = Events.LayerChangeReason.AddLayer, Layer = layer
            };
            On_LayerChange(layerchange);

            return(true);
        }
Пример #5
0
        public void ReStartSelecting()
        {
            UnselectAllLayer();

            foreach (ILayer selectionLayer in CurrentSelectionLayers)
            {
                if (selectionLayer.GetType() == typeof(ResTBDamagePotentialLayer))
                {
                    Shapefile sf = AxMap.get_Shapefile(((ResTBDamagePotentialLayer)selectionLayer).PointHandle);
                    sf.Identifiable = true;
                    sf.Selectable   = true;
                    sf = AxMap.get_Shapefile(((ResTBDamagePotentialLayer)selectionLayer).PointHandle);
                    sf.Identifiable = true;
                    sf.Selectable   = true;
                    sf = AxMap.get_Shapefile(((ResTBDamagePotentialLayer)selectionLayer).PointHandle);
                    sf.Identifiable = true;
                    sf.Selectable   = true;
                }
                else
                {
                    Shapefile sf = AxMap.get_Shapefile(selectionLayer.Handle);
                    sf.Identifiable   = true;
                    sf.Selectable     = true;
                    sf.SelectionColor = utils.ColorByName(tkMapColor.Yellow);
                }
            }
        }
Пример #6
0
        private bool InitMap(AxMap axMap1, string dataPath)
        {
            axMap1.Projection             = tkMapProjection.PROJECTION_GOOGLE_MERCATOR;
            axMap1.GrabProjectionFromData = true;
            axMap1.ZoomBehavior           = tkZoomBehavior.zbUseTileLevels;

            axMap1.DisableWaitCursor = true;

            string filename1 = dataPath + "buildings.shp";
            string filename2 = dataPath + "roads.shp";


            if (!File.Exists(filename1) || !File.Exists(filename2))
            {
                MessageBox.Show("Couldn't find the files (buildings.shp, roads.shp): " + dataPath);
                return(false);
            }

            Shapefile sf = new Shapefile();

            sf.Open(filename1, null);
            axMap1.AddLayer(sf, true);

            Debug.Print(axMap1.GeoProjection.ExportToWKT());

            sf = new Shapefile();
            sf.Open(filename2, null);
            sf.Labels.Generate("[Name]", tkLabelPositioning.lpLongestSegement, false);

            axMap1.ZoomToMaxExtents();
            return(true);
        }
Пример #7
0
        public void DrawNodes(AxMap pMap, Graphics g)
        {
            float num = (float)(this.m_Zoom / pMap.Zoom);

            num = Conversions.ToSingle(Operators.MultiplyObject(num, Interaction.IIf(this.m_MWidth > 0f, pMap.MapScreenWidth / this.m_MWidth, 1)));
            float dx;
            float dy;

            pMap.ConvertCoord(ref dx, ref dy, ref this.m_GocX, ref this.m_GocY, ConversionConstants.miMapToScreen);
            GraphicsContainer container = g.BeginContainer();

            g.TranslateTransform(dx, dy);
            g.ScaleTransform(num, num);
            try
            {
                IEnumerator enumerator = this.m_GObjs.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    GraphicObject graphicObject = (GraphicObject)enumerator.Current;
                    PointF[]      points        = graphicObject.GetPoints();
                    modBdTC.DrawNodes(g, points, 3f);
                }
            }
            finally
            {
                IEnumerator enumerator;
                if (enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
            g.EndContainer(container);
        }
Пример #8
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="table"></param>ais数据库表
 /// <param name="handle"></param>shapefile句柄
 public AISData(AxMap map, DataTable table)
 {
     this.map = map;
     IntoAisData(table);
     IntoPointData();
     drawPoint = new classDrawPoint(map);
 }
 private void OnFormClosing(object sender, FormClosingEventArgs e)
 {
     _instance = null;
     _mapControl.MouseMoveEvent -= OnMapMouseMove;
     _mapControl = null;
     global.SaveFormSettings(this);
 }
Пример #10
0
        public CSymbol(AxMap pMap, PointF pt0, CGraphicObjs pGObjs, double pZoom, float pMWidth)
            : this()
        {
            float x = pt0.X;
            float y = pt0.Y;

            pMap.ConvertCoord(ref x, ref y, ref this.m_GocX, ref this.m_GocY, ConversionConstants.miScreenToMap);
            pt0.Y         = y;
            pt0.X         = x;
            this.m_Zoom   = pZoom;
            this.m_MWidth = pMWidth;
            this.m_GObjs  = new CGraphicObjs();
            try
            {
                IEnumerator enumerator = pGObjs.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    GraphicObject graphicObject = (GraphicObject)enumerator.Current;
                    this.m_GObjs.Add(graphicObject.Clone());
                }
            }
            finally
            {
                IEnumerator enumerator;
                if (enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
            this.m_Description = "";
            this.m_Blinking    = false;
        }
Пример #11
0
        public static void MakeScreenshot(this AxMap map, Form parentForm)
        {
            var ext = map.Extents as MapWinGIS.Extents;

            var img = map.SnapShot3(ext.xMin, ext.xMax, ext.yMax, ext.yMin, map.Width);

            if (img != null)
            {
                using (var dlg = new SaveFileDialog())
                {
                    dlg.Filter = "*.jpg|*.jpg";
                    if (dlg.ShowDialog(parentForm) == DialogResult.OK)
                    {
                        if (!img.Save(dlg.FileName, false, ImageType.JPEG_FILE))
                        {
                            MessageHelper.Warn("Failed to save image: " + img.get_ErrorMsg(img.LastErrorCode));
                        }
                        else
                        {
                            MessageHelper.Warn("Image is saved: " + dlg.FileName);
                        }
                    }
                }
            }
        }
        public bool StopEditingLayer(bool saveEdits = false)
        {
            if (CurrentEditingLayer == null)
            {
                // there is nothing to save...
                return(false);
            }

            saveAndCloseWhenFinish = false;


            AxMap.ShapeEditor.SaveChanges();

            if (saveEdits)
            {
                if (!SaveEdits())
                {
                    //return false;
                }
            }


            var sf       = AxMap.get_Shapefile(CurrentEditingLayer.Handle);
            var ogrLayer = AxMap.get_OgrLayer(CurrentEditingLayer.Handle);

            if (ogrLayer != null)
            {
                ogrLayer.ReloadFromSource();
                // show the editing layer (with all Polygons)
                sf = AxMap.get_Shapefile(((ResTBPostGISLayer)CurrentEditingLayer).EditingLayerHandle);
                AxMap.RemoveLayer(((ResTBPostGISLayer)CurrentEditingLayer).EditingLayerHandle);
                AxMap.set_LayerVisible(CurrentEditingLayer.Handle, true);
            }
            bool returnBool = sf.StopEditingShapes();

            AxMap.ChooseLayer           -= AxMap_ChooseLayer;
            AxMap.AfterShapeEdit        -= _map_AfterShapeEdit;
            AxMap.BeforeDeleteShape     -= _map_BeforeDeleteShape;
            AxMap.BeforeShapeEdit       -= _map_BeforeShapeEdit;
            AxMap.ShapeValidationFailed -= _map_ShapeValidationFailed;
            AxMap.ValidateShape         -= _map_ValidateShape;

            MapControlTools.Redraw(true);
            Events.MapControl_LayerChange layerChange = new Events.MapControl_LayerChange()
            {
                Layer = this.CurrentEditingLayer, LayerChangeReason = Events.LayerChangeReason.EditedLayer
            };
            On_LayerChange(layerChange);
            Events.MapControl_EditingStateChange editingStateChange = new Events.MapControl_EditingStateChange()
            {
                EditingState = Events.EditingState.StopEditing, EditingLayer = CurrentEditingLayer
            };
            On_EditingStateChange(editingStateChange);

            _currentEditingLayer = null;

            AxMap.CursorMode = tkCursorMode.cmPan;

            return(returnBool);
        }
Пример #13
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="mapControl"></param>
        /// <param name="layersHandler"></param>
        public Graticule(AxMap mapControl, MapLayersHandler layersHandler)
        {
            Name                   = "Graticule";
            LabelFontSize          = 8;
            NumberOfGridlines      = 5;
            _axMap                 = mapControl;
            _axMap.ExtentsChanged += OnMapExtentsChanged;
            _axMap.LayerRemoved   += OnLayerRemoved;
            _axMap.LayerAdded     += OnLayerAdded;
            _geoProjection         = _axMap.GeoProjection;
            _mapLayersHandler      = layersHandler;
            _mapLayersHandler.OnLayerVisibilityChanged += OnLayerVisibleChange;
            _mapLayersHandler.MapRedrawNeeded          += OnRedrawNeeded;
            GraticuleTextHelper = new MapTextGraticuleHelper(_geoProjection, this);
            BorderColor         = new Utils().ColorByName(tkMapColor.Black);
            switch (global.CoordinateDisplay)
            {
            case CoordinateDisplayFormat.DegreeDecimal:
                CoordFormat = "D";
                break;

            case CoordinateDisplayFormat.DegreeMinute:
                CoordFormat = "DM";
                break;

            case CoordinateDisplayFormat.DegreeMinuteSecond:
                CoordFormat = "DMS";
                break;

            default:
                throw new Exception("Graticule: Invalid coordinate format");
            }
        }
Пример #14
0
        protected virtual void Dispose(bool disposing)
        {
            if (!_disposed)
            {
                if (disposing)
                {
                }
                _axMap.ExtentsChanged -= OnMapExtentsChanged;
                _axMap.LayerRemoved   -= OnLayerRemoved;
                _axMap.LayerAdded     -= OnLayerAdded;
                _axMap = null;

                if (_sfGraticule != null)
                {
                    _sfGraticule.EditClear();
                }
                _sfGraticule = null;

                _geoProjection    = null;
                _graticuleExtents = null;
                _boundaryExtents  = null;
                _mapExtents       = null;
                _mapLayersHandler.OnLayerVisibilityChanged -= OnLayerVisibleChange;
                _mapLayersHandler.MapRedrawNeeded          -= OnRedrawNeeded;
                _mapLayersHandler.RemoveLayer("Mask");
                _mapLayersHandler.RemoveLayer(Name);
                _mapLayersHandler = null;
            }
        }
Пример #15
0
        public void Scale(AxMap pMap, PointF rootPt, PointF fromPt, PointF toPt)
        {
            float num;
            float num2;

            pMap.ConvertCoord(ref num, ref num2, ref this.m_GocX, ref this.m_GocY, ConversionConstants.miMapToScreen);
            num  -= rootPt.X;
            num2 -= rootPt.Y;
            PointF rootPt2 = default(PointF);

            rootPt2.X = num;
            rootPt2.Y = num2;
            fromPt.X -= rootPt.X;
            fromPt.Y -= rootPt.Y;
            toPt.X   -= rootPt.X;
            toPt.Y   -= rootPt.Y;
            try
            {
                IEnumerator enumerator = this.m_GObjs.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    GraphicObject graphicObject = (GraphicObject)enumerator.Current;
                    graphicObject.Zoom(rootPt2, fromPt, toPt);
                }
            }
            finally
            {
                IEnumerator enumerator;
                if (enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
        }
Пример #16
0
        public CSymbol FindSymbolAtPoint(AxMap pMap, PointF pt)
        {
            bool flag = this.List != null && this.List.Count > 0;

            checked
            {
                CSymbol FindSymbolAtPoint;
                if (flag)
                {
                    int     i = this.List.Count - 1;
                    CSymbol drawSymbol;
                    while (true)
                    {
                        int arg_64_0 = i;
                        int num      = 0;
                        if (arg_64_0 < num)
                        {
                            goto IL_66;
                        }
                        drawSymbol = (CSymbol)this.List[i];
                        flag       = drawSymbol.HitTest(pMap, pt);
                        if (flag)
                        {
                            break;
                        }
                        i += -1;
                    }
                    FindSymbolAtPoint = drawSymbol;
                    return(FindSymbolAtPoint);
                }
IL_66:
                FindSymbolAtPoint = null;
                return(FindSymbolAtPoint);
            }
        }
Пример #17
0
        public void Scale2(AxMap pMap, PointF rootPt, float deltaX, float deltaY)
        {
            float num;
            float num2;

            pMap.ConvertCoord(ref num, ref num2, ref this.m_GocX, ref this.m_GocY, ConversionConstants.miMapToScreen);
            num  -= rootPt.X;
            num2 -= rootPt.Y;
            PointF rootPt2 = default(PointF);

            rootPt2.X = num;
            rootPt2.Y = num2;
            RectangleF bounds  = this.GetBounds(pMap);
            float      deltaX2 = (bounds.Width + deltaX) / bounds.Width;
            float      deltaY2 = (bounds.Height + deltaY) / bounds.Height;

            try
            {
                IEnumerator enumerator = this.m_GObjs.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    GraphicObject graphicObject = (GraphicObject)enumerator.Current;
                    graphicObject.Zoom2(rootPt2, deltaX2, deltaY2);
                }
            }
            finally
            {
                IEnumerator enumerator;
                if (enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
        }
Пример #18
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);
        }
Пример #19
0
        public CSymbol(AxMap pMap, CGraphicObjs pGObjs)
            : this()
        {
            float num  = 0f;
            float num2 = 0f;

            pMap.ConvertCoord(ref num, ref num2, ref this.m_GocX, ref this.m_GocY, ConversionConstants.miScreenToMap);
            this.m_Zoom   = pMap.Zoom;
            this.m_MWidth = pMap.MapScreenWidth;
            this.m_GObjs  = new CGraphicObjs();
            try
            {
                IEnumerator enumerator = pGObjs.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    GraphicObject graphicObject = (GraphicObject)enumerator.Current;
                    this.m_GObjs.Add(graphicObject.Clone());
                }
            }
            finally
            {
                IEnumerator enumerator;
                if (enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
            this.m_Description = "";
            this.m_Blinking    = false;
        }
Пример #20
0
        public void TrackCars(AxMap axMap1, string dataPath)
        {
            if (!InitMap(axMap1, dataPath))
            {
                return;
            }

            string filename = dataPath + "path.shp";

            if (!File.Exists(filename))
            {
                MessageBox.Show("Path.shp wasn't found: " + dataPath);
                return;
            }

            int handle = axMap1.AddLayerFromFilename(filename, tkFileOpenStrategy.fosAutoDetect, false);

            var sf      = axMap1.get_Shapefile(handle);
            var service = new CarService(axMap1.Extents as Extents, sf, 20);

            _carShapefile               = CreateCarShapefile(service);
            _carShapefile.Volatile      = true;
            _carShapefile.CollisionMode = tkCollisionMode.AllowCollisions;
            axMap1.AddLayer(_carShapefile, true);

            axMap1.ZoomToLayer(handle);

            service.StateChanged += ServiceStateChanged;
        }
Пример #21
0
        public static AxMap GetAxMap()
        {
            if (_axMap1 != null)
            {
                return(_axMap1);
            }

            // Create MapWinGIS:
            _axMap1 = new AxMap();
            _axMap1.CreateControl();
            _axMap1.Width  = 200;
            _axMap1.Height = 200;

            // Create form and add MapWinGIS:
            var myForm = new Form();

            myForm.Controls.Add(_axMap1);

            _axMap1.ScalebarVisible   = true;
            _axMap1.ShowCoordinates   = tkCoordinatesDisplay.cdmAuto;
            _axMap1.ShowRedrawTime    = true;
            _axMap1.ShowVersionNumber = true;
            _axMap1.ShowZoomBar       = true;
            _axMap1.CursorMode        = tkCursorMode.cmZoomIn;

            return(_axMap1);
        }
Пример #22
0
        // <summary>
        // Adds the layers and register event handler.
        // </summary>
        public void SelectBox(AxMap axMap1, string dataPath)
        {
            axMap1.Projection = tkMapProjection.PROJECTION_GOOGLE_MERCATOR;

            string filename = dataPath + "landuse.shp";

            if (!File.Exists(filename))
            {
                MessageBox.Show("Couldn't file the file: " + filename);
                return;
            }

            Shapefile sf = new Shapefile();

            sf.Open(filename, null);
            if (!sf.StartEditingShapes(true, null))
            {
                MessageBox.Show("Failed to start edit mode: " + sf.Table.ErrorMsg[sf.LastErrorCode]);
            }
            else
            {
                sf.UseQTree = true;
                sf.Labels.Generate("[Name]", tkLabelPositioning.lpCentroid, false);

                axMap1.AddLayer(sf, true);
                axMap1.SendSelectBoxFinal = true;
                MapEvents.SelectBoxFinal += AxMap1SelectBoxFinal; // change MapEvents to axMap1
                axMap1.MapUnits           = tkUnitsOfMeasure.umMeters;
                axMap1.CurrentScale       = 50000;
                axMap1.CursorMode         = tkCursorMode.cmSelection;
            }
        }
Пример #23
0
        // <summary>
        // Creates a shapefile holding polygons with holes
        // </summary>
        public void PolygonsWithHoles(AxMap axMap1)
        {
            axMap1.Projection = tkMapProjection.PROJECTION_NONE;

            var  sf     = new Shapefile();
            bool result = sf.CreateNewWithShapeID("", ShpfileType.SHP_POLYGON);

            if (!result)
            {
                MessageBox.Show(sf.ErrorMsg[sf.LastErrorCode]);
            }
            else
            {
                double xMin = 0.0;
                double yMin = 0.0;
                double xMax = 1000.0;
                double yMax = 1000.0;
                Random rnd  = new Random(DateTime.Now.Millisecond);

                // builds 10 polygons
                for (int i = 0; i < 40; i++)
                {
                    double xCenter = xMin + (xMax - xMin) * rnd.NextDouble();
                    double yCenter = yMin + (yMax - yMin) * rnd.NextDouble();

                    // random radius from 10 to 100
                    double radius = 10 + rnd.NextDouble() * 90;

                    var shp = new Shape();
                    shp.Create(ShpfileType.SHP_POLYGON);

                    // polygon must have clockwise order of points (first argument - true)
                    this.AddRing(true, xCenter, yCenter, radius, ref shp);

                    // holes must have counter-clockwise order of points (fale for the last argument)
                    this.AddRing(false, xCenter + radius / 2.0, yCenter, radius / 4.0, ref shp);
                    this.AddRing(false, xCenter - radius / 2.0, yCenter, radius / 4.0, ref shp);
                    this.AddRing(false, xCenter, yCenter + radius / 2.0, radius / 4.0, ref shp);
                    this.AddRing(false, xCenter, yCenter - radius / 2.0, radius / 4.0, ref shp);

                    for (int j = 0; j < shp.NumParts; j++)
                    {
                        Debug.Print("Part is clocwise: " + shp.PartIsClockWise[j]);
                    }

                    Debug.Print("Shape is valid: " + shp.IsValid);
                    if (!shp.IsValid)
                    {
                        Debug.Print("Reason: " + shp.IsValidReason);
                    }

                    sf.EditInsertShape(shp, ref i);
                }

                axMap1.AddLayer(sf, true);
                axMap1.ZoomToLayer(0);

                sf.SaveAs(@"c:\polygons.shp", null);
            }
        }
        /// <summary>
        /// Constructor and sets up map control events
        /// </summary>
        /// <param name="mapControl"></param>
        /// <param name="layersHandler"></param>
        public MapInterActionHandler(AxMap mapControl, MapLayersHandler layersHandler)
        {
            _mapLayersHandler = layersHandler;
            _mapLayersHandler.CurrentLayer += OnCurrentMapLayer;
            _axMap = mapControl;
            _axMap.SendMouseDown      = true;
            _axMap.SendMouseMove      = true;
            _axMap.SendSelectBoxFinal = true;
            _axMap.SendMouseUp        = true;
            _axMap.DblClick          += _axMap_DblClick;


            _axMap.ChooseLayer      += _axMap_ChooseLayer;
            _axMap.MouseUpEvent     += OnMapMouseUp;
            _axMap.MouseDownEvent   += OnMapMouseDown;
            _axMap.SelectBoxFinal   += OnMapSelectBoxFinal;
            _axMap.MouseMoveEvent   += OnMapMouseMove;
            _axMap.DblClick         += OnMapDoubleClick;
            _axMap.SelectionChanged += OnMapSelectionChanged;

            EnableMapInteraction = true;

            _axMap.MapCursor  = tkCursor.crsrArrow;
            _axMap.CursorMode = tkCursorMode.cmSelection;
        }
Пример #25
0
        private void OnMapperForm_Load(object sender, EventArgs e)
        {
            MapControl = axMap;
            toolstripToolBar.ClickThrough = true;
            Text = "Map";
            global.LoadFormSettings(this);
            _mapLayersHandler = new MapLayersHandler(axMap);
            _mapLayersHandler.OnLayerVisibilityChanged += OnMapLayerVisibilityChanged;
            _mapLayersHandler.CurrentLayer             += OnCurrentMapLayer;
            _mapLayersHandler.LayerRead += OnMapLayerRead;
            _mapInterActionHandler       = new MapInterActionHandler(axMap, _mapLayersHandler)
            {
                MapContextMenuStrip = menuDropDown
            };

            if (global.MappingMode == fad3MappingMode.defaultMode)
            {
                _mapLayersHandler.LoadMapState();
            }
            else
            {
                tsButtonSave.Enabled = false;
            }
            ConfigureMapControl();
            SetCursor(tkCursorMode.cmSelection);
            EventHandler handler = MapperOpen;

            if (handler != null)
            {
                handler(this, EventArgs.Empty);
            }
            global.MappingForm = this;
            MapLegend          = new MapLegend(MapControl, _mapLayersHandler);
        }
        public bool AddProjectLayer(ResTBPostGISLayer resTBPostGISLayer, bool visible = true)
        {
            if (!MapControlTools.Layers.Where(m => m.Name == resTBPostGISLayer.Name).Any())
            {
                Type t = resTBPostGISLayer.GetType();

                // Handle the damage potential differently
                if (resTBPostGISLayer.GetType() == typeof(ResTBDamagePotentialLayer))
                {
                    return(AddProjectLayer((ResTBDamagePotentialLayer)resTBPostGISLayer, visible));
                }
                if (resTBPostGISLayer.GetType() == typeof(ResTBRiskMapLayer))
                {
                    return(AddProjectLayer((ResTBRiskMapLayer)resTBPostGISLayer, visible));
                }

                var layer = ds.RunQuery(resTBPostGISLayer.SQL);
                if (layer == null)
                {
                    Events.MapControl_Error error = new Events.MapControl_Error()
                    {
                        ErrorCode = Events.ErrorCodes.FailedToRunSQLQuery, InMethod = "AddPostGISLayer", AxMapError = ds.GdalLastErrorMsg
                    };
                    On_Error(error);
                    return(false);
                }
                else
                {
                    int handle = AxMap.AddLayer(layer, visible);

                    if (handle == -1)
                    {
                        Events.MapControl_Error error = new Events.MapControl_Error()
                        {
                            ErrorCode = Events.ErrorCodes.CouldNotLoadLayer, InMethod = "AddPostGISLayer", AxMapError = AxMap.FileManager.get_ErrorMsg(AxMap.FileManager.LastErrorCode)
                        };
                        On_Error(error);


                        return(false);
                    }
                    else
                    {
                        resTBPostGISLayer.Handle = handle;

                        resTBPostGISLayer.ApplyStyle(AxMap);

                        MapControlTools.Layers.Add(resTBPostGISLayer);
                        Events.MapControl_LayerChange layerchange = new Events.MapControl_LayerChange()
                        {
                            LayerChangeReason = Events.LayerChangeReason.AddLayer, Layer = resTBPostGISLayer
                        };
                        On_LayerChange(layerchange);
                    }

                    return(true);
                }
            }
            return(false);
        }
Пример #27
0
 /// <summary>
 /// constructor
 /// </summary>
 /// <param name="mapControl"></param>
 public MapLayersHandler(AxMap mapControl)
 {
     _axmap                     = mapControl;
     _axmap.LayerAdded         += OnMapLayerAdded;
     _axmap.ProjectionMismatch += OnProjectionMismatch;
     SetLayerColorSchemes();
 }
        private void Callback_MapControl_RasterReprojected(object sender, Events.MapControl_RasterReprojected e)
        {
            Console.WriteLine("Finished");
            Image img = new Image();

            if (img.Open(e.rasterLayer.FileName))
            {
                string proj        = img.GetProjection();
                int    layerHandle = AxMap.AddLayer(img, true);
                if (layerHandle == -1)
                {
                    Events.MapControl_Error imghandle_error = new Events.MapControl_Error()
                    {
                        ErrorCode = Events.ErrorCodes.CouldNotLoadLayer, InMethod = "AddRasterLayer", AxMapError = new GlobalSettings().GdalLastErrorMsg
                    };
                    On_Error(imghandle_error);
                }
                e.rasterLayer.Handle = layerHandle;
                MapControlTools.Layers.Add(e.rasterLayer);
                Events.MapControl_LayerChange layerchange = new Events.MapControl_LayerChange()
                {
                    LayerChangeReason = Events.LayerChangeReason.AddLayer, Layer = e.rasterLayer
                };
                On_LayerChange(layerchange);
            }
        }
Пример #29
0
        public void DrawSymbols(AxMap pMap, Graphics g)
        {
            bool flag = this.InnerList != null && this.InnerList.Count > 0;

            checked
            {
                if (flag)
                {
                    int arg_2E_0 = 0;
                    int num      = this.InnerList.Count - 1;
                    int i        = arg_2E_0;
                    while (true)
                    {
                        int arg_57_0 = i;
                        int num2     = num;
                        if (arg_57_0 > num2)
                        {
                            break;
                        }
                        CSymbol drawSymbol = (CSymbol)this.InnerList[i];
                        drawSymbol.Draw(pMap, g);
                        i++;
                    }
                }
            }
        }
        public override void SaveAttributes(AxMap axMap)
        {
            // check if it is a new shape and we have a reference to the project.
            var editingLayer    = axMap.get_Shapefile(EditingLayerHandle);
            var project_index   = editingLayer.FieldIndexByName[ProjectID];
            var before_index    = editingLayer.FieldIndexByName["BeforeAction"];
            var index_index     = editingLayer.FieldIndexByName["Index"];
            var nathazard_index = editingLayer.FieldIndexByName["NatHazard_ID"];

            for (int i = 0; i < editingLayer.NumShapes; i++)
            {
                if (editingLayer.CellValue[project_index, i] == null)
                {
                    editingLayer.EditCellValue(project_index, i, Project);
                    if (ResTBPostGISType == ResTBPostGISType.HazardMapBefore)
                    {
                        editingLayer.EditCellValue(before_index, i, 1);
                    }
                    else if (ResTBPostGISType == ResTBPostGISType.HazardMapAfter)
                    {
                        editingLayer.EditCellValue(before_index, i, 0);
                    }
                    editingLayer.EditCellValue(index_index, i, Index);
                    editingLayer.EditCellValue(nathazard_index, i, NatHazard.ID);
                }
            }
        }
Пример #31
0
        // <summary>
        // Shows attributes of shape in mouse move event.
        // </summary>
        public void ShowAttributes(AxMap axMap1, string dataPath, ToolStripStatusLabel label)
        {
            axMap1.Projection = tkMapProjection.PROJECTION_GOOGLE_MERCATOR;
            axMap1.ProjectionMismatchBehavior = tkMismatchBehavior.mbCheckLooseAndReproject;

            string filename = dataPath + "landuse.shp";
            Shapefile sf = new Shapefile(); 
            if (sf.Open(filename))
            {
                m_layerHandle = axMap1.AddLayer(sf, true);
                sf = axMap1.get_Shapefile(m_layerHandle);     // in case a copy of shapefile was created by AxMap.ProjectionMismatchBehavior
                
                sf.HotTracking = true;
                axMap1.SendMouseMove = true;
                axMap1.CursorMode = tkCursorMode.cmNone;
                axMap1.ShapeHighlighted += AxMap1ShapeHighlighted;
                m_label = label;
            }
            else
            {
                MessageBox.Show("Failed to open shapefile");
            }
        }