// 鹰眼 private void myMapView_ViewpointChanged(object sender, EventArgs e) { // 声明鹰眼地图的覆盖层边框 Esri.ArcGISRuntime.Geometry.Geometry eagleViewEnv = null; // 每次主地图的焦点改变, 都会清空鹰眼地图的覆盖层 myMapView_Eagle.GraphicsOverlays.Clear(); // 获取主地图的四至 Esri.ArcGISRuntime.Geometry.Polygon vExtent = myMapView.VisibleArea; // 鹰眼地图的覆盖层边框等于主地图四至 eagleViewEnv = vExtent.Extent; // 鹰眼地图的覆盖层边框为"红色" System.Drawing.Color lineColor = System.Drawing.Color.FromName("Red"); // 鹰眼地图的覆盖层边框样式 Esri.ArcGISRuntime.Symbology.SimpleLineSymbol lineSymbol = new Esri.ArcGISRuntime.Symbology.SimpleLineSymbol(Esri.ArcGISRuntime.Symbology.SimpleLineSymbolStyle.Dash, lineColor, 2.0); System.Drawing.Color fillColor = System.Drawing.Color.FromArgb(0, 255, 255, 255); Esri.ArcGISRuntime.Symbology.SimpleFillSymbol polySymbol = new Esri.ArcGISRuntime.Symbology.SimpleFillSymbol(Esri.ArcGISRuntime.Symbology.SimpleFillSymbolStyle.Solid, fillColor, lineSymbol); var graphicOverlay = new Esri.ArcGISRuntime.UI.GraphicsOverlay(); // 几何图层 var envGraphic = new Esri.ArcGISRuntime.UI.Graphic(eagleViewEnv, polySymbol); // 覆盖层 graphicOverlay.Graphics.Add(envGraphic); // 覆盖层添加到鹰眼地图 myMapView_Eagle.GraphicsOverlays.Add(graphicOverlay); }
private async void ProcessMessages(ClientWebSocket socket) { string idAttributeField = ServiceInfo.TimeInfo?.TrackIdField ?? ServiceInfo.ObjectIdField; var buff = new byte[65535]; ArraySegment <byte> buffer = new ArraySegment <byte>(buff); var sr = ServiceInfo.SpatialReference.AsSpatialReference(); var fields = new Dictionary <string, FieldInfo>(); foreach (var f in from p in ServiceInfo.Fields select new KeyValuePair <string, FieldInfo>(p.Name, p)) { fields[f.Key] = f.Value; } DateTimeOffset lastStaleCheck = DateTimeOffset.Now; int messageCount = 0; DateTimeOffset messageCountReset = DateTimeOffset.Now; while (IsConnected) { var result = await socket.ReceiveAsync(buffer, CancellationToken.None).ConfigureAwait(false); if (!IsConnected) { break; } messageCount++; using (var ms = new MemoryStream(buff, 0, result.Count)) { FeatureMessage p; try { #if __IOS__ || __ANDROID__ p = FeatureMessage.FromJson(Encoding.UTF8.GetString(buff, 0, result.Count)); #else p = FeatureMessage.FromJson(ms); #endif } catch (System.Exception) { Debug.WriteLine("Failed to parse message: " + Encoding.UTF8.GetString(buff, 0, result.Count)); continue; } if (p.Geometry == null || p.Attributes == null) { continue; } foreach (var pair in p.Attributes.ToArray()) { var type = pair.Value?.GetType(); if (type == typeof(Decimal)) { p.Attributes[pair.Key] = Convert.ToDouble(pair.Value); } if (fields.ContainsKey(pair.Key) && fields[pair.Key].Type == "esriFieldTypeDate" && pair.Value != null) { p.Attributes[pair.Key] = DateTimeOffset.FromUnixTimeMilliseconds(Convert.ToInt64(pair.Value)); } } if (p.Attributes.ContainsKey(idAttributeField)) { string id = p.Attributes[idAttributeField].ToString(); MapPoint location; if (p.Geometry.Z.HasValue) { location = new MapPoint(p.Geometry.X, p.Geometry.Y, p.Geometry.Z.Value, sr); } else { location = new MapPoint(p.Geometry.X, p.Geometry.Y, sr); } if (_vehicles.ContainsKey(id)) // update { var graphic = _vehicles[id]; foreach (var att in p.Attributes) { graphic.Attributes[att.Key] = att.Value; } if (AnimateUpdates && AnimationSpeed.TotalMilliseconds > 16) { Animations.GeometryAnimatorHelper.AnimatePointTo(graphic, location, AnimationSpeed, null); } else { graphic.Geometry = location; } OnUpdate?.Invoke(this, "Update"); } else { var graphic = new Esri.ArcGISRuntime.UI.Graphic(location, p.Attributes); _vehicles[id] = graphic; if (Overlay != null) { Overlay.Graphics.Add(graphic); } OnUpdate?.Invoke(this, "Add"); } } } DateTimeOffset now = DateTimeOffset.Now; double timeSinceCountReset = (now - messageCountReset).TotalSeconds; if (timeSinceCountReset > 10 && messageCount > 10) { MessagesPerSecond = messageCount / timeSinceCountReset; OnUpdate?.Invoke(this, "MessagesPerSecond"); messageCount = 0; messageCountReset = now; } //Check if any features has gone stale and remove them if (FeatureTimeout < TimeSpan.MaxValue) { DateTimeOffset timeoutDate = now - FeatureTimeout; if (DateTimeOffset.Now - lastStaleCheck > TimeSpan.FromSeconds(10)) { var timeField = ServiceInfo.TimeInfo?.StartTimeField; if (!string.IsNullOrEmpty(timeField)) { var outdated = (from a in _vehicles where a.Value.Attributes.ContainsKey(timeField) && ((DateTimeOffset)a.Value.Attributes[timeField]) < timeoutDate select a.Key).ToArray(); foreach (var key in outdated) { var graphic = _vehicles[key]; _vehicles.Remove(key); if (Overlay != null) { Overlay.Graphics.Remove(graphic); } } if (outdated.Length > 0) { OnUpdate?.Invoke(this, "Remove"); } } lastStaleCheck = DateTimeOffset.Now; } } } _vehicles.Clear(); Overlay.Graphics.Clear(); }