/// <summary> /// Redraw the LegendControl if not locked - See 'Locked' Property for more details /// </summary> public void Redraw(LegendRedraw redrawType = LegendRedraw.LegendOnly) { switch (redrawType) { case LegendRedraw.LegendOnly: RedrawCore(); break; case LegendRedraw.LegendAndMap: _map.Redraw(); RedrawCore(); break; case LegendRedraw.LegendAndMapForce: bool locked = _map.IsLocked == tkLockMode.lmLock; if (locked) { _map.LockWindow(tkLockMode.lmUnlock); } _map.Redraw(); if (locked) { _map.LockWindow(tkLockMode.lmLock); } RedrawCore(); break; } }
private void UpdatePoint(AxMap Map, List <MapWinGIS.Point> PointsToUpdate) { var sf = new Shapefile(); if (PointShapefileLayerHandle != -1) { sf = Map.get_Shapefile(PointShapefileLayerHandle); } if (PointShapefileLayerHandle == -1) { if (!sf.CreateNewWithShapeID("", ShpfileType.SHP_POINT)) { MessageBox.Show("Failed to create shapefile: " + sf.ErrorMsg[sf.LastErrorCode]); return; } PointShapefileLayerHandle = Map.AddLayer(sf, true); } ShapeDrawingOptions options = sf.DefaultDrawingOptions; options.PointType = tkPointSymbolType.ptSymbolStandard; options.PointShape = tkPointShapeType.ptShapeCross; sf.DefaultDrawingOptions = options; sf.CollisionMode = tkCollisionMode.AllowCollisions; sf.EditClear(); foreach (MapWinGIS.Point PointToUpdate in PointsToUpdate) { Shape shp = new Shape(); shp.Create(ShpfileType.SHP_POINT); MapWinGIS.Point pnt = PointToUpdate; int Index; Index = shp.NumPoints; shp.InsertPoint(pnt, ref Index); Index = sf.NumShapes; if (!sf.EditInsertShape(shp, Index)) { MessageBox.Show("Failed to insert shape: " + sf.ErrorMsg[sf.LastErrorCode]); return; } Map.Redraw(); } if (PointsToUpdate.Count == 0) { Map.Redraw(); } }
private void AddPoint(AxMap Map, double lng, double lat, string pointName) { var sf = new Shapefile(); if (PointShapefileLayerHandle != -1) { sf = Map.get_Shapefile(PointShapefileLayerHandle); } if (PointShapefileLayerHandle == -1) { if (!sf.CreateNewWithShapeID("", ShpfileType.SHP_POINT)) { MessageBox.Show("Failed to create shapefile: " + sf.ErrorMsg[sf.LastErrorCode]); return; } PointShapefileLayerHandle = Map.AddLayer(sf, true); } var utils = new Utils(); ShapeDrawingOptions options = sf.DefaultDrawingOptions; options.PointType = tkPointSymbolType.ptSymbolStandard; options.PointShape = tkPointShapeType.ptShapeCross; options.FillColor = utils.ColorByName(tkMapColor.Black); sf.DefaultDrawingOptions = options; sf.CollisionMode = tkCollisionMode.AllowCollisions; Shape shp = new Shape(); //shp = sf.get_Shape(shapeIndex); shp.Create(ShpfileType.SHP_POINT); MapWinGIS.Point pnt = new MapWinGIS.Point(); pnt.x = lng; pnt.y = lat; pnt.Key = pointName; int Index; Index = shp.NumPoints; shp.InsertPoint(pnt, ref Index); Index = sf.NumShapes; if (!sf.EditInsertShape(shp, Index)) { MessageBox.Show("Failed to insert shape: " + sf.ErrorMsg[sf.LastErrorCode]); return; } points.Add(pnt); Map.Redraw(); }
public bool DrawLegend() { bool success = false; RemoveLegend(); if (Graticule != null && Graticule.GridVisible) { if (_legendExtents != null) { _mapLegendPosition = MapLegendPosition.PositionFromDefinedExtent; } else { //SetLegendPositionFromCorner(); _mapLegendPosition = MapLegendPosition.PositionFromCorner; } _legendDrawingLayer = _mapControl.NewDrawing(tkDrawReferenceList.dlScreenReferencedList); using (Graphics g = Graphics.FromHwnd(IntPtr.Zero)) { g.PageUnit = GraphicsUnit.Pixel; foreach (MapLayer ml in MapLayersHandler) { if (ml.IncludeInLegend) { SizeF size = g.MeasureString(ml.Name, SystemFonts.DefaultFont); LegendLabel label = new LegendLabel(ml.Handle, ml.Name, size.Width); label.Height = size.Height; _legendLabels.Add(ml.Handle, label); if (size.Width > _labelMaxWidth) { _labelMaxWidth = size.Width; } if (ml.LayerType == "ShapefileClass") { var sf = ml.LayerObject as Shapefile; if (sf.Categories.Count == 0) { } else if (sf.Categories.Count > 0) { foreach (var item in ml.ClassificationItems) { size = g.MeasureString(item.Value.Caption, SystemFonts.DefaultFont); } } } else { //not a shapefile } } } } success = SetLegendFrame(); } _mapControl.Redraw(); return(_legendLabels.Count > 0); }
// <summary> // Split a shapefile into several ones according the values the specified attribute. // </summary> public void SplitByAttribute(AxMap axMap1, string dataPath) { axMap1.Projection = tkMapProjection.PROJECTION_NONE; axMap1.GrabProjectionFromData = true; string filename = dataPath + "natural.shp"; if (!File.Exists(filename)) { MessageBox.Show("Couldn't file the file: " + filename); } else { Shapefile sf = new Shapefile(); sf.Open(filename, null); int fieldIndex = sf.Table.FieldIndexByName["type"]; sf.Categories.Generate(fieldIndex, tkClassificationType.ctUniqueValues, 0); sf.Categories.ApplyExpressions(); ColorScheme scheme = new ColorScheme(); scheme.SetColors2(tkMapColor.White, tkMapColor.Black); for (int i = 0; i < sf.Categories.Count; i++) { Shapefile sfNew = sf.Clone(); int layerHandle = axMap1.AddLayer(sfNew, true); for (int shapeIndex = 0; shapeIndex < sf.NumShapes; shapeIndex++) { if (sf.ShapeCategory[shapeIndex] == i) { Shape shape = sf.Shape[shapeIndex].Clone(); int index = sfNew.NumShapes; sfNew.EditInsertShape(shape, ref index); } } ShapefileCategory category = sf.Categories.Item[i]; string name = category.Name.Substring(category.Name.IndexOf("=") + 1); uint color = scheme.get_RandomColor((i + 1) / sf.Categories.Count); sfNew.DefaultDrawingOptions.FillColor = color; axMap1.set_LayerName(layerHandle, name); //sfNew.SaveAs(path + name + ".shp", null); // saves shapefile } ShowLegend(); axMap1.ZoomToMaxExtents(); axMap1.Redraw(); } }
/// <summary> /// opens an existing template shapefile by looking for the .lay extension /// </summary> /// <param name="fileName"></param> /// <returns></returns> public bool OpenLayoutFile(string fileName) { bool success = false; _sfLayout = new Shapefile(); if (_sfLayout.Open(fileName.Replace("lay", "shp"))) { _hsfLayout = _majorGrid.MaplayersHandler.AddLayer(_sfLayout, "Layout frame", true, true); if (_hsfLayout > 0) { MaxPanelHeight = 0; MaxPanelWidth = 0; for (int n = 0; n < _sfLayout.NumShapes; n++) { var ext = _sfLayout.Shape[n].Extents; if (ext.Width > MaxPanelWidth) { MaxPanelWidth = (int)ext.Width; LayoutMaxDimensionIndex = n; } if (ext.Height > MaxPanelHeight) { MaxPanelHeight = (int)ext.Height; LayoutMaxDimensionIndex = n; } } _sfLayout.DefaultDrawingOptions.FillVisible = false; _sfLayout.DefaultDrawingOptions.LineWidth = 2; _sfLayout.DefaultDrawingOptions.LineColor = new Utils().ColorByName(tkMapColor.DarkBlue); _majorGrid.MaplayersHandler[_hsfLayout].IsFishingGridLayoutTemplate = true; _axMap.Redraw(); success = true; LayoutTemplateFromFile = true; _layoutExtents = _sfLayout.Extents; } } return(success); }
// <summary> // Adds randomly positioned labels to the image layer. // </summary> public void ImageLabels(AxMap axMap1) { axMap1.Projection = tkMapProjection.PROJECTION_NONE; axMap1.GrabProjectionFromData = true; Image img = new Image(); OpenFileDialog dlg = new OpenFileDialog { Filter = img.CdlgFilter }; if (dlg.ShowDialog() == DialogResult.OK) { img.Open(dlg.FileName, ImageType.USE_FILE_EXTENSION, false, null); axMap1.AddLayer(img, true); Labels lbl = img.Labels; lbl.FontSize = 12; lbl.FontBold = true; lbl.FontOutlineVisible = true; lbl.FontOutlineColor = (255 << 16) + (255 << 8) + 255; //white lbl.FontOutlineWidth = 4; LabelCategory cat = lbl.AddCategory("Red"); cat.FontColor = 255; cat = lbl.AddCategory("Blue"); cat.FontColor = 255 << 16; cat = lbl.AddCategory("Yellow"); cat.FontColor = 255 + 255 << 8; Extents ext = img.Extents; double xRange = ext.xMax - ext.xMin; double yRange = ext.yMax - ext.yMin; Random rnd = new Random(); for (int i = 0; i < 100; i++) { double x = xRange * rnd.NextDouble(); double y = yRange * rnd.NextDouble(); int categoryIndex = i % 3; lbl.AddLabel("label" + Convert.ToString(i), ext.xMin + x, ext.yMin + y, i * 3.6, categoryIndex); } axMap1.Redraw(); } }
// <summary> // Calculates area of polygons and sets 3 range of categories with different symbology // </summary> public void AddCategoryRange(AxMap axMap, string dataPath) { axMap.Projection = tkMapProjection.PROJECTION_GOOGLE_MERCATOR; string filename = dataPath + "landuse.shp"; if (File.Exists(filename) == false) { MessageBox.Show(@"Failed to open file: " + filename); return; } Shapefile sf = new Shapefile(); if (!sf.Open(filename)) { return; } if (!sf.StartEditingTable()) { MessageBox.Show(@"Failed to open editing mode."); return; } int fieldIndex = sf.Table.FieldIndexByName["Area"]; if (fieldIndex == -1) { fieldIndex = sf.EditAddField("Area", FieldType.DOUBLE_FIELD, 15, 18); } for (int i = 0; i < sf.NumShapes; i++) { double area = sf.Shape[i].Area * 100000.0; sf.EditCellValue(fieldIndex, i, area); } // adding to map int handle = axMap.AddLayer(sf, true); sf = axMap.get_Shapefile(handle); // in case a copy of shapefile was created by GlobalSettings.ReprojectLayersOnAdding double mean = sf.Table.MeanValue[fieldIndex]; double stDev = sf.Table.StandardDeviation[fieldIndex]; double min = (double)sf.Table.MinValue[fieldIndex]; double max = (double)sf.Table.MaxValue[fieldIndex]; var scheme = new ColorScheme(); // 1. the first range [min; mean - stDev] Utils utils = new Utils(); sf.DefaultDrawingOptions.FillType = tkFillType.ftHatch; sf.DefaultDrawingOptions.FillHatchStyle = tkGDIPlusHatchStyle.hsDiagonalBrick; sf.Categories.AddRange(fieldIndex, tkClassificationType.ctNaturalBreaks, 5, min, mean); scheme.SetColors2(tkMapColor.Red, tkMapColor.Yellow); // apply colors 0 and 4 are indices of categories, since 5 categories were added - from 0 to 4 sf.Categories.ApplyColorScheme3(tkColorSchemeType.ctSchemeRandom, scheme, tkShapeElements.shElementFill, 0, 4); // 2. the second range [mean - stDev; mean + stDev] // the default drawing options will be copied to the new categories sf.DefaultDrawingOptions.FillType = tkFillType.ftHatch; sf.DefaultDrawingOptions.FillHatchStyle = tkGDIPlusHatchStyle.hsCross; sf.Categories.AddRange(fieldIndex, tkClassificationType.ctEqualIntervals, 5, mean, mean + stDev); scheme.SetColors2(tkMapColor.Green, tkMapColor.Blue); sf.Categories.ApplyColorScheme3(tkColorSchemeType.ctSchemeGraduated, scheme, tkShapeElements.shElementFill, 5, 9); // 3. the third range [mean + stDev; max] // the default drawing options will be copied to the new categories sf.DefaultDrawingOptions.FillType = tkFillType.ftGradient; sf.DefaultDrawingOptions.FillColor2 = utils.ColorByName(tkMapColor.Gray); sf.Categories.AddRange(fieldIndex, tkClassificationType.ctEqualIntervals, 5, mean + stDev, max); scheme.SetColors2(tkMapColor.Pink, tkMapColor.Violet); sf.Categories.ApplyColorScheme3(tkColorSchemeType.ctSchemeGraduated, scheme, tkShapeElements.shElementFill, 10, 14); // apply expresions should be called exlicitly sf.Categories.ApplyExpressions(); axMap.Redraw(); // saving options to see categories desription in XML axMap.SaveLayerOptions(handle, "categories_sample", true, ""); }
public void RedrawNap() { _mapcontrol.Redraw(); }
// <summary> // Assigns markers for points // </summary> public void PointIcons(AxMap axMap1, string dataPath, string iconPath) { axMap1.Projection = tkMapProjection.PROJECTION_GOOGLE_MERCATOR; if (!Directory.Exists(iconPath)) { MessageBox.Show("Icons folder wasn't found: " + iconPath); return; } string roads = dataPath + "roads.shp"; string buildings = dataPath + "buildings.shp"; if (File.Exists(roads)) { Shapefile sfRoads = new Shapefile(); sfRoads.Open(roads, null); sfRoads.DefaultDrawingOptions.LineWidth = 5; //axMap1.AddLayer(sfRoads, true); Shapefile sfBuildings = new Shapefile(); sfBuildings.Open(buildings, null); axMap1.AddLayer(sfBuildings, true); } Shapefile sf = new Shapefile(); string filename = dataPath + "points.shp"; if (!sf.Open(filename, null)) { MessageBox.Show("Failed to open shapefile: " + sf.ErrorMsg[sf.LastErrorCode]); } else { int layerHandle = axMap1.AddLayer(sf, true); sf = axMap1.get_Shapefile(layerHandle); // in case a copy of shapefile was created by GlobalSettings.ReprojectLayersOnAdding int index = sf.Table.FieldIndexByName["Type"]; var names = new HashSet <string>(); for (int i = 0; i < sf.Table.NumRows; i++) { names.Add((string)sf.Table.CellValue[index, i]); } string[] files = Directory.GetFiles(iconPath); foreach (string file in files) { string name = Path.GetFileNameWithoutExtension(file); if (Path.GetExtension(file).ToLower() == ".png" && names.Contains(name)) { Image img = new Image(); if (img.Open(file, ImageType.USE_FILE_EXTENSION, true, null)) { ShapefileCategory ct = sf.Categories.Add(name); ct.Expression = "[Type] = \"" + name + "\""; ct.DrawingOptions.PointType = tkPointSymbolType.ptSymbolPicture; ct.DrawingOptions.Picture = img; } } } sf.DefaultDrawingOptions.Visible = false; // hide all the unclassified points sf.Categories.ApplyExpressions(); axMap1.Redraw(); } }
public void MoveToTop() { _axmap.MoveLayerTop(_axmap.get_LayerPosition(_currentMapLayer.Handle)); _axmap.Redraw(); }
/// <summary> /// Creates a polygon shapefile by placing 100 circles randomly. /// </summary> public void CreatePolygonShapefile(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; var rnd = new Random(DateTime.Now.Millisecond); int fldX = sf.EditAddField("x", FieldType.DOUBLE_FIELD, 9, 12); int fldY = sf.EditAddField("y", FieldType.DOUBLE_FIELD, 9, 12); int fldArea = sf.EditAddField("area", FieldType.DOUBLE_FIELD, 9, 12); // In a loop we are creating 100 different points using the box established above. for (int i = 0; i < 100; 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; // polygons must be clockwise Shape shp = new Shape(); shp.Create(ShpfileType.SHP_POLYGON); for (int j = 0; j < 37; j++) { Point pnt = new Point(); pnt.x = xCenter + radius * Math.Cos(j * Math.PI / 18); pnt.y = yCenter - radius * Math.Sin(j * Math.PI / 18); shp.InsertPoint(pnt, ref j); } Debug.Print(shp.Extents.ToDebugString()); sf.EditInsertShape(shp, ref i); sf.EditCellValue(fldX, i, xCenter.ToString()); sf.EditCellValue(fldY, i, yCenter.ToString()); sf.EditCellValue(fldArea, i, Math.PI * radius * radius); } int handle = axMap1.AddLayer(sf, true); string extents = sf.Extents.ToDebugString(); axMap1.ZoomToLayer(handle); sf.Categories.Generate(fldArea, tkClassificationType.ctNaturalBreaks, 7); ColorScheme scheme = new ColorScheme(); scheme.SetColors2(tkMapColor.Wheat, tkMapColor.Salmon); sf.Categories.ApplyColorScheme(tkColorSchemeType.ctSchemeGraduated, scheme); axMap1.Redraw(); // save if needed //sf.SaveAs(@"c:\polygons.shp", null); } }
// <summary> // Creates a drawing layer from the specified shapefile. // </summary> public void ShapefileToDrawingLayer(AxMap axMap1, string dataPath) { axMap1.Projection = tkMapProjection.PROJECTION_NONE; axMap1.GrabProjectionFromData = true; string[] filenames = new [] { "buildings.shp", "roads.shp", "points.shp" }; for (int i = 0; i < filenames.Length; i++) { filenames[i] = dataPath + filenames[i]; } Extents extents = null; var center = (axMap1.Extents as Extents).Center; try { for (int n = 0; n < filenames.Length; n++) { Shapefile sf = new Shapefile(); if (sf.Open(filenames[n], null)) { if (axMap1.Projection == tkMapProjection.PROJECTION_NONE) { axMap1.GeoProjection = sf.GeoProjection.Clone(); } if (extents == null) { extents = sf.Extents; // the extents of the fist shapefile will be used to setup display } int drawHandle = axMap1.NewDrawing(tkDrawReferenceList.dlSpatiallyReferencedList); for (int i = 0; i < sf.NumShapes; i++) { Shape shp = sf.Shape[i]; if (shp.ShapeType == ShpfileType.SHP_POINT) { double x = 0.0; double y = 0.0; shp.get_XY(0, ref x, ref y); axMap1.DrawPointEx(drawHandle, x, y, 5, 0); } else { for (int p = 0; p < shp.NumParts; p++) { int initIndex = shp.Part[p]; int numPoints = shp.EndOfPart[p] - shp.Part[p] + 1; if (numPoints > 0) { double[] x = new double[numPoints]; double[] y = new double[numPoints]; for (int j = 0; j < numPoints; j++) { shp.get_XY(j + initIndex, ref x[j], ref y[j]); } object xObj = x; object yObj = y; bool drawFill = shp.ShapeType == ShpfileType.SHP_POLYGON; uint color = sf.ShapefileType == ShpfileType.SHP_POLYGON ? sf.DefaultDrawingOptions.FillColor : sf.DefaultDrawingOptions.LineColor; axMap1.DrawPolygonEx(drawHandle, ref xObj, ref yObj, numPoints, color, drawFill); } } } } } } } finally { if (extents != null) { axMap1.Extents = extents; } axMap1.LockWindow(tkLockMode.lmUnlock); axMap1.Redraw(); } }
// <summary> // Creates several buffers around the waterways. // </summary> public void CreateBuffer(AxMap axMap1, string dataPath, System.Windows.Forms.ToolStripStatusLabel label) { axMap1.Projection = tkMapProjection.PROJECTION_GOOGLE_MERCATOR; string filename = dataPath + "waterways.shp"; if (!File.Exists(filename)) { MessageBox.Show("The shapefile with rivers wasn't found: " + filename); } else { var callback = new Callback(label); var sf = new Shapefile(); if (!sf.Open(filename, callback)) { MessageBox.Show(sf.ErrorMsg[sf.LastErrorCode]); } else { int layerHandle = axMap1.AddLayer(sf, true); sf = axMap1.get_Shapefile(layerHandle); // in case a copy of shapefile was created by GlobalSettings.ReprojectLayersOnAdding var utils = new Utils(); sf.DefaultDrawingOptions.LineWidth = 3.0f; sf.DefaultDrawingOptions.LineColor = utils.ColorByName(tkMapColor.Blue); const double distance = 150; // meters var buffers = new List <Shapefile>(); for (int i = 1; i < 5; i++) { Shapefile sfBuffer = sf.BufferByDistance(distance * i, 30, false, true); if (sfBuffer == null) { MessageBox.Show("Failed to calculate the buffer: " + sf.ErrorMsg[sf.LastErrorCode]); return; } else { sfBuffer.GlobalCallback = callback; buffers.Add(sfBuffer); } } // now subtract smaller buffers from larger ones for (int i = buffers.Count - 1; i > 0; i--) { Shapefile sfDiff = buffers[i].Difference(false, buffers[i - 1], false); if (sfDiff == null) { MessageBox.Show("Failed to calculate the difference: " + sf.ErrorMsg[sf.LastErrorCode]); return; } else { buffers[i] = sfDiff; } } // pass all the resulting shapes to a single shapefile and mark their distance Shapefile sfResult = buffers[0].Clone(); sfResult.GlobalCallback = callback; int fieldIndex = sfResult.EditAddField("Distance", FieldType.DOUBLE_FIELD, 10, 12); for (int i = 0; i < buffers.Count; i++) { Shapefile sfBuffer = buffers[i]; for (int j = 0; j < sfBuffer.NumShapes; j++) { int index = sfResult.NumShapes; sfResult.EditInsertShape(sfBuffer.Shape[j].Clone(), ref index); sfResult.EditCellValue(fieldIndex, index, distance * (i + 1)); } } // create visualization categories sfResult.DefaultDrawingOptions.FillType = tkFillType.ftStandard; sfResult.Categories.Generate(fieldIndex, tkClassificationType.ctUniqueValues, 0); sfResult.Categories.ApplyExpressions(); // apply color scheme var scheme = new ColorScheme(); scheme.SetColors2(tkMapColor.LightBlue, tkMapColor.LightYellow); sfResult.Categories.ApplyColorScheme(tkColorSchemeType.ctSchemeGraduated, scheme); layerHandle = axMap1.AddLayer(sfResult, true); axMap1.Redraw(); //sfResult.SaveAs(@"c:\buffers.shp", null); } } }
public bool SaveEdits() { if (CurrentEditingLayer == null) { Events.MapControl_Error error = new Events.MapControl_Error() { ErrorCode = Events.ErrorCodes.UseStartEditing, InMethod = "StopEditingLayer", AxMapError = "" }; On_Error(error); return(false); } Events.MapControl_EditingStateChange editingStateChange = new Events.MapControl_EditingStateChange() { EditingState = Events.EditingState.SaveEditing, EditingLayer = CurrentEditingLayer }; On_EditingStateChange(editingStateChange); var sf = AxMap.get_Shapefile(CurrentEditingLayer.Handle); var ogrLayer = AxMap.get_OgrLayer(CurrentEditingLayer.Handle); bool success = false; if (ogrLayer != null) { ogrLayer = ((ResTBPostGISLayer)CurrentEditingLayer).EditingLayer; ((ResTBPostGISLayer)CurrentEditingLayer).SaveAttributes(AxMap); int savedCount; tkOgrSaveResult saveResult = ogrLayer.SaveChanges(out savedCount); success = saveResult == tkOgrSaveResult.osrAllSaved || saveResult == tkOgrSaveResult.osrNoChanges; // if hazard map before --> copy to hazardmap after if ((success) && (((ResTBPostGISLayer)CurrentEditingLayer).ResTBPostGISType == ResTBPostGISType.HazardMapBefore) && (isAdding)) { string newName = ((ResTBHazardMapLayer)CurrentEditingLayer).CopyToAfter(MapControlTools); ILayer HMAfter = MapControlTools.Layers.Where(m => m.Name == newName).FirstOrDefault(); if (HMAfter != null) { ogrLayer = AxMap.get_OgrLayer(HMAfter.Handle); ogrLayer.ReloadFromSource(); } } ogrLayer = AxMap.get_OgrLayer(CurrentEditingLayer.Handle); ogrLayer.ReloadFromSource(); } if (success) { sf.InteractiveEditing = false; AxMap.ShapeEditor.Clear(); AxMap.UndoList.ClearForLayer(CurrentEditingLayer.Handle); Events.MapControl_EditingStateChange editingStateChangeStop = new Events.MapControl_EditingStateChange() { EditingState = Events.EditingState.StopEditing, EditingLayer = CurrentEditingLayer }; On_EditingStateChange(editingStateChangeStop); Events.MapControl_LayerChange layerChange = new Events.MapControl_LayerChange() { Layer = this.CurrentEditingLayer, LayerChangeReason = Events.LayerChangeReason.EditedLayer }; On_LayerChange(layerChange); return(true); } AxMap.Redraw(); return(false); }
/// <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") { } } }
public bool Redraw(bool reloadLayers = false) { Events.MapControl_BusyStateChange bc = new Events.MapControl_BusyStateChange(); bc = new Events.MapControl_BusyStateChange(); bc.BusyState = Events.BusyState.Busy; bc.KeyOfSender = "Redraw"; bc.Percent = 0; bc.Message = Resources.MapControl_RedrawMap; MapControlTools.On_BusyStateChange(bc); if (reloadLayers) { double percentadd = 80.0 / MapControlTools.Layers.Count; int currentpercent = 10; foreach (ILayer layer in MapControlTools.Layers) { Type editingLayerType = layer.GetType(); if (editingLayerType == typeof(ResTBDamagePotentialLayer)) { OgrLayer o = AxMap.get_OgrLayer(((ResTBDamagePotentialLayer)layer).PointHandle); o.ReloadFromSource(); o = AxMap.get_OgrLayer(((ResTBDamagePotentialLayer)layer).LineHandle); o.ReloadFromSource(); o = AxMap.get_OgrLayer(((ResTBDamagePotentialLayer)layer).PolygonHandle); o.ReloadFromSource(); } else if (editingLayerType == typeof(ResTBRiskMapLayer)) { OgrLayer o = AxMap.get_OgrLayer(((ResTBRiskMapLayer)layer).PointHandle); o.ReloadFromSource(); o = AxMap.get_OgrLayer(((ResTBRiskMapLayer)layer).LineHandle); o.ReloadFromSource(); o = AxMap.get_OgrLayer(((ResTBRiskMapLayer)layer).PolygonHandle); o.ReloadFromSource(); } else if (editingLayerType.BaseType != null && editingLayerType.BaseType == typeof(ResTBPostGISLayer)) { OgrLayer o = AxMap.get_OgrLayer(((ResTBPostGISLayer)layer).Handle); o.ReloadFromSource(); } layer.ShapeCount = MapControlTools.ShapesCount(layer.Name); currentpercent += (int)percentadd; bc = new Events.MapControl_BusyStateChange(); bc.BusyState = Events.BusyState.Busy; bc.KeyOfSender = "Redraw"; bc.Percent = currentpercent; bc.Message = Resources.MapControl_ReloadLayers; } } bc = new Events.MapControl_BusyStateChange(); bc.BusyState = Events.BusyState.Busy; bc.KeyOfSender = "Redraw"; bc.Percent = 80; bc.Message = Resources.MapControl_RedrawMap; MapControlTools.On_BusyStateChange(bc); AxMap.Redraw(); foreach (BaseLayer l in MapControlTools.Layers) { l.ApplyStyle(AxMap); } bc = new Events.MapControl_BusyStateChange(); bc = new Events.MapControl_BusyStateChange(); bc.BusyState = Events.BusyState.Idle; bc.KeyOfSender = "Redraw"; bc.Percent = 100; bc.Message = Resources.MapControl_MapRefreshed; MapControlTools.On_BusyStateChange(bc); //MapControlTools.ReStartSelecting(); return(true); }
/// <summary> /// Runs appropriate handler for the element that was clicked. If no handler is found false is returned. /// </summary> private bool OnLayerElementClicked(LegendLayer lyr, LegendElement element) { switch (element.Type) { case LayerElementType.RasterColorBox: case LayerElementType.ColorBox: if (element.Index == -1) { FireEvent(this, LayerStyleClicked, new LayerEventArgs(lyr.Handle)); } else { FireEvent(this, LayerCategoryClicked, new LayerCategoryEventArgs(lyr.Handle, MouseButtons.Left, element.Index)); } break; case LayerElementType.Label: FireEvent(this, LayerLabelsClicked, new LayerEventArgs(lyr.Handle)); break; case LayerElementType.Charts: case LayerElementType.ChartField: case LayerElementType.ChartFieldName: FireEvent(this, LayerDiagramsClicked, new LayerMouseEventArgs(lyr.Handle, MouseButtons.Left)); // event for individual fields can be fired if necessary // FireEvent(this, LayerDiagramFieldClicked, new ChartFieldClickedEventArgs(lyr.Handle, MouseButtons.Left, element.Index)); break; case LayerElementType.CategoryCheckbox: var sf = AxMap.get_Shapefile(lyr.Handle); if (sf != null) { var ct = sf.Categories.Item[element.Index]; if (ct != null) { bool state = ct.DrawingOptions.Visible; ct.DrawingOptions.Visible = !state; AxMap.Redraw(); } } break; case LayerElementType.CheckBox: { var newState = !AxMap.get_LayerVisible(lyr.Handle); var args = new LayerCancelEventArgs(lyr.Handle, newState); FireEvent(this, LayerVisibleChanged, args); if (args.Cancel) { return(true); } AxMap.set_LayerVisible(lyr.Handle, newState); var group = GetGroup(element.GroupIndex); group.UpdateGroupVisibility(); FireEvent(this, LayerCheckboxClicked, new LayerEventArgs(lyr.Handle)); } break; case LayerElementType.ExpansionBox: { Lock(); lyr.Expanded = !lyr.Expanded; FireEvent(this, LayerPropertiesChanged, new LayerEventArgs(lyr.Handle)); Unlock(); return(true); } case LayerElementType.CategoriesCaption: case LayerElementType.ChartsCaption: Logger.Current.Info("Legend element clicked: " + element.Type + ". No handler is attached"); return(true); case LayerElementType.Name: case LayerElementType.None: default: return(false); } Redraw(); return(true); }