using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Controls;
using ThinkGeo.MapSuite.Core;
using ThinkGeo.MapSuite.WpfDesktopEdition;
namespace CSHowDoISamples
{
///
/// Interaction logic for DisplayASimpleMap.xaml
///
public partial class DisplayASimpleMap : UserControl
{
public DisplayASimpleMap()
{
InitializeComponent();
}
private void WpfMap_Loaded(object sender, RoutedEventArgs e)
{
Map1.MapUnit = GeographyUnit.DecimalDegree;
Map1.CurrentExtent = new RectangleShape(-155.733, 95.60, 104.42, -81.9);
ShapeFileFeatureLayer worldLayer = new WrapShapeFileFeatureLayer(@"..\..\SampleData\Data\Countries02.shp");
worldLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.Country2;
worldLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
LayerOverlay worldOverlay = new LayerOverlay();
worldOverlay.Layers.Add("WorldLayer", worldLayer);
worldOverlay.MaxExtent = new RectangleShape(-200000, 90, 200000, -90);
Map1.Overlays.Add("WorldOverlay", worldOverlay);
Map1.Refresh();
}
}
public class WrapShapeFileFeatureLayer : ShapeFileFeatureLayer
{
public WrapShapeFileFeatureLayer(string filePath)
: base(filePath)
{
FeatureSource = new WrapShapeFileFeatureSource(filePath);
}
}
public class WrapShapeFileFeatureSource : ShapeFileFeatureSource
{
public WrapShapeFileFeatureSource(string filePath)
: base(filePath)
{ }
protected override System.Collections.ObjectModel.Collection GetFeaturesForDrawingCore(RectangleShape boundingBox, double screenWidth, double screenHeight, System.Collections.Generic.IEnumerable returningColumnNames)
{
PointShape currentCenter = boundingBox.GetCenterPoint();
int wrapCount = (int)((currentCenter.X + 180d) / 360d);
if (wrapCount == 0)
{
if (currentCenter.X + 180 >= 0)
{
return base.GetFeaturesForDrawingCore(boundingBox, screenWidth, screenHeight, returningColumnNames);
}
else
{
wrapCount = -1;
}
}
else if (wrapCount < 0) { wrapCount--; }
RectangleShape normalBoundingBox = new RectangleShape(boundingBox.UpperLeftPoint.X - 360 * wrapCount, boundingBox.UpperLeftPoint.Y, boundingBox.LowerRightPoint.X - 360 * wrapCount, boundingBox.LowerRightPoint.Y);
Collection originFeaturesForDrawing = base.GetFeaturesForDrawingCore(normalBoundingBox, screenWidth, screenHeight, returningColumnNames);
Collection featuresForDrawing = new Collection();
foreach (var feature in originFeaturesForDrawing)
{
BaseShape newShape = feature.GetShape();
if (wrapCount > 0)
{
newShape.TranslateByDegree(wrapCount * 360, 90);
}
else
{
newShape.TranslateByDegree(-wrapCount * 360, 270);
}
Feature newFeature = new Feature(newShape.GetWellKnownBinary(), feature.Id);
foreach (var item in newFeature.ColumnValues)
{
newFeature.ColumnValues.Add(item.Key, item.Value);
}
featuresForDrawing.Add(newFeature);
}
return featuresForDrawing;
}
}
}