2017-10-06 48 views
4

我有一个SQL数据库内的区域边界列表,我使用sharpmap渲染每个我需要的国家的缩略图。它工作得很好。如何使用清晰的地图在地球上呈现国家的图像

但我想更进一步,在它周围添加一个小地球仪,并将其放置在地球上的国家,但我不知道从哪里开始。

下面是我使用到目前为止呈现国家拇指的代码。有任何想法吗?

var map = new Map(new Size(command.Width, command.Height)); 
map.BackColor = Color.Transparent; 
var countryGeometry = GeometryFromWKT.Parse(command.CountryLevelWkt); 
IProvider countryProvider = new GeometryFeatureProvider(countryGeometry); 
var countryLayer = new VectorLayer("country", countryProvider); 
var borderColor = System.Drawing.ColorTranslator.FromHtml(command.BorderColor); 
countryLayer.Style.EnableOutline = true; 
countryLayer.Style.Outline = new Pen(borderColor); 
countryLayer.Style.Outline.Width = command.BorderWidth; 
countryLayer.Style.Fill = Brushes.Transparent; 

var transformationFactory = new CoordinateTransformationFactory(); 
countryLayer.CoordinateTransformation = transformationFactory.CreateFromCoordinateSystems(
      GeographicCoordinateSystem.WGS84, 
      ProjectedCoordinateSystem.WebMercator); 
map.Layers.Add(countryLayer); 
var bottomLeft = new Coordinate(command.Extents.BottomLeft.Longitude, command.Extents.BottomLeft.Latitude); 
var topRight = new Coordinate(command.Extents.TopRight.Longitude, command.Extents.TopRight.Latitude); 


// transformations 
var bottomLeftLongLat = countryLayer.CoordinateTransformation.MathTransform.Transform(bottomLeft); 
var topRightLongLat = countryLayer.CoordinateTransformation.MathTransform.Transform(topRight); 
map.ZoomToBox(new Envelope(bottomLeftLongLat, topRightLongLat)); 
      var img = map.GetMap(); 
return img; 
+0

地球仪是指三维地球仪还是投影仪? – Isma

+0

@Isma no。它可以看起来像facebook图标一样通知,但它必须有选定的国家。 – Robert

回答

2
  1. 开始通过绘制新的地图上所有的国家,它的每一个自己的层上。
  2. 在您自己的图层上绘制您感兴趣的国家。
  3. 将地图中心设置为步骤2中图层的Envelope.Center。例如,如果绘制澳大利亚地图,地图将移动到左侧。
  4. 将地图渲染为图像。在绘图sufrace上绘制图像(System.Drawing.Graphics)。
  5. 将地图重新​​居中以覆盖空白区域。例如,如果绘制澳大利亚,几乎一直向右移动地图。您将需要编程解决这些偏移量。
  6. 将步骤5中的地图渲染为图像。添加图像到相同的图纸sufrace(请参阅步骤4)。
  7. 重复步骤5-6覆盖空的空间低于/高于呈现在步骤3.

这里制成是一个例子: Sample form with map rendering

注意的是:

  • 澳大利亚是中心
  • 鼠标指针附近的地图图层之间存在间隙(屏幕截图中的间隙旨在演示逻辑)
  • 一些国家是非常大的(如俄罗斯),并获得Envelope.Center将不能很好地工作 - 考虑定心基础上,最大的多边形只有

下面是一个示例Windows Forms project。在示例中,我使用了http://thematicmapping.org/downloads/world_borders.php的地图。

相关问题