public void DrawCircle() { _axMap1.ClearDrawings(); var dhandle = _axMap1.NewDrawing(tkDrawReferenceList.dlSpatiallyReferencedList); _axMap1.DrawCircle(24.0, 57.0, 0.1, 0, false); Helper.SaveSnapshot2(_axMap1, "DrawCircle.jpg"); }
// <summary> // Opens a shapefile, registers event handler // </summary> public void ToolTip(AxMap axMap1) { axMap1.Projection = tkMapProjection.PROJECTION_NONE; foreach (var filename in _l) { 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.SendMouseMove = true; axMap1.ShowRedrawTime = true; axMap1.MapUnits = tkUnitsOfMeasure.umMeters; axMap1.CurrentScale = 50000; axMap1.CursorMode = tkCursorMode.cmNone; axMap1.MouseMoveEvent += AxMap1MouseMoveEvent; // change MapEvents to axMap1 _mDrawingHandle = axMap1.NewDrawing(tkDrawReferenceList.dlScreenReferencedList); Labels labels = axMap1.get_DrawingLabels(_mDrawingHandle); labels.FrameVisible = true; labels.FrameType = tkLabelFrameType.lfRectangle; } } //string filename = @"C:\Users\Admin\source\repos\GIS\GIS\bin\Debug\Shapefiles_Data\Hanoi\planet_105.141,20.676_106.164,21.273.osm.shp\shape\roads.shp"; }
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> // Opens a shapefile, registers event handler // </summary> public void ToolTip(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.SendMouseMove = true; axMap1.ShowRedrawTime = true; axMap1.MapUnits = tkUnitsOfMeasure.umMeters; axMap1.CurrentScale = 50000; axMap1.CursorMode = tkCursorMode.cmNone; MapEvents.MouseMoveEvent += AxMap1MouseMoveEvent; // change MapEvents to axMap1 _mDrawingHandle = axMap1.NewDrawing(tkDrawReferenceList.dlScreenReferencedList); Labels labels = axMap1.get_DrawingLabels(_mDrawingHandle); labels.FrameVisible = true; labels.FrameType = tkLabelFrameType.lfRectangle; } }
public int AddLayer(DrawReferenceList projection) { return(_map.NewDrawing((tkDrawReferenceList)projection)); }
// <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(); } }