private static bool IsTouchingTakingIntoAccountSymbolStyles( Point point, IFeature feature, IStyle layerStyle, double resolution, ISymbolCache symbolCache) { if (feature.Geometry is Point) { var styles = new List <IStyle>(); if (layerStyle != null) { styles.Add(layerStyle); } styles.AddRange(feature.Styles); foreach (var style in styles) { var symbolStyle = style as SymbolStyle; if (symbolStyle == null) { Logger.Log(LogLevel.Warning, $"Feature info not supported for {style.GetType()}"); continue; //todo: add support for other types } var scale = symbolStyle.SymbolScale; var size = symbolStyle.BitmapId >= 0 ? symbolCache.GetSize(symbolStyle.BitmapId) : new Size(SymbolStyle.DefaultWidth, SymbolStyle.DefaultHeight); // Symbols allways drawn around the center (* 0.5 instead of / 2) var factor = resolution * scale; var marginX = size.Width * 0.5 * factor; var marginY = size.Height * 0.5 * factor; var box = feature.Geometry.GetBoundingBox(); box = box.Grow(marginX, marginY); if (symbolStyle.SymbolOffset.IsRelative) { box.Offset(size.Width * symbolStyle.SymbolOffset.X * factor, size.Height * symbolStyle.SymbolOffset.Y * factor); } else { box.Offset(symbolStyle.SymbolOffset.X * factor, symbolStyle.SymbolOffset.Y * factor); } if (box.Contains(point)) { return(true); } } } return(feature.Geometry.Contains(point)); }
private static bool IsTouchingTakingIntoAccountSymbolStyles(Point point, IFeature feature, IStyle layerStyle, double resolution, ISymbolCache symbolCache, int margin = 0) { var styles = new List <IStyle>(); styles.AddRange(ToCollection(layerStyle)); styles.AddRange(feature.Styles); var marginInWorldUnits = margin * resolution; if (feature.Geometry is Point) { foreach (var style in styles) { var localStyle = HandleThemeStyle(feature, style); if (localStyle is SymbolStyle symbolStyle) { var scale = symbolStyle.SymbolScale; var size = symbolStyle.BitmapId >= 0 ? symbolCache.GetSize(symbolStyle.BitmapId) : new Size(SymbolStyle.DefaultWidth, SymbolStyle.DefaultHeight); // Symbols allways drawn around the center (* 0.5 instead of / 2) var factor = resolution * scale; var marginX = size.Width * 0.5 * factor; var marginY = size.Height * 0.5 * factor; var box = feature.Geometry.BoundingBox; box = box.Grow(marginX, marginY); if (symbolStyle.SymbolOffset.IsRelative) { box.Offset( size.Width * symbolStyle.SymbolOffset.X * factor, size.Height * symbolStyle.SymbolOffset.Y * factor); } else { box.Offset(symbolStyle.SymbolOffset.X * factor, symbolStyle.SymbolOffset.Y * factor); } if (box.Distance(point) <= marginInWorldUnits) { return(true); } } else if (localStyle is VectorStyle) { var marginX = SymbolStyle.DefaultWidth * 0.5 * resolution; var marginY = SymbolStyle.DefaultHeight * 0.5 * resolution; var box = feature.Geometry.BoundingBox; box = box.Grow(marginX, marginY); if (box.Distance(point) <= marginInWorldUnits) { return(true); } } else { if (!(localStyle is LabelStyle)) // I don't intend to support label click, so don't warn { Logger.Log(LogLevel.Warning, $"Feature info not supported for points with {localStyle.GetType()}"); } } } } else if (feature.Geometry is LineString || feature.Geometry is MultiLineString) { foreach (var style in styles) { var localStyle = HandleThemeStyle(feature, style); if (localStyle is VectorStyle symbolStyle) { var lineWidthInWorldUnits = symbolStyle.Line.Width * resolution * 0.5; if (feature.Geometry.Distance(point) <= lineWidthInWorldUnits + marginInWorldUnits) { return(true); } } else { Logger.Log(LogLevel.Warning, $"Feature info not supported for lines with {localStyle.GetType()}"); } } } else { return(feature.Geometry.Distance(point) <= marginInWorldUnits); } return(false); }