public override void MouseClick(object sender, MouseEventArgs e) { if (map.InsertionLayer == null) return; CoordSys layerCoordsys = map.InsertionLayer.LayerCoordSys; CoordConverter oCC = new CoordConverter(); oCC.Init(layerCoordsys, map.DisplayCoordSys); // this atPan converts DisplayCoordSys into Screen CoordSys[px] // DisplayCoordSys has Y axis up (unless its AT does not change it) // Screen Y axis is down AffineTransform atPan = new AffineTransform(); atPan.OffsetInPlace((double)map.MapOffsetX, (double)map.MapOffsetY); atPan.MultiplyInPlace(map.MapScale, -map.MapScale); // add screen scale and offset transformation oCC.atMaster = oCC.atMaster.Compose(atPan); oCC.ConvertInverse(e.X, e.Y); DPoint pt = new DPoint(oCC.X, oCC.Y); // szukaj w tym miejscu feature List<Feature> ftrs = map.InsertionLayer.Search(pt); if (ftrs.Count == 0) { Feature oF = FeatureFactory.CreateSymbol(oCC.X, oCC.Y); map.InsertionLayer.FeaturesAdd(oF); } MapControl.Globals.Instance.MapControl.InvalidateMap(); }
public override void MouseMove(object sender, MouseEventArgs e) { base.MouseMove(sender, e); // highlight polilines and points if (map.InsertionLayer == null) return; CoordSys layerCoordsys = map.InsertionLayer.LayerCoordSys; CoordConverter oCC = new CoordConverter(); oCC.Init(layerCoordsys, map.DisplayCoordSys); // this atPan converts DisplayCoordSys into Screen CoordSys[px] // DisplayCoordSys has Y axis up (unless its AT does not change it) // Screen Y axis is down AffineTransform atPan = new AffineTransform(); atPan.OffsetInPlace((double)map.MapOffsetX, (double)map.MapOffsetY); atPan.MultiplyInPlace(map.MapScale, -map.MapScale); // add screen scale and offset transformation oCC.atMaster = oCC.atMaster.Compose(atPan); int margin = 5; oCC.ConvertInverse(e.X, e.Y); DPoint pt_center = new DPoint(oCC.X, oCC.Y); oCC.ConvertInverse(e.X - margin, e.Y - margin); DPoint pt1 = new DPoint(oCC.X, oCC.Y); oCC.ConvertInverse(e.X + margin, e.Y + margin); DPoint pt2 = new DPoint(oCC.X, oCC.Y); // szukaj w tym miejscu feature //List<Feature> ftrs = map.InsertionLayer.Search(pt); // construct search rectangle (10px wide) DRect rect = new DRect(pt1.X, pt2.Y, pt2.X, pt1.Y); //map.InsertionLayer.SelectWithinRectangle(rect); }
void DrawLayer(LayerAbstract oL, Graphics g, Rectangle Rect) { CoordSys layerCoordsys = oL.LayerCoordSys; CoordConverter oCC = new CoordConverter(); oCC.Init(layerCoordsys, DisplayCoordSys); // this atPan converts DisplayCoordSys into Screen CoordSys[px] // DisplayCoordSys has Y axis up (unless its AT does not change it) // Screen Y axis is down AffineTransform atPan = new AffineTransform(); atPan.OffsetInPlace((double)mapOffsetX, (double)mapOffsetY); atPan.MultiplyInPlace(mapScale, -mapScale); // add screen scale and offset transformation oCC.atMaster = oCC.atMaster.Compose(atPan); oL.Draw(g, Rect, oCC); }
/// <summary> /// Select all objects within the rectangle /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public override void MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) { bool modified = false; base.MouseUp(sender, e); bool keyShift = ((System.Windows.Forms.Control.ModifierKeys & Keys.Shift) == Keys.Shift); bool keyControl = ((System.Windows.Forms.Control.ModifierKeys & Keys.Control) == Keys.Control); MapControl.Globals.Instance.MapControl.Cursor = Cursors.Arrow; if (ActiveRectangle.Width == 0 && ActiveRectangle.Height == 0) { relocateMode = false; rotateMode = false; rectSelectionMode = false; relocateModeAllowRelocation = false; DRect rect = calculateRectangleFromPoint(e.X, e.Y); List<DPoint> points = polylineLayer.SearchForPolylinePoints(rect); if (points.Count > 0) { if (points[0].Selected) { if (!keyControl && !keyShift) { polylineLayer.selectionClear(); points[0].Selected = true; MapControl.Globals.Instance.MapControl.InvalidateMap(); modified = true; } if (keyControl && !keyShift) { points[0].Selected = false; MapControl.Globals.Instance.MapControl.InvalidateMap(); modified = true; } } else { if (keyControl && !keyShift) { points[0].Selected = true; MapControl.Globals.Instance.MapControl.InvalidateMap(); modified = true; } } if (modified) { if (ToolUsed != null) ToolUsed(this, new EventArgs()); } return; } // select polyline // try to select an object List<Feature> features = polylineLayer.SearchForFeaturesColliding(rect); if (features.Count > 0) { if (features[0].Selected) { if (!keyControl && !keyShift) { polylineLayer.selectionClear(); features[0].Selected = true; modified = true; MapControl.Globals.Instance.MapControl.InvalidateMap(); } if (keyControl && !keyShift) { features[0].Selected = false; modified = true; MapControl.Globals.Instance.MapControl.InvalidateMap(); } } else { if (keyControl && !keyShift) { features[0].Selected = true; modified = true; MapControl.Globals.Instance.MapControl.InvalidateMap(); } } if (modified) { if (ToolUsed != null) ToolUsed(this, new EventArgs()); } return; } if (!keyControl && !keyShift) { polylineLayer.selectionClear(); modified = true; } } else { // Dragging done if (relocateMode && relocateModeAllowRelocation) { List<Feature> features = polylineLayer.selectionFeatures(); List<DPoint> points = polylineLayer.selectionPoints(true); // calculate delta... // mouse start: m_oMouseStart // mouse end: m_oMouseCurrent int dxi = m_oMouseStart.X - m_oMouseCurrent.X; int dyi = m_oMouseStart.Y - m_oMouseCurrent.Y; int pixelDelta = (int)Math.Sqrt(dxi * dxi + dyi * dyi); DRect r1 = calculateRectangleFromPoint(m_oMouseStart.X, m_oMouseStart.Y); DRect r2 = calculateRectangleFromPoint(m_oMouseCurrent.X, m_oMouseCurrent.Y); double dx = r2.X1 - r1.X1; double dy = r2.Y1 - r1.Y1; // store copy of original point for undo polylineLayer.Manager.startRecordingUndoElement(); symbolLayer.Manager.startRecordingUndoElement(); // move polylines for (int i = 0; i < points.Count; i++) { DPoint newPoint = new DPoint(points[i].X + dx, points[i].Y + dy); polylineLayer.Manager.recordMovePoint(points[i], newPoint); // find correcponding symbol in symbolLayer SymbolFeature symbol = (SymbolFeature)points[i].Tag; Debug.Assert(symbol != null); SymbolFeature newSymbol = new SymbolFeature(symbol.x + dx, symbol.y + dy); symbolLayer.Manager.recordMoveFeature(symbol, newSymbol); modified = true; } polylineLayer.Manager.stopRecordingUndoElement(); symbolLayer.Manager.stopRecordingUndoElement(); // refresh view MapControl.Globals.Instance.MapControl.InvalidateMap(); } if (rotateMode) { // rotation } if (rectSelectionMode) { if (!keyShift && !keyControl) { polylineLayer.selectionClear(); modified = true; /* // emit clear selection for all wpt-s for (int i = 0; i < symbolLayer.FeaturesCount; i++) { SymbolFeature symbol = symbolLayer.FeatureGet(i) as SymbolFeature; if (symbol != null) { //WptSelected(this, (symbol.Tag as GpxWpt), false); } }*/ } if (!keyControl) { System.Drawing.Rectangle r = ActiveRectangle; System.Drawing.Point p1 = new System.Drawing.Point(r.X, r.Y); System.Drawing.Point p2 = new System.Drawing.Point(r.X + r.Width, r.Y + r.Height); DPoint pt1, pt2; map.DisplayTransform.FromDisplay(p1, out pt1); map.DisplayTransform.FromDisplay(p2, out pt2); // convert mercator to wgs84 CoordConverter occ = new CoordConverter(); CoordSys oCSMercator = CoordSysFactory.CreateCoordSys(CoordSysType.Mercator, CoordSysFactory.CreateDatum(DatumID.WGS84), new AffineTransform()); CoordSys oCSWGS84 = CoordSysFactory.CreateCoordSys(CoordSysType.LatLong, CoordSysFactory.CreateDatum(DatumID.WGS84), new AffineTransform()); occ.Init(oCSMercator, oCSWGS84); occ.Convert(pt1.X, pt1.Y); DPoint dp1 = new DPoint(occ.X, occ.Y); occ.Convert(pt2.X, pt2.Y); DPoint dp2 = new DPoint(occ.X, occ.Y); DRect rect = new DRect(dp1.X, dp2.Y, dp2.X, dp1.Y); List<DPoint> points = polylineLayer.SearchForPolylinePoints(rect); for (int i = 0; i < points.Count; i++) { points[i].Selected = true; modified = true; } List<Feature> features = polylineLayer.SearchForFeaturesContained(rect); for (int i = 0; i < features.Count; i++) { features[i].Selected = true; modified = true; } MapControl.Globals.Instance.MapControl.InvalidateMap(); } } if (timer != null) { timer.Stop(); timer = null; } relocateMode = false; rotateMode = false; rectSelectionMode = false; relocateModeAllowRelocation = false; } if (modified) { if (ToolUsed != null) ToolUsed(this, new EventArgs()); } }
private DRect calculateRectangleFromPoint(int x, int y) { // try to select a polyline point int margin = 3; System.Drawing.Point p1 = new System.Drawing.Point(x - margin, y - margin); System.Drawing.Point p2 = new System.Drawing.Point(x + margin, y + margin); DPoint pt1, pt2; map.DisplayTransform.FromDisplay(p1, out pt1); map.DisplayTransform.FromDisplay(p2, out pt2); // convert mercator to wgs84 CoordConverter occ = new CoordConverter(); CoordSys oCSMercator = CoordSysFactory.CreateCoordSys(CoordSysType.Mercator, CoordSysFactory.CreateDatum(DatumID.WGS84), new AffineTransform()); CoordSys oCSWGS84 = CoordSysFactory.CreateCoordSys(CoordSysType.LatLong, CoordSysFactory.CreateDatum(DatumID.WGS84), new AffineTransform()); occ.Init(oCSMercator, oCSWGS84); occ.Convert(pt1.X, pt1.Y); DPoint dp1 = new DPoint(occ.X, occ.Y); occ.Convert(pt2.X, pt2.Y); DPoint dp2 = new DPoint(occ.X, occ.Y); DRect rect = new DRect(dp1.X, dp2.Y, dp2.X, dp1.Y); return rect; }
private void aboutToolStripMenuItem_Click(object sender, EventArgs e) { // test coordsys Datum datumEllipse = CoordSysFactory.CreateDatum(DatumID.WGS84); Datum datumSphere = CoordSysFactory.CreateDatum(Ellipsoid.Sphere, 0, 0, 0, 0, 0, 0, 0, 0); CoordSys source = CoordSysFactory.CreateCoordSys(CoordSysType.LatLong, datumEllipse, new AffineTransform()); CoordSys target = CoordSysFactory.CreateCoordSys(CoordSysType.Mercator, datumEllipse, new AffineTransform()); CoordConverter oCC = new CoordConverter(); oCC.Init(source, target); oCC.Convert(21, 52); double x = oCC.X; // 2337709.3066587453 double y = oCC.Y; // 6800125.4543973068 // (21, 52) -> (2337709.3066587453, 6800125.4543973068) (alg. Sphere) // (21, 52) -> (2337709.3066587453, 6766432.7231710562) (alg. Ellipse) // (21, 52) -> (2337709.3066587453, 6800078.8362877583) (DatumConv + Ellipse) // (21, 52) -> (2337709.3066587453, 6800125.4543973068) (alg. Ellipse , data Sphere) }
private void tileDownloaderToolStripMenuItem_Click(object sender, EventArgs e) { // auto download tiles // calculate x,y, range // calculate zoom range CoordSys layerCoordsys = tileLayer.LayerCoordSys; CoordConverter oCC = new CoordConverter(); oCC.Init(layerCoordsys, mapControl1.Map.DisplayCoordSys); // this atPan converts DisplayCoordSys into Screen CoordSys[px] // DisplayCoordSys has Y axis up (unless its AT does not change it) // Screen Y axis is down AffineTransform atPan = new AffineTransform(); atPan.OffsetInPlace((double)mapControl1.Map.MapOffsetX, (double)mapControl1.Map.MapOffsetY); atPan.MultiplyInPlace(mapControl1.Map.MapScale, -mapControl1.Map.MapScale); // add screen scale and offset transformation oCC.atMaster = oCC.atMaster.Compose(atPan); double zoomElevateUpscale = 1024 * 8; //1024; double scale = oCC.atMaster.A; int zoom = (int)Math.Log(scale * zoomElevateUpscale, 2); TileDownloader downloader = new TileDownloader(); downloader.Download(zoom, ((LayerTilesAsynch)tileLayer).MapType, oCC, new System.Drawing.Rectangle(0, 0, mapControl1.Width, mapControl1.Height)); }
private void mapControl1_MouseMove(object sender, MouseEventArgs e) { DPoint pt; mapControl1.Map.DisplayTransform.FromDisplay(new System.Drawing.Point(e.X, e.Y), out pt); // convert mercator to wgs84 CoordConverter occ = new CoordConverter(); CoordSys oCSMercator = CoordSysFactory.CreateCoordSys(CoordSysType.Mercator, CoordSysFactory.CreateDatum(DatumID.WGS84), new AffineTransform()); CoordSys oCSWGS84 = CoordSysFactory.CreateCoordSys(CoordSysType.LatLong, CoordSysFactory.CreateDatum(DatumID.WGS84), new AffineTransform()); occ.Init(oCSMercator, oCSWGS84); occ.Convert(pt.X, pt.Y); // calculate zoom CoordSys layerCoordsys = tileLayer.LayerCoordSys; CoordConverter oCC = new CoordConverter(); oCC.Init(layerCoordsys, mapControl1.Map.DisplayCoordSys); // this atPan converts DisplayCoordSys into Screen CoordSys[px] // DisplayCoordSys has Y axis up (unless its AT does not change it) // Screen Y axis is down AffineTransform atPan = new AffineTransform(); atPan.OffsetInPlace((double)mapControl1.Map.MapOffsetX, (double)mapControl1.Map.MapOffsetY); atPan.MultiplyInPlace(mapControl1.Map.MapScale, -mapControl1.Map.MapScale); // add screen scale and offset transformation oCC.atMaster = oCC.atMaster.Compose(atPan); double zoomElevateUpscale = 1024 * 8; //1024; double scale = oCC.atMaster.A; int zoom = (int)Math.Log(scale * zoomElevateUpscale, 2); lblInfo.Text = string.Format("x={0:0.00000}, y={1:0.00000} Mercator: x={2:0}, y={3:0}, zoom={4}", occ.X, occ.Y, pt.X, pt.Y, zoom); }
private void mapControl1_MouseClick(object sender, MouseEventArgs e) { if (mapControl1.CurrentTool == MapControl.ToolConst.InfoTool) { // get gpx coordinate (from map or from gpx table) DPoint pt; mapControl1.Map.DisplayTransform.FromDisplay(new System.Drawing.Point(e.X, e.Y), out pt); // convert mercator to wgs84 CoordConverter occ = new CoordConverter(); CoordSys oCSMercator = CoordSysFactory.CreateCoordSys(CoordSysType.Mercator, CoordSysFactory.CreateDatum(DatumID.WGS84), new AffineTransform()); CoordSys oCSWGS84 = CoordSysFactory.CreateCoordSys(CoordSysType.LatLong, CoordSysFactory.CreateDatum(DatumID.WGS84), new AffineTransform()); occ.Init(oCSMercator, oCSWGS84); occ.Convert(pt.X, pt.Y); lblInfo.Text = string.Format("x={0:0.00000}, y={1:0.00000} Mercator: x={2:0}, y={3:0}", occ.X, occ.Y, pt.X, pt.Y); // search for features //Feature[] fts = oLayerPointer.Search(pt); //e.X } }
private void InitMapAndPresenter() { // set Display coordsys mapControl1.Map.DisplayCoordSys = CoordSysFactory.CreateCoordSys("Mercator Datum(WGS84)"); // make Map Layer mapControl1.Map.Layers.Clear(); mapControl1.ResizeScaleMode = MapControl.ResizeScaleConst.NoChange; // One Tile Layer tileLayer = new LayerTilesAsynch(); // mercator (datum(wgs84)) mapControl1.Map.Layers.Add(tileLayer); // MVC ------------ // bind view to presentation surface (control) gpxMapView = new GPXViewMap(mapControl1); gpxViewTree = new GPXViewTree(treeView1); gpxViewScrollbar = new GPXViewScrollbar(gpxScrollBar); gpxViewTimeSlide = new GPXViewTimeSlide(timeSlide1); gpxPresenter = new GPXPresenter(); gpxPresenter.registerView(gpxMapView); gpxPresenter.registerView(gpxViewTree); gpxPresenter.registerView(gpxViewScrollbar); gpxPresenter.registerView(gpxViewTimeSlide); mapControl1.Map.InsertionLayer = gpxMapView.o_LayerGPXPolylines; // CoordSys oCSWGS84 = CoordSysFactory.CreateCoordSys(CoordSysType.LatLong, CoordSysFactory.CreateDatum(DatumID.WGS84), new AffineTransform()); oCCGPS = new CoordConverter(); oCCGPS.Init(gpxMapView.o_LayerGPXPolylines.LayerCoordSys, mapControl1.Map.DisplayCoordSys); // show zoom=0 (whole world) in scale 1px screen = 1px layer Datum datumWGS84 = CoordSysFactory.CreateDatum(DatumID.WGS84); double r = datumWGS84.SemiMajorAxis; double zoom = mapControl1.Bounds.Width / 256.0 * 2 * Math.PI * r; //mapControl1.SetCenterZoom(0.0, 0.0, zoom, mapControl1.Bounds); /* if (gpxFile.getWptCount() > 0) { GpxWpt wpt = gpxFile.getWpt(0); oCCGPS.Convert(wpt.lon, wpt.lat); mapControl1.SetCenterZoom(oCCGPS.X, -oCCGPS.Y, zoom / 256.0, mapControl1.Bounds); // center poland } else {*/ oCCGPS.Convert(21.0, 52.0); mapControl1.SetCenterZoom(oCCGPS.X, -oCCGPS.Y, zoom / 256.0, mapControl1.Bounds); // center poland //} }