有幸參與過一個簡易地理信息系統(GIS)的開發,學到了很多地理信息相關的知識,便想要開發一個關於瓦片地圖加載的開源庫,跟你們一塊兒分享交流。java
Android瓦片地圖加載,支持多種投影,包括Web墨卡託投影,經緯度直投及自定義投影等;支持定位,添加圖層和覆蓋物。android
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
compile 'com.github.1993hzw:TiledMapView:1.2'
}
複製代碼
最新版本請查看>>>TiledMapViewgit
TiledMapView使用Picasso庫做爲默認圖像加載程序。所以,若是你想使用Picasso,應該額外增長依賴:github
dependencies {
implementation 'com.squareup.picasso:picasso:2.71828'
}
複製代碼
在佈局裏添加TiledMapView:app
<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);
複製代碼
如今你能夠添加瓦片圖層。以加載谷歌地圖爲例:maven
TiledMapView mapView = (TiledMapView) findViewById(R.id.mapview);
ITileLayer googleTileLayer = new GoogleTileLayer(mMapView, GoogleOnlineTileImageSource.ImgType.SATILLITE_WITH_MARKER);
mapView.getLayerGroup().add(googleTileLayer);
複製代碼
目前,TiledMapView直接支持加載谷歌地圖(GoogleTileLayer),天地圖(TiandituTileLayer),以及自定義瓦片地圖。佈局
另外,你也能夠添加覆蓋物:gradle
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添加圖片覆蓋物google
這裏有一個加載LOL遊戲地圖的示例,顯示瞭如何加載自定義瓦片地圖.url
TiledMapView是一個功能強大、可定製和可擴展的加載庫。未來會提供更多的文檔,固然,如今您能夠經過閱讀代碼來找到更多的特性,盡情探索吧!
最新代碼請關注github項目>>>TiledMapView,謝謝你們支持!