2017-10-06 46 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的地圖。

相關問題