原創(chuàng)|使用教程|編輯:郝浩|2013-04-10 09:42:38.000|閱讀 411 次
概述:在上一篇移動GIS控件Map Suite MVC使用教程中我們介紹了GIS示例"Hello World"中一些重要參數(shù)和數(shù)據(jù),本文中慧都小編將為你介紹一個簡單的世界地圖創(chuàng)建方法。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
在上一篇移動GIS控件Map Suite MVC使用教程中我們介紹了GIS示例"Hello World"中一些重要參數(shù)和數(shù)據(jù),本文中慧都小編將為你介紹一個簡單的世界地圖創(chuàng)建方法。
說明:Map Suite MVC Edition提供了兩種方法,我們可以添加我們的代碼定義ShapeFileFeatureLayer。一個是控制器的操作中,另一種是在視圖頁面中。這里,在我們的例子中將使用后者。前者的例子你可以參考安裝文件中的示例應(yīng)用。
現(xiàn)在,讓我們來看看實現(xiàn)這個概念所需的代碼。在這個例子中,我們將使用一個Shapefile文件,它包含了整個世界的數(shù)據(jù)。有一個現(xiàn)成的Shapefile文件可供我們使用:
注意:在此示例中使用的數(shù)據(jù)存放在Map Suite MVC Edition安裝文件夾的“Samples\CSharp HowDoISamples Razor\App_Data”中。下圖顯示了該文件夾的內(nèi)容。
在此示例中使用的數(shù)據(jù)
我們的下一步是為地圖定義和添加Shapefile層。我們的所有示例代碼被放置在視圖頁面“Index.cshtml”中。
@{Html.ThinkGeo().Map("Map1", 600, 500) .MapBackground(new BackgroundLayer(new GeoSolidBrush(GeoColor.FromHtml("#E5E3DF")))) .CurrentExtent(-131.22, 55.05, -54.03, 16.91) .MapUnit(GeographyUnit.DecimalDegree) .StaticOverlay(overlay => { // We create a new Layer and pass the path to a Shapefile into its constructor. ShapeFileFeatureLayer worldLayer = new ShapeFileFeatureLayer(@"C:\Program Files (x86)\ThinkGeo\Map Suite Mvc Evaluation Edition 6.0\Samples\CSharp HowDoISamples Razor\App_Data\cntry02.shp"); // Set the worldLayer to use a preset Style. Since AreaStyles.Country1 has YellowGreen background and Black border, our worldLayer will have the same render style. worldLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.Country1; // This setting will apply from ZoomLevel01 to ZoomLevel20, which means we can see the world the same style all the time no matter how far we zoom in or out. worldLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; // We need to add the worldLayer to the map's Static Overlay. overlay.Layer(worldLayer); }) .Render(); }
如果你編譯并運行,你的地圖看起來應(yīng)該像下面的截圖:
一個簡單的世界地圖
我們已經(jīng)創(chuàng)建了一個圖層,并把它添加到地圖,地圖將根據(jù)它的默認樣式參數(shù)渲染。此外,我們還使用ZoomLevel按照我們想要的方式顯示地圖。
注意:這是很重要的一個Map對象MapUnit屬性被設(shè)置為使用GeographyUnit枚舉。這是因為Shapefiles只能存儲二元矢量坐標,它可以顯示為十進制度、英尺、米或其他單位,可以通過為地圖Shapefiles指定計量單位來實現(xiàn)。這些信息一般存放在Shapefile的文檔中,或者在Shapefile的補充數(shù)據(jù)文件中。
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自:慧都控件網(wǎng)