private new void AddPoi(PoI p) { try { p.UpdateAnalysisStyle(); if (string.IsNullOrEmpty(p.Layer) && p.PoiType != null) p.Layer = p.PoiType.Layer; var l = FindPoiLayer(p); if (!string.IsNullOrEmpty(p.PoiTypeId) && p.PoiType == null) p.PoiType = Service.PoITypes.FirstOrDefault(k => (k).ContentId == p.PoiTypeId) as PoI; if (p.PoiType == null) { p.PoiType = new PoI { StrokeColor = Colors.White, Service = service, StrokeWidth = 2, DrawingMode = DrawingModes.Polygon }; } if (p.Data == null) p.Data = new Dictionary<string, object>(); p.Data["layer"] = this; var g = new StaticGraphic { Service = Service, Poi = p }; if (p.DrawingMode == DrawingModes.MultiPolygon) { var converted = p.WktText.ConvertFromWkt(); if (converted is MultiPolygon) { // NOTE Others have not been implemented, such as MultiPoint or Path var mp = converted as MultiPolygon; var gs = new List<StaticGraphic>(); foreach (var poly in mp.Polygons) { g = new StaticGraphic {Service = Service, Poi = p}; ConvertPolygonToGraphic(poly, g); g.Layer = this; g.Poi = p; g.Symbol = new SimpleFillSymbol { BorderBrush = new SolidColorBrush(p.NEffectiveStyle.StrokeColor.Value), BorderThickness = p.NEffectiveStyle.StrokeWidth.Value, Fill = new SolidColorBrush(p.NEffectiveStyle.FillColor.Value) { Opacity = p.NEffectiveStyle.FillOpacity.Value } }; l.Graphics.Add(g); gs.Add(g); } p.Data["graphics"] = gs; } else if (converted is MultiLineString) { var ml = converted as MultiLineString; var gs = new List<StaticGraphic>(); foreach (var line in ml.Lines) { g = new StaticGraphic { Service = Service, Poi = p }; ConvertPolylineToGraphic(line, g); g.Layer = this; g.Poi = p; g.Symbol = new SimpleFillSymbol { BorderBrush = new SolidColorBrush(p.NEffectiveStyle.StrokeColor.Value), BorderThickness = p.NEffectiveStyle.StrokeWidth.Value, Fill = new SolidColorBrush(p.NEffectiveStyle.FillColor.Value) { Opacity = p.NEffectiveStyle.FillOpacity.Value } }; l.Graphics.Add(g); gs.Add(g); } p.Data["graphics"] = gs; } } else { g = new StaticGraphic { Service = Service, Poi = p }; g.SetZIndex(p.ZIndex); GetGraphic(p, ref g); l.Graphics.Add(g); p.Data["graphic"] = g; } p.PositionChanged += p_PositionChanged; var height = p.NEffectiveStyle.IconHeight == null ? 32 : p.NEffectiveStyle.IconHeight.Value; var width = p.NEffectiveStyle.IconWidth == null ? 32 : p.NEffectiveStyle.IconWidth.Value; if (p.NEffectiveStyle.DrawingMode.Value == DrawingModes.Point) { if (!string.IsNullOrEmpty(p.NEffectiveStyle.Icon)) { //var ig = new StaticGraphic {Poi = p, Geometry = g.Geometry, Service = Service}; var ig = new Graphic { Geometry = g.Geometry }; if (p.NEffectiveStyle.IconUri.OriginalString.StartsWith("http", StringComparison.InvariantCultureIgnoreCase)) { p.NEffectiveStyle.Picture = new BitmapImage(p.NEffectiveStyle.IconUri); } else { var s = Service.MediaFolder + p.NEffectiveStyle.Icon; ig.Attributes["staticgraphic"] = g; if (service.store.HasFile(s)) { p.NEffectiveStyle.Picture = new BitmapImage(new Uri(s)); } } // When image not found display not_found image (so poi is visible on map) /* if (p.NEffectiveStyle.Picture == null) { p.NEffectiveStyle.Picture = LoadImageFromResource("csCommon.Resources.Icons.ImageNotFound.png"); } */ //Fix by Jeroen: Invalid bitmap, don't add if (p.NEffectiveStyle.Picture == null) return; var sym = new PictureMarkerSymbol { Source = p.NEffectiveStyle.Picture, Width = width, Height = height, OffsetX = width / 2, OffsetY = height / 2, }; if (p.Position != null ) sym.Angle = p.Position.Course; ig.Symbol = sym; l.Graphics.Add(ig); ig.MouseLeftButtonDown += (e, st) => g.PoiGraphic_MouseLeftButtonDown(e, st); ig.MouseLeftButtonUp += (e, st) => g.PoiGraphic_MouseLeftButtonUp(e, st); g.ImageGraphic = ig; } } if (p.NEffectiveStyle.TitleMode.HasValue && p.NEffectiveStyle.TitleMode.Value != TitleModes.None) { var sym = new TextSymbol { Text = p.Labels.ContainsKey(p.NEffectiveStyle.NameLabel) ? p.Labels[p.NEffectiveStyle.NameLabel] : string.Empty, FontSize = 12, Foreground = Brushes.Black, //OffsetX = -p.Name.Length * 24, OffsetY = height / -2 }; var tg = new Graphic { Geometry = g.BaseGeometry, Symbol = sym }; tg.Attributes["staticgraphic"] = g; l.Graphics.Add(tg); g.LabelGraphic = tg; } if (!string.IsNullOrEmpty(p.InnerText)) { var sym = new TextSymbol { Text = p.InnerText, FontSize = 16, Foreground = new SolidColorBrush(p.NEffectiveStyle.InnerTextColor.Value), OffsetX = (p.InnerText.Length * 5.0), OffsetY = 8, FontWeight = FontWeights.ExtraBold }; if (p.DrawingMode == DrawingModes.Line || p.DrawingMode == DrawingModes.Polyline) { var p0 = p.Points[0]; var p1 = p.Points[1]; var xdelta = (p1.X - p0.X); var ydelta = (p1.Y - p0.Y); const double rad2Deg = 180.0 / Math.PI; var angle = rad2Deg * Math.Atan2(xdelta, ydelta); sym.OffsetX -= 10 * Math.Cos(angle / rad2Deg); sym.OffsetY -= 10 * Math.Sin(angle / rad2Deg); //angle = (angle + 360.0)%360.0; ////Item is either N or S //if ((angle < 20 || angle > 340) || (angle > 160 && angle < 200)) // sym.OffsetY += 10; ////Item is either NW or SW or NE or SE //else if ((angle > 20 && angle < 70) || (angle > 200 && angle < 250)) //{ // sym.OffsetX += 10; // sym.OffsetY += 10; //} ////Item is either W or E //else if ((angle > 70 && angle < 110) || (angle > 250 && angle < 290)) // sym.OffsetX += 10; ////Item is either NW or SW or NE or SE //else if ((angle > 110 && angle < 160) || (angle > 290 && angle < 340)) //{ // sym.OffsetX += 10; // sym.OffsetY += 10; //} //// else glabel = "dunno!"; } var tg = new Graphic { Geometry = g.BaseGeometry, Symbol = sym }; tg.MouseLeftButtonDown += (e, st) => g.PoiGraphic_MouseLeftButtonDown(e, st); l.Graphics.Add(tg); g.InnerTextGraphic = tg; } g.UpdateScale(); base.AddPoi(p); //p.UpdateAnalysisStyle(); } catch (Exception e) { LogCs.LogException("dsStaticLayer.AddPoi: Exception adding poi icon on map (causes strange behaviour of poi icon (missing eventhandler etc.)) ", e); Logger.Log("dsStaticLayer.AddPoi", "Error adding graphic", e.Message, Logger.Level.Error); } }
/// <summary> /// Add new poi /// </summary> /// <param name="p"></param> public new void AddPoi(PoI p) { if (p == null) return; var poiLayer = FindPoiLayer(p); //AddLabels(p); p.UpdateAnalysisStyle(); poiLayer.AddPoi(p); // check models p.FindModels(); base.AddPoi(p); }