internal void AddMapOverlay(ResourceActivationContext context, MapOverlay overlay) { if (overlay.CenterLocation != null) { var ann = new Overlay(overlay); m_overlays.Add(context.InstanceId, ann); MapView.AddOverlay(ann); } }
public async Task RedrawObservationAsync() { await QueuedTask.Run(() => { _disposeInnerLine?.Dispose(); _disposeOuterLine?.Dispose(); if (_measurementPoint?.IsObservationVisible() ?? false) { MapView thisView = MapView.Active; MapPoint measPoint = _measurementPoint?.Point; MapPoint mapPointObsLine; if ((measPoint != null) && (!double.IsNaN(measPoint.X)) && (!double.IsNaN(measPoint.Y))) { Point winMeasPoint = thisView.MapToScreen(measPoint); Point winObsPoint = thisView.MapToScreen(Point); double xdir = ((winMeasPoint.X - winObsPoint.X) * 3) / 2; double ydir = ((winMeasPoint.Y - winObsPoint.Y) * 3) / 2; Point winPointObsLine = new Point(winObsPoint.X + xdir, winObsPoint.Y + ydir); mapPointObsLine = thisView.ScreenToMap(winPointObsLine); } else { mapPointObsLine = MapPointBuilder.CreateMapPoint((Point.X + (XDir * DistLine)), (Point.Y + (YDir * DistLine))); } IList <MapPoint> linePointList = new List <MapPoint>(); linePointList.Add(mapPointObsLine); linePointList.Add(Point); Polyline polyline = PolylineBuilder.CreatePolyline(linePointList); Color outerColorLine = Viewer?.Color ?? Color.DarkGray; CIMColor cimOuterColorLine = ColorFactory.Instance.CreateColor(Color.FromArgb(255, outerColorLine)); CIMLineSymbol cimOuterLineSymbol = SymbolFactory.Instance.DefaultLineSymbol; cimOuterLineSymbol.SetColor(cimOuterColorLine); cimOuterLineSymbol.SetSize(OuterLineSize); CIMSymbolReference cimOuterLineSymbolRef = cimOuterLineSymbol.MakeSymbolReference(); _disposeOuterLine = thisView.AddOverlay(polyline, cimOuterLineSymbolRef); Color innerColorLine = Color.LightGray; CIMColor cimInnerColorLine = ColorFactory.Instance.CreateColor(innerColorLine); CIMLineSymbol cimInnerLineSymbol = SymbolFactory.Instance.DefaultLineSymbol; cimInnerLineSymbol.SetColor(cimInnerColorLine); cimInnerLineSymbol.SetSize(InnerLineSize); CIMSymbolReference cimInnerLineSymbolRef = cimInnerLineSymbol.MakeSymbolReference(); _disposeInnerLine = thisView.AddOverlay(polyline, cimInnerLineSymbolRef); } }); }
public async Task <bool> Redraw(MapView mapView, IPointSymbology symbology, CancellationToken ctsToken) { if (_elements.Count <= 0) { return(false); } await QueuedTask.Run(() => { InitSymbology(symbology); var spatialRef = SpatialReferences.WGS84; // TODO: this should be coming from response foreach (var element in _elements) { if (ctsToken.IsCancellationRequested) { return; } element.Overlay.Dispose(); element.Overlay = mapView.AddOverlay(element.Location, _symbolRef); element.Hitbox = CreateHitBox(mapView, element.Location, symbology.Size / 2, spatialRef); } }); return(true); }
public async Task <bool> ApplyResults(MapView mapView, SearchResults results, IPointSymbology symbology, CancellationToken ctsToken) { Clear(); if (ctsToken.IsCancellationRequested) { return(false); } await QueuedTask.Run(() => { InitSymbology(symbology); var spatialRef = SpatialReferences.WGS84; // TODO: this should be coming from response foreach (var point in results.GetValuePoints(ValueName)) { if (ctsToken.IsCancellationRequested) { return; } var location = MapPointBuilder.CreateMapPoint(point.Longitude, point.Latitude, spatialRef); var overlay = mapView.AddOverlay(location, _symbolRef); _elements.Add(new Element() { Value = point, Location = location, Overlay = overlay, Hitbox = CreateHitBox(mapView, location, symbology.Size / 2, spatialRef) }); } }); return(_elements.Count > 0); }
private void UpdateAnnotation() { IMKOverlay[] overlays = MapView.Overlays; if (overlays != null) { MapView.RemoveOverlays(MapView.Overlays); } IMKAnnotation[] mKAnnotation = MapView.Annotations; if (mKAnnotation != null) { MapView.RemoveAnnotations(mKAnnotation); } //Access database, will create table if needed DatabaseManagement.BuildAllTables(); Data[] traces = DatabaseManagement.GetAllTraces(); //Add Overlay to map foreach (var i in traces) { MapView.AddOverlay(MKPolyline.FromCoordinates(i.locs.ToArray())); } annotationData[] annotations = DatabaseManagement.GetAllAnnotations(); //Add Overlay to map foreach (var j in annotations) { MapView.AddAnnotations(new TraceAnnotation(j)); } }
private Tuple <IDisposable, IDisposable, Envelope> AddOverlay(MapView mapView, MapPoint location, ValuePointCluster value, SpatialReference spatialRef) { var text = value.Count.ToString(); var textGraphic = new CIMTextGraphic() { Text = text, Symbol = _textSymbolRef, Shape = location }; var baseSize = _pointSize * 2; // smallest size (slightly bigger than for single points) var multiplier = 1 + ((text.Length - 1) * 0.5); // increase size by 0.5 for every text digit var size = baseSize * multiplier; _pointSymbol.SetSize(size); var pointElem = mapView.AddOverlay(location, _pointSymbol.MakeSymbolReference()); var textElem = mapView.AddOverlay(textGraphic); var hitbox = CreateHitBox(mapView, location, size / 2, spatialRef); return(new Tuple <IDisposable, IDisposable, Envelope>(pointElem, textElem, hitbox)); }
async void ShowPath() { var inputController = new InputDataController(); var data = await inputController.GetListAsync(_jsonResult); var locations = new List <CLLocationCoordinate2D>(); foreach (var item in data) { locations.Add(new CLLocationCoordinate2D() { Latitude = item.Latitude, Longitude = item.Longitude }); } MapView.RemoveAnnotations(MapView.Annotations); if (locations.Count > 0) { var polyline = MKPolyline.FromCoordinates(locations.ToArray()); MapView.AddOverlay(polyline); var startLocation = new CLLocation(locations[0].Latitude, locations[0].Longitude); var endLocation = new CLLocation(locations.Last().Latitude, locations.Last().Longitude); var distance = startLocation.DistanceFrom(endLocation); var region = MKCoordinateRegion.FromDistance(locations[(locations.Count / 2)], distance + 10000, distance + 10000); MapView.SetRegion(region, animated: false); var annoStart = new FlightAnnotation(title: "Starting point", subtitle: "", coordinate: locations[0]); MapView.AddAnnotation(annoStart); var annoEnd = new FlightAnnotation(title: "End point", subtitle: "", coordinate: locations.Last()); annoEnd.TintColor = UIColor.Purple; MapView.AddAnnotation(annoEnd); } }
/// <summary> /// Add a point to the specified mapview /// </summary> /// <param name="point">The location of the graphic</param> /// <param name="mapView">The mapview to whose overlay the graphic will be added</param> /// <returns></returns> public static async void AddToMapOverlay(ArcGIS.Core.Geometry.MapPoint point, MapView mapView) { ArcGIS.Core.CIM.CIMPointSymbol symbol = null; await QueuedTask.Run(() => { // Construct point symbol symbol = SymbolFactory.ConstructPointSymbol(ColorFactory.Red, 10.0, SimpleMarkerStyle.Star); }); //Get symbol reference from the symbol CIMSymbolReference symbolReference = symbol.MakeSymbolReference(); await QueuedTask.Run(() => { _overlayObject = mapView.AddOverlay(point, symbolReference); }); }
public override void Refresh(ChallengeResponseModel challengeResponce) { base.Refresh(challengeResponce); if (challengeResponce == null) { return; } Challenge = challengeResponce.Challenge; HeaderLbl.Text = Challenge.Name; //MainTextLable.Text = Challenge.Desc; TimeDisLbl.Text = Challenge.NextEventCountDown; var navigationDelegate = new ChallengeDetailWebViewNavigationDelegate(); navigationDelegate.NavigationFinished += SetupConstraint; this.WebView.NavigationDelegate = navigationDelegate; WebView.LoadHtmlString(Challenge.Desc, null); if (!DidSetupMap && Challenge.LocationLat != null && Challenge.LocationLong != null) { double radius = Challenge.RadiusMeters ?? 100.0; if (radius > 6000000) { radius = 6000000; } double mapRegion = radius * 2.5; CLLocationCoordinate2D mapCoordinate = new CLLocationCoordinate2D(Challenge.LocationLat.Value, Challenge.LocationLong.Value); MapView.SetRegion(MKCoordinateRegion.FromDistance(mapCoordinate, mapRegion, mapRegion), true); MKCircle circle = MKCircle.Circle(mapCoordinate, radius); MapView.AddOverlay(circle); MKPointAnnotation annotation = new MKPointAnnotation(); annotation.Coordinate = new CLLocationCoordinate2D(Challenge.LocationLat.Value, Challenge.LocationLong.Value); MapView.AddAnnotation(annotation); DidSetupMap = true; } }
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 Task <bool> Select(MapView mapView, Envelope box) { if (mapView == null) { return(Task.FromResult(false)); } _overlay?.Dispose(); if (box == null) { return(Task.FromResult(false)); } ; return(QueuedTask.Run(() => { var boxColor = ColorFactory.Instance.CreateRGBColor(Color.R, Color.G, Color.B); var polygon = PolygonBuilder.CreatePolygon(box); var symbol = SymbolFactory.Instance.ConstructPolygonSymbol(boxColor, SimpleFillStyle.Null, SymbolFactory.Instance.ConstructStroke(boxColor, LineWidth, SimpleLineStyle.Solid)); _overlay = mapView.AddOverlay(polygon, symbol.MakeSymbolReference()); return true; })); }
internal async Task PerformAnalysis(MapPoint ptStartLoc, MapView mapView, ProgressorSource ps) { ps.Progressor.Message = "Running the analysis..."; ps.Progressor.Status = "Gathering and verifying parameter data"; string sReqUrl = Properties.Settings.Default.QryPointToState; string sReq = String.Format("{0}?returnGeometry=false&returnDistinctValues=false&geometry={1}&geometryType=esriGeometryPoint&f=json&outFields=*&spatialRel=esriSpatialRelIntersects", sReqUrl, ptStartLoc.ToJson()); // Find out what state the user clicked; or report an error if outside the U.S. HttpWebRequest req = (HttpWebRequest)WebRequest.Create(sReq); string sResp; try { using (StreamReader sread = new StreamReader(req.GetResponse().GetResponseStream())) sResp = sread.ReadToEnd(); } catch (Exception e) { ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Error mapping the chosen spot to a petroleum area district in the U.S.A.: " + e.Message); return; } dynamic respPADDState = JsonConvert.DeserializeObject(sResp); try { string sState = respPADDState.features[0].attributes.STATE.ToString(); // Find out what PADD zone the state is in SelectedPADDZone = PaddStateToZone[sState]; } catch (Exception e) { System.Diagnostics.Debug.WriteLine("Exception getting PADD for chosen spot: " + e.Message); ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Please choose a spot within the U.S.A."); return /*null*/; } // Find out the gallons/$1.00 in that PADD zone double nFuelCost = PADDZoneToFuelCost[SelectedPADDZone]; // Find out the miles per dollar each vehicle: (mi / gal) / (dollars / gal) // Map is in meters, so convert miles to meters Vehicle[] orderedVehicles = SelectedVehicles.OrderBy(vehicle => vehicle.Mpg).ToArray <Vehicle>(); IEnumerable <double> vehicleMetersPerDollar = orderedVehicles.Select(vehicle => (vehicle.MetersPerGallon) / nFuelCost); string sDistsParam = String.Join(" ", vehicleMetersPerDollar.ToArray()); MapPoint ptStartLocNoZ = await QueuedTask.Run(() => { MapPoint ptNoZ = MapPointBuilder.CreateMapPoint(ptStartLoc.X, ptStartLoc.Y, ptStartLoc.SpatialReference); return(ptNoZ); }); // No corresponding type for the needed GPFeatureRecordSetLayer parameter string sStartGeom = ptStartLocNoZ.ToJson(); string sStartLocParam = "{\"geometryType\":\"esriGeometryPoint\",\"features\":[{\"geometry\":" + sStartGeom + "}]}"; // Run the query ps.Progressor.Status = "Executing the analysis"; string sGPUrl = Properties.Settings.Default.GPFindSA; sGPUrl += String.Format("?Distances={0}&Start_Location={1}&f=json", sDistsParam, sStartLocParam); HttpWebRequest reqSA = (HttpWebRequest)WebRequest.Create(sGPUrl); HttpWebResponse wr; try { wr = (HttpWebResponse)reqSA.GetResponse(); if (wr.StatusCode != HttpStatusCode.OK) { ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Error running analysis: " + wr.StatusDescription); return; } } catch (WebException e) { ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Error running analysis: " + e.Message); return; } // Show the results ps.Progressor.Status = "Processing the results"; using (StreamReader sread = new StreamReader(wr.GetResponseStream())) sResp = sread.ReadToEnd(); JObject respAnalysis = JObject.Parse(sResp); JArray feats = respAnalysis["results"][0]["value"]["features"] as JArray; // Rectify results and order so that largest polygon can be added to the map first List <JToken> aryResFeats = RectifyResults(feats, orderedVehicles); int iSR = respAnalysis["results"][0]["value"]["spatialReference"]["wkid"].ToObject <Int32>(); SpatialReference sr = await QueuedTask.Run <SpatialReference>(() => { SpatialReference srTemp = SpatialReferenceBuilder.CreateSpatialReference(iSR); return(srTemp); }); /*lock (_lockResults)*/ Results.ClearResults(); // Iterate backwards to add larger polygons behind smaller ones for (int iVeh = orderedVehicles.Count() - 1; iVeh >= 0; iVeh--) { Result result = new Result(orderedVehicles[iVeh]); Polygon poly = null; IDisposable graphic = null; // Compute color for this result float multiplier = aryResFeats.Count > 1 ? ((float)iVeh) / ((float)(aryResFeats.Count - 1)) : 0; byte red = (byte)(255 - (255 * multiplier)); byte green = (byte)(255 * multiplier); Color color = Color.FromRgb(red, green, 0); result.Color = color.ToString(); result.PaddZone = SelectedPADDZone; result.DollarsPerGallon = nFuelCost; string sGeom = aryResFeats[iVeh]["geometry"].ToString(); poly = await QueuedTask.Run(() => { Polygon polyNoSR = PolygonBuilder.FromJson(sGeom); return(PolygonBuilder.CreatePolygon(polyNoSR, sr)); }); CIMStroke outline = SymbolFactory.ConstructStroke(ColorFactory.BlackRGB, 1.0, SimpleLineStyle.Solid); CIMPolygonSymbol symPoly = SymbolFactory.ConstructPolygonSymbol( ColorFactory.CreateRGBColor(color.R, color.G, color.B, RESULT_OPACITY_PCT), SimpleFillStyle.Solid, outline); CIMSymbolReference sym = symPoly.MakeSymbolReference(); CIMSymbolReference symDef = SymbolFactory.DefaultPolygonSymbol.MakeSymbolReference(); graphic = await QueuedTask.Run(() => { return(mapView.AddOverlay(poly, sym)); }); result.DriveServiceArea = poly; result.DriveServiceAreaGraphic = graphic; result.DriveDistM = aryResFeats[iVeh]["attributes"]["ToBreak"].Value <double>(); /*lock (_lockResults)*/ Results.Add(result); } }
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(); } }); }
public async Task RedrawPointAsync() { await QueuedTask.Run(() => { GlobeSpotter globeSpotter = GlobeSpotter.Current; MeasurementList measurementList = globeSpotter.MeasurementList; _disposeText?.Dispose(); if ((globeSpotter.InsideScale() && (!_isDisposed) && (Point != null) && ((Measurement?.IsOpen ?? false) || ((Measurement?.IsPointMeasurement ?? false) && (measurementList.Sketch == null))) && (Measurement?.DrawPoint ?? false) && (!double.IsNaN(Point.X)) && (!double.IsNaN(Point.Y)))) { MapView thisView = MapView.Active; Point winPoint = thisView.MapToScreen(Point); float fontSize = _constants.MeasurementFontSize; int fontSizeT = (int)(fontSize * 2); int fontSizeR = (int)((fontSize * 3) / 2); int fontSizeK = (int)(fontSize / 4); int txt = (Measurement?.IsOpen ?? true) ? Index : measurementList.GetMeasurementNumber(Measurement); string text = txt.ToString(_ci); int characters = text.Length; Bitmap bitmap = new Bitmap((fontSizeT *characters), fontSizeT); double pointSize = _constants.MeasurementPointSize; double pointSizePoint = (pointSize * 6) / 4; Point winPointText = new Point { X = (winPoint.X + pointSizePoint), Y = (winPoint.Y - pointSizePoint) }; MapPoint pointText = thisView.ScreenToMap(winPointText); using (var sf = new StringFormat()) { using (Graphics g = Graphics.FromImage(bitmap)) { g.Clear(Color.Transparent); Font font = new Font("Arial", fontSize); sf.Alignment = StringAlignment.Center; Rectangle rectangle = new Rectangle(fontSizeK, fontSizeK, (fontSizeR *characters), fontSizeR); g.DrawString(text, font, Brushes.Black, rectangle, sf); } } BitmapSource source = bitmap.ToBitmapSource(); var frame = BitmapFrame.Create(source); var encoder = new PngBitmapEncoder(); encoder.Frames.Add(frame); using (MemoryStream stream = new MemoryStream()) { encoder.Save(stream); byte[] imageBytes = stream.ToArray(); string base64String = Convert.ToBase64String(imageBytes); string url = $"data:image/bmp;base64,{base64String}"; CIMPictureMarker marker = new CIMPictureMarker { URL = url, Enable = true, ScaleX = 1, Size = fontSizeR }; CIMPointSymbol symbol = SymbolFactory.Instance.ConstructPointSymbol(marker); CIMSymbolReference symbolReference = symbol.MakeSymbolReference(); _disposeText = thisView.AddOverlay(pointText, symbolReference); } } }); }