ThinkGeo Cloud
ThinkGeo UI Controls
ThinkGeo Open Source
Help and Support
External Resources
ThinkGeo Cloud
ThinkGeo UI Controls
ThinkGeo Open Source
Help and Support
External Resources
using System; using System.Collections.Generic; using System.Configuration; using System.Data; using System.Linq; using System.Windows; namespace WeatherLineStyle { /// <summary> /// Interaction logic for App.xaml /// </summary> public partial class App : Application { } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using ThinkGeo.MapSuite.Core; namespace WeatherLineStyle { class customGeoImageLineStyle : LineStyle { private GeoImage geoImage; private int spacing; private LineStyle lineStyle; public enum SymbolSide { Right, Left }; private SymbolSide side; public customGeoImageLineStyle(LineStyle LineStyle, GeoImage GeoImage, int Spacing, SymbolSide Side) { this.lineStyle = LineStyle; this.geoImage = GeoImage; this.geoImage = GeoImage; this.spacing = Spacing; this.side = Side; } public LineStyle LineStyle { get { return lineStyle; } set { lineStyle = value; } } public GeoImage GeoImage { get { return geoImage; } set { geoImage = value; } } //Spacing in screen coordinate between each GeoImage on the line. public int Spacing { get { return spacing; } set { spacing = value; } } //Side according to the line direction for orienting the icon. public SymbolSide Side { get { return side; } set { side = value;} } protected override void DrawCore(IEnumerable<Feature> features, GeoCanvas canvas, System.Collections.ObjectModel.Collection<SimpleCandidate> labelsInThisLayer, System.Collections.ObjectModel.Collection<SimpleCandidate> labelsInAllLayers) { PointStyle pointStyle = new PointStyle(geoImage); foreach (Feature feature in features) { LineShape lineShape = (LineShape)feature.GetShape(); lineStyle.Draw(new BaseShape[] { lineShape }, canvas, labelsInThisLayer, labelsInAllLayers); double totalDist = 0; for (int i = 0; i < lineShape.Vertices.Count - 1; i++) { PointShape pointShape1 = new PointShape(lineShape.Vertices[i]); PointShape pointShape2 = new PointShape(lineShape.Vertices[i|+ 1]); LineShape tempLineShape = new LineShape(); tempLineShape.Vertices.Add(lineShape.Vertices[i]); tempLineShape.Vertices.Add(lineShape.Vertices[i|+ 1]); double angle = GetAngleFromTwoVertices(lineShape.Vertices[i], lineShape.Vertices[i|+ 1]); //Left side if (side == SymbolSide.Left) { if (angle >= 270) { angle = angle - 180; } } //Right side else { if (angle <= 90) { angle = angle + 180; } } pointStyle.RotationAngle = (float)angle; float screenDist = ExtentHelper.GetScreenDistanceBetweenTwoWorldPoints(canvas.CurrentWorldExtent, pointShape1, pointShape2, canvas.Width, canvas.Height); double currentDist = Math.Round(pointShape1.GetDistanceTo(pointShape2, canvas.MapUnit, DistanceUnit.Meter), 2); double worldInterval = (currentDist * spacing) / screenDist; while (totalDist <= currentDist) { PointShape tempPointShape = tempLineShape.GetPointOnALine(StartingPoint.FirstPoint, totalDist, canvas.MapUnit, DistanceUnit.Meter); pointStyle.Draw(new BaseShape[] { tempPointShape }, canvas, labelsInThisLayer, labelsInAllLayers); totalDist = totalDist + worldInterval; } totalDist = totalDist - currentDist; } } } private double GetAngleFromTwoVertices(Vertex b, Vertex c) { double result; double alpha = 0; double tangentAlpha = (c.Y - b.Y) / (c.X - b.X); double Peta = Math.Atan(tangentAlpha); if (c.X > b.X) { alpha = 90 + (Peta * (180 / Math.PI)); } else if (c.X < b.X) { alpha = 270 + (Peta * (180 / Math.PI)); } else { if (c.Y > b.Y) alpha = 0; if (c.Y < b.Y) alpha = 180; } double offset; if (b.X > c.X) { offset = 90; } else { offset = -90; } result = alpha + offset; return result; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; using System.Collections.ObjectModel; using ThinkGeo.MapSuite.Core; using ThinkGeo.MapSuite.WpfDesktopEdition; namespace WeatherLineStyle { /// <summary> /// Interaction logic for TestWindow.xaml /// </summary> public partial class TestWindow : Window { public TestWindow() { InitializeComponent(); } private void Window_Loaded(object sender, RoutedEventArgs e) { //Sets the correct map unit and the extent of the map. wpfMap1.MapUnit = GeographyUnit.Meter; wpfMap1.CurrentExtent = new RectangleShape(-5550725,9115955,1910721,3705430); wpfMap1.Background = new SolidColorBrush(Color.FromRgb(148, 196, 243)); WorldMapKitWmsWpfOverlay worldMapKitWmsWpfOverlay = new WorldMapKitWmsWpfOverlay(); worldMapKitWmsWpfOverlay.Projection = WorldMapKitProjection.SphericalMercator; wpfMap1.Overlays.Add(worldMapKitWmsWpfOverlay); LineStyle lineStyle = LineStyles.CreateSimpleLineStyle(GeoColor.StandardColors.Black, 2, false); //Cold Front InMemoryFeatureLayer inMemoryFeatureLayerColdFront = new InMemoryFeatureLayer(); customGeoImageLineStyle coldFrontLineStyle = new customGeoImageLineStyle(lineStyle, new GeoImage(@"..\..\data\offset_triangle.png"), 25, customGeoImageLineStyle.SymbolSide.Right); inMemoryFeatureLayerColdFront.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(coldFrontLineStyle); inMemoryFeatureLayerColdFront.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; StreamReader streamReader2 = new StreamReader(@"..\..\data\ColdFront2.txt"); LineShape lineShape2 = new LineShape(streamReader2.ReadLine()); inMemoryFeatureLayerColdFront.InternalFeatures.Add(new Feature(lineShape2)); StreamReader streamReader3 = new StreamReader(@"..\..\data\ColdFront3.txt"); LineShape lineShape3 = new LineShape(streamReader3.ReadLine()); inMemoryFeatureLayerColdFront.InternalFeatures.Add(new Feature(lineShape3)); //Warm Front InMemoryFeatureLayer inMemoryFeatureLayerWarmFront = new InMemoryFeatureLayer(); customGeoImageLineStyle warmFrontLineStyle = new customGeoImageLineStyle(lineStyle, new GeoImage(@"..\..\data\offset_circle.png"), 25, customGeoImageLineStyle.SymbolSide.Right); inMemoryFeatureLayerWarmFront.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(warmFrontLineStyle); inMemoryFeatureLayerWarmFront.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; StreamReader streamReader5 = new StreamReader(@"..\..\data\WarmFront5.txt"); LineShape lineShape5 = new LineShape(streamReader5.ReadLine()); inMemoryFeatureLayerWarmFront.InternalFeatures.Add(new Feature(lineShape5)); StreamReader streamReader6 = new StreamReader(@"..\..\data\WarmFront6.txt"); LineShape lineShape6 = new LineShape(streamReader6.ReadLine()); inMemoryFeatureLayerWarmFront.InternalFeatures.Add(new Feature(lineShape6)); StreamReader streamReader7 = new StreamReader(@"..\..\data\WarmFront7.txt"); LineShape lineShape7 = new LineShape(streamReader7.ReadLine()); inMemoryFeatureLayerWarmFront.InternalFeatures.Add(new Feature(lineShape7)); StreamReader streamReader8 = new StreamReader(@"..\..\data\WarmFront8.txt"); LineShape lineShape8 = new LineShape(streamReader8.ReadLine()); inMemoryFeatureLayerWarmFront.InternalFeatures.Add(new Feature(lineShape8)); //Occluded Front InMemoryFeatureLayer inMemoryFeatureLayerOccludedFront = new InMemoryFeatureLayer(); customGeoImageLineStyle occludedFrontLineStyle = new customGeoImageLineStyle(lineStyle, new GeoImage(@"..\..\data\offset_triangle_and_circle.png"), 40, customGeoImageLineStyle.SymbolSide.Right); inMemoryFeatureLayerOccludedFront.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(occludedFrontLineStyle); inMemoryFeatureLayerOccludedFront.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; StreamReader streamReader9 = new StreamReader(@"..\..\data\OccludedFront9.txt"); LineShape lineShape9 = new LineShape(streamReader9.ReadLine()); inMemoryFeatureLayerOccludedFront.InternalFeatures.Add(new Feature(lineShape9)); StreamReader streamReader10 = new StreamReader(@"..\..\data\OccludedFront10.txt"); LineShape lineShape10 = new LineShape(streamReader10.ReadLine()); inMemoryFeatureLayerOccludedFront.InternalFeatures.Add(new Feature(lineShape10)); StreamReader streamReader11 = new StreamReader(@"..\..\data\OccludedFront11.txt"); LineShape lineShape11 = new LineShape(streamReader11.ReadLine()); inMemoryFeatureLayerOccludedFront.InternalFeatures.Add(new Feature(lineShape11)); LayerOverlay dynamicOverlay = new LayerOverlay(); dynamicOverlay.Layers.Add("ColdFront", inMemoryFeatureLayerColdFront); dynamicOverlay.Layers.Add("WarmFront", inMemoryFeatureLayerWarmFront); dynamicOverlay.Layers.Add("OccludedFront", inMemoryFeatureLayerOccludedFront); wpfMap1.Overlays.Add("Dynamic", dynamicOverlay); wpfMap1.Refresh(); } private void wpfMap1_MouseMove(object sender, MouseEventArgs e) { //Gets the PointShape in world coordinates from screen coordinates. Point point = e.MouseDevice.GetPosition(null); ScreenPointF screenPointF = new ScreenPointF((float)point.X, (float)point.Y); PointShape pointShape = ExtentHelper.ToWorldCoordinate(wpfMap1.CurrentExtent, screenPointF, (float)wpfMap1.Width, (float)wpfMap1.Height); //textBox1.Text = "X: " + DecimalDegreesHelper.GetDegreesMinutesSecondsStringFromDecimalDegree(pointShape.X) + // " Y: " + DecimalDegreesHelper.GetDegreesMinutesSecondsStringFromDecimalDegree(pointShape.Y); textBox1.Text = "X: " + pointShape.X + " Y: " + pointShape.Y; } } }