public class WindStyle: TextStyle { private Dictionary m_WindImages; private ZoomLevelSet m_ZoomLevels; private List m_ZoomLevelDef; public WindStyle(Dictionary windImages, ZoomLevelSet zoomLevels, List zoomLevelDef ) : base() { m_WindImages = windImages; m_ZoomLevels = zoomLevels; m_ZoomLevelDef = zoomLevelDef; if (m_WindImages == null || m_WindImages.Count == 0) m_WindImages = CreateWindGeoImages(); } internal static Dictionary CreateWindGeoImages() { string windDirectory = Path.Combine(Singleton.Variables.ApplicationSettings.WeatherShpSplitPath, "img"); Dictionary dicImages = new Dictionary(); foreach (string file in Directory.GetFiles(windDirectory, "wind*.png")) { Bitmap b = new Bitmap(file); Bitmap scaled = new Bitmap(b, new Size((int)(b.Width * 0.6), (int)(b.Height * 0.6))); MemoryStream stream = new MemoryStream(); scaled.Save(stream, ImageFormat.Png); dicImages.AddIfNotExists(Path.GetFileNameWithoutExtension(file).ToLower(), new GeoImage(stream)); } return dicImages; } protected override Collection GetRequiredColumnNamesCore() { var results = new Collection(){"val", "spd"}; return results; } protected override Collection FilterFeaturesCore(IEnumerable features, GeoCanvas canvas) { if (m_ZoomLevelDef == null || m_ZoomLevelDef.Count < 2) { return new Collection(features.ToList()); } int currentZoomLevel = StyleUtils.GetCurrentZoomLevel(m_ZoomLevels, canvas.CurrentWorldExtent, (double)canvas.Width, canvas.MapUnit); GriddedZoomLevelDef startFromZoomLevel = null; for (int i = 0; i <= m_ZoomLevelDef.Count - 2; i++) { if (currentZoomLevel >= m_ZoomLevelDef[i].ZoomLevel && currentZoomLevel < m_ZoomLevelDef[i + 1].ZoomLevel) { startFromZoomLevel = m_ZoomLevelDef[i]; break; } } if (startFromZoomLevel == null) return new Collection(features.ToList()); else return new Collection(features.AsParallel().Where(f => IsMatch(f, currentZoomLevel, startFromZoomLevel.DisplayInterval)).ToList()); } private bool IsMatch(Feature feature, int currentZoomLevel, double displayInterval) { PointShape pointDegrees = (PointShape)Singleton.DefaultProjection.ConvertToInternalProjection(feature.GetBoundingBox().GetCenterPoint()); if (pointDegrees.Y < 0) feature.Tag = "S"; else feature.Tag = "N"; if (Math.Round(pointDegrees.X, 2) % displayInterval == 0 && Math.Round(pointDegrees.Y, 2) % displayInterval == 0) return true; else return false; } protected override void DrawCore(IEnumerable features, GeoCanvas canvas, Collection labelsInThisLayer, System.Collections.ObjectModel.Collection labelsInAllLayers) { Collection filteredFeatures = FilterFeatures(features, canvas); foreach (Feature feature in filteredFeatures) { float angle = float.Parse(feature.ColumnValues["val"]); float spd = float.Parse(feature.ColumnValues["spd"]); int speed = (int)(Math.Round(spd / 5.0) * 5.0); if (speed > 100) speed = 100; if (speed > 0) { PointShape centerPoint = feature.GetBoundingBox().GetCenterPoint(); string key = ("wind_" + feature.Tag.ToString() + "_" + speed).ToLower(); if (m_WindImages.ContainsKey(key)) { canvas.DrawWorldImageWithoutScaling(m_WindImages[key], centerPoint.X, centerPoint.Y, DrawingLevel.LabelLevel, 0, 0, -angle); } else { Logger.Log.Error("wind key " + key + " not found"); } } } } }