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 string CheckCycloramaSpatialReference() { Settings settings = Settings.Instance; MySpatialReference spatialReference = settings.CycloramaViewerCoordinateSystem; return(CheckCycloramaSpatialReference(spatialReference)); }
protected async Task InitializeAsync(RecordingLocation location, double angle, double hFov, Color color) { _angle = angle; _hFov = hFov; Color = color; _isInitialized = true; double x = location.X; double y = location.Y; Settings settings = Settings.Instance; MySpatialReference spatRel = settings.CycloramaViewerCoordinateSystem; await QueuedTask.Run(() => { Map map = MapView.Active?.Map; SpatialReference mapSpatialReference = map?.SpatialReference; SpatialReference spatialReference = spatRel?.ArcGisSpatialReference ?? mapSpatialReference; MapPoint point = MapPointBuilder.CreateMapPoint(x, y, spatialReference); 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(); } }); MapViewCameraChangedEvent.Subscribe(OnMapViewCameraChanged); await RedrawConeAsync(); }
private async Task OpenImageAsync(bool replace) { if (_api != null) { string location = ((dynamic)DataContext).Location; bool nearest = ((dynamic)DataContext).Nearest; _api.SetActiveViewerReplaceMode(replace); if (nearest) { MySpatialReference spatialReference = _settings.CycloramaViewerCoordinateSystem; SpatialReference thisSpatialReference = spatialReference.ArcGisSpatialReference ?? await spatialReference.CreateArcGisSpatialReferenceAsync(); if ((_lastSpatialReference != null) && (thisSpatialReference.Wkid != _lastSpatialReference.Wkid)) { string[] splitLoc = location.Split(','); CultureInfo ci = CultureInfo.InvariantCulture; double x = double.Parse(splitLoc.Length >= 1 ? splitLoc[0] : "0.0", ci); double y = double.Parse(splitLoc.Length >= 2 ? splitLoc[1] : "0.0", ci); MapPoint point = null; await QueuedTask.Run(() => { point = MapPointBuilder.CreateMapPoint(x, y, _lastSpatialReference); ProjectionTransformation projection = ProjectionTransformation.Create(_lastSpatialReference, thisSpatialReference); point = GeometryEngine.Instance.ProjectEx(point, projection) as MapPoint; }); if (point != null) { location = string.Format(ci, "{0},{1}", point.X, point.Y); DockPaneGlobeSpotter globeSpotter = ((dynamic)DataContext); globeSpotter.PropertyChanged -= OnGlobeSpotterPropertyChanged; ((dynamic)DataContext).Location = location; globeSpotter.PropertyChanged += OnGlobeSpotterPropertyChanged; } } _startOpenNearest = true; _api.OpenNearestImage(location, _settings.CtrlClickHashTag * _settings.CtrlClickDelta); } else { _api.OpenImage(location); } MySpatialReference cycloSpatialReference = _settings.CycloramaViewerCoordinateSystem; _lastSpatialReference = cycloSpatialReference.ArcGisSpatialReference ?? await cycloSpatialReference.CreateArcGisSpatialReferenceAsync(); } }
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); }
private void AddVectorLayer(VectorLayer vectorLayer) { int minZoomLevel = _constants.MinVectorLayerZoomLevel; MySpatialReference cyclSpatRel = _settings.CycloramaViewerCoordinateSystem; string srsName = cyclSpatRel.SRSName; string layerName = vectorLayer.Name; string gml = vectorLayer.Gml; Color color = vectorLayer.Color; uint?layerId = _api?.AddGMLLayer(layerName, gml, srsName, color, true, false, minZoomLevel); vectorLayer.LayerId = layerId; }
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); }
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; } }); }
public async Task UpdateMeasurementPointsAsync(Geometry geometry) { if ((geometry != null) && (!_updateMeasurement)) { _updateMeasurement = true; List <MapPoint> ptColl = await ToPointCollectionAsync(geometry); if (ptColl != null) { int msPoints = Count; var toRemove = new Dictionary <MeasurementPoint, bool>(); var toAdd = new List <MapPoint>(); bool toRemoveFrom = false; for (int i = 0; i < msPoints; i++) { MeasurementPoint measurementPoint = GetPointByNr(i); if ((measurementPoint != null) && (((!measurementPoint.NotCreated) && (!IsPointMeasurement)) || (IsPointMeasurement && (PointNr >= 1)))) { toRemove.Add(measurementPoint, true); } } for (int j = 0; j < PointNr; j++) { MapPoint point = ptColl[j]; var measurementPoint = GetPoint(point); if (measurementPoint == null) { toAdd.Add(point); toRemoveFrom = true; } else { if (!toRemoveFrom) { if (toRemove.ContainsKey(measurementPoint)) { toRemove[measurementPoint] = false; } } else { toAdd.Add(point); } } } if (toRemove.Aggregate(false, (current, remove) => remove.Value || current) || (toAdd.Count >= 1)) { if (!IsPointMeasurement) { DisableMeasurementSeries(); } foreach (var elem in toRemove) { if (elem.Value && GlobeSpotterConfiguration.MeasurePermissions) { MeasurementPoint msPoint = elem.Key; int pointId = msPoint.PointId; _api?.RemoveMeasurementPoint(EntityId, pointId); } } foreach (var point in toAdd) { MapView mapView = MapView.Active; Map map = mapView?.Map; SpatialReference mapSpatRef = map?.SpatialReference; MySpatialReference myCyclSpatRef = _settings.CycloramaViewerCoordinateSystem; SpatialReference cyclSpatRef = (myCyclSpatRef == null) ? mapSpatRef : (myCyclSpatRef.ArcGisSpatialReference ?? (await myCyclSpatRef.CreateArcGisSpatialReferenceAsync())); SpatialReference layerSpatRef = point.SpatialReference ?? cyclSpatRef; MapPoint copyGsPoint = null; await QueuedTask.Run(() => { ProjectionTransformation projection = ProjectionTransformation.Create(layerSpatRef, cyclSpatRef); copyGsPoint = GeometryEngine.Instance.ProjectEx(point, projection) as MapPoint; }); CreateMeasurementPoint(copyGsPoint); } if (!IsPointMeasurement) { EnableMeasurementSeries(); } } } _updateMeasurement = false; } }
public async Task <string> GenerateGmlAsync() { MapView mapView = MapView.Active; Map map = mapView?.Map; SpatialReference mapSpatRef = map?.SpatialReference; MySpatialReference myCyclSpatRef = _settings.CycloramaViewerCoordinateSystem; SpatialReference cyclSpatRef = (myCyclSpatRef == null) ? mapSpatRef : (myCyclSpatRef.ArcGisSpatialReference ?? (await myCyclSpatRef.CreateArcGisSpatialReferenceAsync())); Unit unit = cyclSpatRef?.Unit; double factor = unit?.ConversionFactor ?? 1; Color color = Color.White; string result = "<wfs:FeatureCollection xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:wfs=\"http://www.opengis.net/wfs\" xmlns:gml=\"http://www.opengis.net/gml\">"; await QueuedTask.Run(async() => { SpatialReference layerSpatRef = Layer.GetSpatialReference(); IList <IList <Segment> > geometries = new List <IList <Segment> >(); ICollection <Viewer> viewers = _viewerList.Viewers; foreach (var viewer in viewers) { double distance = viewer.OverlayDrawDistance; RecordingLocation recordingLocation = viewer.Location; if (recordingLocation != null) { if (cyclSpatRef?.IsGeographic ?? true) { distance = distance * factor; } else { distance = distance / factor; } double x = recordingLocation.X; double y = recordingLocation.Y; double xMin = x - distance; double xMax = x + distance; double yMin = y - distance; double yMax = y + distance; Envelope envelope = EnvelopeBuilder.CreateEnvelope(xMin, yMin, xMax, yMax, cyclSpatRef); Envelope copyEnvelope = envelope; if (layerSpatRef.Wkid != 0) { ProjectionTransformation projection = ProjectionTransformation.Create(cyclSpatRef, layerSpatRef); copyEnvelope = GeometryEngine.Instance.ProjectEx(envelope, projection) as Envelope; } Polygon copyPolygon = PolygonBuilder.CreatePolygon(copyEnvelope, layerSpatRef); ReadOnlyPartCollection polygonParts = copyPolygon.Parts; IEnumerator <ReadOnlySegmentCollection> polygonSegments = polygonParts.GetEnumerator(); IList <Segment> segments = new List <Segment>(); while (polygonSegments.MoveNext()) { ReadOnlySegmentCollection polygonSegment = polygonSegments.Current; foreach (Segment segment in polygonSegment) { segments.Add(segment); } } geometries.Add(segments); } } GC.Collect(); Polygon polygon = PolygonBuilder.CreatePolygon(geometries, layerSpatRef); using (FeatureClass featureClass = Layer?.GetFeatureClass()) { string uri = Layer?.URI; SpatialQueryFilter spatialFilter = new SpatialQueryFilter { FilterGeometry = polygon, SpatialRelationship = SpatialRelationship.Intersects, SubFields = "*" }; using (RowCursor existsResult = featureClass?.Search(spatialFilter, false)) { while (existsResult?.MoveNext() ?? false) { Row row = existsResult.Current; long objectId = row.GetObjectID(); if ((_selection == null) || (!_selection.Contains(objectId))) { Feature feature = row as Feature; var fieldvalues = new Dictionary <string, string> { { FieldUri, uri }, { FieldObjectId, objectId.ToString() } }; Geometry geometry = feature?.GetShape(); GeometryType geometryType = geometry?.GeometryType ?? GeometryType.Unknown; Geometry copyGeometry = geometry; if ((geometry != null) && (layerSpatRef.Wkid != 0)) { ProjectionTransformation projection = ProjectionTransformation.Create(layerSpatRef, cyclSpatRef); copyGeometry = GeometryEngine.Instance.ProjectEx(geometry, projection); } if (copyGeometry != null) { string gml = string.Empty; switch (geometryType) { case GeometryType.Envelope: break; case GeometryType.Multipatch: break; case GeometryType.Multipoint: break; case GeometryType.Point: MapPoint point = copyGeometry as MapPoint; if (point != null) { gml = $"<gml:Point {GmlDimension(copyGeometry)}><gml:coordinates>{await GmlPointAsync(point)}</gml:coordinates></gml:Point>"; } break; case GeometryType.Polygon: Polygon polygonGml = copyGeometry as Polygon; if (polygonGml != null) { ReadOnlyPartCollection polygonParts = polygonGml.Parts; IEnumerator <ReadOnlySegmentCollection> polygonSegments = polygonParts.GetEnumerator(); while (polygonSegments.MoveNext()) { ReadOnlySegmentCollection segments = polygonSegments.Current; gml = $"{gml}<gml:MultiPolygon><gml:PolygonMember><gml:Polygon {GmlDimension(copyGeometry)}><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>"; for (int i = 0; i < segments.Count; i++) { if (segments[i].SegmentType == SegmentType.Line) { MapPoint polygonPoint = segments[i].StartPoint; gml = $"{gml}{((i == 0) ? string.Empty : " ")}{await GmlPointAsync(polygonPoint)}"; if (i == (segments.Count - 1)) { polygonPoint = segments[i].EndPoint; gml = $"{gml} {await GmlPointAsync(polygonPoint)}"; } } } gml = $"{gml}</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:PolygonMember></gml:MultiPolygon>"; } } break; case GeometryType.Polyline: Polyline polylineGml = copyGeometry as Polyline; if (polylineGml != null) { ReadOnlyPartCollection polylineParts = polylineGml.Parts; IEnumerator <ReadOnlySegmentCollection> polylineSegments = polylineParts.GetEnumerator(); while (polylineSegments.MoveNext()) { ReadOnlySegmentCollection segments = polylineSegments.Current; gml = $"{gml}<gml:MultiLineString><gml:LineStringMember><gml:LineString {GmlDimension(copyGeometry)}><gml:coordinates>"; for (int i = 0; i < segments.Count; i++) { if (segments[i].SegmentType == SegmentType.Line) { MapPoint linePoint = segments[i].StartPoint; gml = $"{gml}{((i == 0) ? string.Empty : " ")}{await GmlPointAsync(linePoint)}"; if (i == (segments.Count - 1)) { linePoint = segments[i].EndPoint; gml = $"{gml} {await GmlPointAsync(linePoint)}"; } } } gml = $"{gml}</gml:coordinates></gml:LineString></gml:LineStringMember></gml:MultiLineString>"; } } break; case GeometryType.Unknown: break; } string fieldValueStr = fieldvalues.Aggregate(string.Empty, (current, fieldvalue) => string.Format("{0}<{1}>{2}</{1}>", current, fieldvalue.Key, fieldvalue.Value)); result = $"{result}<gml:featureMember><xs:Geometry>{fieldValueStr}{gml}</xs:Geometry></gml:featureMember>"; } } } } } CIMRenderer renderer = Layer.GetRenderer(); CIMSimpleRenderer simpleRenderer = renderer as CIMSimpleRenderer; CIMUniqueValueRenderer uniqueValueRendererRenderer = renderer as CIMUniqueValueRenderer; CIMSymbolReference symbolRef = simpleRenderer?.Symbol ?? uniqueValueRendererRenderer?.DefaultSymbol; CIMSymbol symbol = symbolRef?.Symbol; CIMColor cimColor = symbol?.GetColor(); double[] colorValues = cimColor?.Values; int red = ((colorValues != null) && (colorValues.Length >= 1)) ? ((int)colorValues[0]) : 255; int green = ((colorValues != null) && (colorValues.Length >= 2)) ? ((int)colorValues[1]) : 255; int blue = ((colorValues != null) && (colorValues.Length >= 3)) ? ((int)colorValues[2]) : 255; int alpha = ((colorValues != null) && (colorValues.Length >= 4)) ? ((int)colorValues[3]) : 255; color = Color.FromArgb(alpha, red, green, blue); }); GmlChanged = (Color != color); Color = color; string newGml = $"{result}</wfs:FeatureCollection>"; GmlChanged = ((newGml != Gml) || GmlChanged); return(Gml = newGml); }
/* * 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; })); }