瓦片地圖加載框架——TiledMapView

有幸參與過一個簡易地理信息系統(GIS)的開發,學到了不少地理信息相關的知識,便想要開發一個關於瓦片地圖加載的開源庫,跟大家一起分享交流。

TiledMapView

Android瓦片地圖加載,支持多種投影,包括Web墨卡託投影,經緯度直投及自定義投影等;支持定位,添加圖層和覆蓋物。

googlemap

tianditu

用法

Gradle

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}
 
dependencies {
    compile 'com.github.1993hzw:TiledMapView:1.0.0'
}

目前***最新版本***爲:

TiledMapView使用Picasso庫作爲默認圖像加載程序。因此,如果你想使用Picasso,應該額外增加依賴:

dependencies {
    implementation 'com.squareup.picasso:picasso:2.71828'
}

代碼

在佈局裏添加TiledMapView:

<cn.forward.tiledmapview.TiledMapView
    android:id="@+id/mapview"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />
TiledMapView mapView = (TiledMapView)findViewById(R.id.mapview);

現在你可以添加瓦片圖層。以加載谷歌地圖爲例:

TiledMapView mapView = (TiledMapView) findViewById(R.id.mapview);
ITileLayer googleTileLayer = new GoogleTileLayer(mMapView, GoogleOnlineTileImageSource.ImgType.SATILLITE_WITH_MARKER);
mapView.getLayerGroup().add(googleTileLayer);

目前,TiledMapView直接支持加載谷歌地圖(GoogleTileLayer),天地圖(TiandituTileLayer),以及自定義瓦片地圖。

另外,你也可以添加覆蓋物:

TextPixelOverlay textPixelOverlay = new TextPixelOverlay("Hello world!");
textPixelOverlay.setBackgroundColor(0x99ffffff);
textPixelOverlay.getTextPaint().setColor(Color.BLUE);
textPixelOverlay.getTextPaint().setTextSize(Util.dp2px(getApplicationContext(), 14));
textPixelOverlay.setLocationOnMap(0,-300);
mapView.getLayerGroup().add(textPixelOverlay);

可以通過使用BitmapPixelOverlay/BitmapMapOverlay添加圖片覆蓋物

拓展

這裏有一個加載LOL遊戲地圖的示例,顯示瞭如何加載自定義瓦片地圖.

lol

TiledMapView是一個功能強大、可定製和可擴展的加載庫。將來會提供更多的文檔,當然,現在您可以通過閱讀代碼來找到更多的特性,盡情探索吧!

項目地址TiledMapView

最新代碼請關注github項目>>>TiledMapView,謝謝大家支持!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章