public static string CheckCycloramaSpatialReference()
        {
            Settings           settings         = Settings.Instance;
            MySpatialReference spatialReference = settings.CycloramaViewerCoordinateSystem;

            return(CheckCycloramaSpatialReference(spatialReference));
        }
        private static string CheckCycloramaSpatialReference(MySpatialReference spatialReference)
        {
            Settings           settings = Settings.Instance;
            MySpatialReference recordingSpatialReference = settings.RecordingLayerCoordinateSystem;
            string             epsgCode = spatialReference == null
        ? (recordingSpatialReference == null
          ? $"EPSG:{MapView.Active?.Map?.SpatialReference.Wkid ?? 0}"
          : recordingSpatialReference.SRSName)
        : spatialReference.SRSName;

            if (spatialReference?.ArcGisSpatialReference == null)
            {
                MySpatialReferenceList spatialReferences = MySpatialReferenceList.Instance;
                spatialReference = spatialReferences.GetItem(epsgCode) ??
                                   spatialReferences.Aggregate <MySpatialReference, MySpatialReference>(null,
                                                                                                        (current, spatialReferenceComp) =>
                                                                                                        spatialReferenceComp.ArcGisSpatialReference != null ? spatialReferenceComp : current);

                if (spatialReference != null)
                {
                    epsgCode = spatialReference.SRSName;
                    settings.CycloramaViewerCoordinateSystem = spatialReference;
                    settings.Save();
                }
            }

            return(epsgCode);
        }
        public static async Task <SpatialReference> CycloramaSpatialReferenceAsync()
        {
            Settings           settings  = Settings.Instance;
            MySpatialReference gsSpatRel = settings.CycloramaViewerCoordinateSystem;

            MapView          mapView             = MapView.Active;
            Map              map                 = mapView?.Map;
            SpatialReference mapSpatialReference = map?.SpatialReference;
            SpatialReference gsSpatialReference  = (gsSpatRel == null)
        ? mapSpatialReference
        : (gsSpatRel.ArcGisSpatialReference ?? (await gsSpatRel.CreateArcGisSpatialReferenceAsync()));

            return(gsSpatialReference);
        }
        public static async Task <bool> CheckInAreaCycloramaSpatialReferenceAsync()
        {
            bool               result           = false;
            Settings           settings         = Settings.Instance;
            MySpatialReference spatialReference = settings.CycloramaViewerCoordinateSystem;

            if (spatialReference != null)
            {
                result = await spatialReference.ExistsInAreaAsync();

                if (!result)
                {
                    CheckCycloramaSpatialReference(null);
                }
            }

            return(result);
        }
Esempio n. 5
0
        public async Task UpdateAsync(double x, double y, double size)
        {
            Settings           settings = Settings.Instance;
            MySpatialReference spatRel  = settings.CycloramaViewerCoordinateSystem;

            await QueuedTask.Run(() =>
            {
                MapView thisView = MapView.Active;
                Map map          = thisView?.Map;
                SpatialReference mapSpatialReference = map?.SpatialReference;
                SpatialReference spatialReference    = spatRel?.ArcGisSpatialReference ?? mapSpatialReference;
                MapPoint point = MapPointBuilder.CreateMapPoint(x, y, spatialReference);
                MapPoint mapPoint;

                if (mapSpatialReference != null && spatialReference.Wkid != mapSpatialReference.Wkid)
                {
                    ProjectionTransformation projection = ProjectionTransformation.Create(spatialReference, mapSpatialReference);
                    mapPoint = GeometryEngine.Instance.ProjectEx(point, projection) as MapPoint;
                }
                else
                {
                    mapPoint = (MapPoint)point.Clone();
                }

                if (mapPoint != null && !mapPoint.IsEmpty)
                {
                    CIMColor cimColor          = ColorFactory.Instance.CreateColor(Color.Black);
                    CIMMarker cimMarker        = SymbolFactory.Instance.ConstructMarker(cimColor, size, SimpleMarkerStyle.Cross);
                    CIMPointSymbol pointSymbol = SymbolFactory.Instance.ConstructPointSymbol(cimMarker);
                    CIMSymbolReference pointSymbolReference = pointSymbol.MakeSymbolReference();
                    IDisposable disposeCross = thisView.AddOverlay(mapPoint, pointSymbolReference);

                    _disposeCross?.Dispose();
                    _disposeCross = disposeCross;
                }
            });
        }
/*
 *  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("StreetSmartArcGISPro_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);

                    ModuleStreetSmart streetSmart = ModuleStreetSmart.Current;
                    CycloMediaGroupLayer groupLayer = streetSmart?.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 (!streetSmart.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;
            }));
        }