/* * protected async override void OnUpdate() * { * Cursor nowCursor = Cursor; * Cursor = _containsFeatures ? Cursors.Arrow : _thisCursor; * * if (nowCursor != Cursor) * { * await FrameworkApplication.SetCurrentToolAsync("esri_mapping_exploreTool"); * await FrameworkApplication.SetCurrentToolAsync("globeSpotterArcGISPro_openImageTool"); * } * * base.OnUpdate(); * } * * protected override async void OnToolMouseMove(MapViewMouseEventArgs e) * { * await QueuedTask.Run(() => * { * var constants = ConstantsRecordingLayer.Instance; * double size = constants.SizeLayer; * double halfSize = size / 2; * MapView activeView = MapView.Active; * * WinPoint clientPoint = e.ClientPoint; * WinPoint pointScreen = activeView.ClientToScreen(clientPoint); * double x = pointScreen.X; * double y = pointScreen.Y; * WinPoint minPoint = new WinPoint(x - halfSize, y - halfSize); * WinPoint maxPoint = new WinPoint(x + halfSize, y + halfSize); * MapPoint minPoint1 = activeView.ScreenToMap(minPoint); * MapPoint maxPoint1 = activeView.ScreenToMap(maxPoint); * Envelope envelope = EnvelopeBuilder.CreateEnvelope(minPoint1, maxPoint1, minPoint1.SpatialReference); * var features = MapView.Active?.GetFeatures(envelope); * _containsFeatures = (features != null) && (features.Count >= 1); * }); * * base.OnToolMouseMove(e); * } */ protected override Task <bool> OnSketchCompleteAsync(Geometry geometry) { return(QueuedTask.Run(() => { MapPoint point = geometry as MapPoint; MapView activeView = MapView.Active; if (point != null && activeView != null) { var constants = ConstantsRecordingLayer.Instance; double size = constants.SizeLayer; double halfSize = size / 2; SpatialReference pointSpatialReference = point.SpatialReference; var pointScreen = activeView.MapToScreen(point); double x = pointScreen.X; double y = pointScreen.Y; WinPoint pointScreenMin = new WinPoint(x - halfSize, y - halfSize); WinPoint pointScreenMax = new WinPoint(x + halfSize, y + halfSize); var pointMapMin = activeView.ScreenToMap(pointScreenMin); var pointMapMax = activeView.ScreenToMap(pointScreenMax); Envelope envelope = EnvelopeBuilder.CreateEnvelope(pointMapMin, pointMapMax, pointSpatialReference); var features = activeView.GetFeatures(envelope); GlobeSpotter globeSpotter = GlobeSpotter.Current; CycloMediaGroupLayer groupLayer = globeSpotter?.CycloMediaGroupLayer; if (features != null && groupLayer != null) { _nearest = Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl); if (_nearest) { Settings settings = Settings.Instance; MySpatialReference cycloCoordSystem = settings.CycloramaViewerCoordinateSystem; if (cycloCoordSystem != null) { SpatialReference cycloSpatialReference = cycloCoordSystem.ArcGisSpatialReference ?? cycloCoordSystem.CreateArcGisSpatialReferenceAsync().Result; if (pointSpatialReference.Wkid != cycloSpatialReference.Wkid) { ProjectionTransformation projection = ProjectionTransformation.Create(pointSpatialReference, cycloSpatialReference); point = GeometryEngine.Instance.ProjectEx(point, projection) as MapPoint; } if (point != null) { CultureInfo ci = CultureInfo.InvariantCulture; _location = string.Format(ci, "{0},{1}", point.X, point.Y); if (!globeSpotter.InsideScale()) { double minimumScale = ConstantsRecordingLayer.Instance.MinimumScale; double scale = minimumScale / 2; Camera camera = new Camera(point.X, point.Y, scale, 0.0); MapView.Active?.ZoomTo(camera); } } } } else { foreach (var feature in features) { Layer layer = feature.Key; CycloMediaLayer cycloMediaLayer = groupLayer.GetLayer(layer); if (cycloMediaLayer != null) { foreach (long uid in feature.Value) { Recording recording = cycloMediaLayer.GetRecordingAsync(uid).Result; if (recording.IsAuthorized == null || (bool)recording.IsAuthorized) { _location = recording.ImageId; } } } } } } } return true; })); }
private async Task RedrawConeAsync() { await QueuedTask.Run(() => { GlobeSpotter globeSpotter = GlobeSpotter.Current; if ((globeSpotter.InsideScale()) && (!_mapPoint.IsEmpty) && (Color != null)) { var thisColor = (SystCol)Color; MapView thisView = MapView.Active; Map map = thisView.Map; SpatialReference mapSpat = map.SpatialReference; SpatialReference mapPointSpat = _mapPoint.SpatialReference; ProjectionTransformation projection = ProjectionTransformation.Create(mapPointSpat, mapSpat); _mapPoint = GeometryEngine.Instance.ProjectEx(_mapPoint, projection) as MapPoint; WinPoint point = thisView.MapToScreen(_mapPoint); double angleh = (_hFov *Math.PI) / 360; double angle = (((270 + _angle) % 360) * Math.PI) / 180; double angle1 = angle - angleh; double angle2 = angle + angleh; double x = point.X; double y = point.Y; double size = Size / 2; WinPoint screenPoint1 = new WinPoint((x + (size * Math.Cos(angle1))), (y + (size * Math.Sin(angle1)))); WinPoint screenPoint2 = new WinPoint((x + (size * Math.Cos(angle2))), (y + (size * Math.Sin(angle2)))); MapPoint point1 = thisView.ScreenToMap(screenPoint1); MapPoint point2 = thisView.ScreenToMap(screenPoint2); IList <MapPoint> polygonPointList = new List <MapPoint>(); polygonPointList.Add(_mapPoint); polygonPointList.Add(point1); polygonPointList.Add(point2); polygonPointList.Add(_mapPoint); Polygon polygon = PolygonBuilder.CreatePolygon(polygonPointList); Color colorPolygon = SystCol.FromArgb(_blinking ? BlinkAlpha : NormalAlpha, thisColor); CIMColor cimColorPolygon = ColorFactory.Instance.CreateColor(colorPolygon); CIMPolygonSymbol polygonSymbol = SymbolFactory.Instance.DefaultPolygonSymbol; polygonSymbol.SetColor(cimColorPolygon); polygonSymbol.SetOutlineColor(null); CIMSymbolReference polygonSymbolReference = polygonSymbol.MakeSymbolReference(); IDisposable disposePolygon = thisView.AddOverlay(polygon, polygonSymbolReference); IList <MapPoint> linePointList = new List <MapPoint>(); linePointList.Add(point1); linePointList.Add(_mapPoint); linePointList.Add(point2); Polyline polyline = PolylineBuilder.CreatePolyline(linePointList); Color colorLine = _active ? SystCol.Yellow : SystCol.Gray; CIMColor cimColorLine = ColorFactory.Instance.CreateColor(colorLine); CIMLineSymbol cimLineSymbol = SymbolFactory.Instance.DefaultLineSymbol; cimLineSymbol.SetColor(cimColorLine); cimLineSymbol.SetSize(_blinking ? BorderSizeBlinking : BorderSize); CIMSymbolReference lineSymbolReference = cimLineSymbol.MakeSymbolReference(); IDisposable disposePolyLine = thisView.AddOverlay(polyline, lineSymbolReference); _disposePolygon?.Dispose(); _disposePolygon = disposePolygon; _disposePolyLine?.Dispose(); _disposePolyLine = disposePolyLine; if (_blinking) { var blinkEvent = new AutoResetEvent(true); var blinkTimerCallBack = new TimerCallback(ResetBlinking); _blinkTimer = new Timer(blinkTimerCallBack, blinkEvent, BlinkTime, -1); } } else { _disposePolygon?.Dispose(); _disposePolyLine?.Dispose(); } }); }