有幸参与过一个简易地理信息系统(GIS)的开发,学到了不少地理信息相关的知识,便想要开发一个关于瓦片地图加载的开源库,跟大家一起分享交流。
TiledMapView
Android瓦片地图加载,支持多种投影,包括Web墨卡托投影,经纬度直投及自定义投影等;支持定位,添加图层和覆盖物。
googlemap tianditu用法
Gradle
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
compile 'com.github.1993hzw:TiledMapView:1.0.0'
}
目前最新版本为:
[图片上传失败...(image-dfb874-1556164133425)]
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游戏地图的示例,显示了如何加载自定义瓦片地图.
lolTiledMapView是一个功能强大、可定制和可扩展的加载库。将来会提供更多的文档,当然,现在您可以通过阅读代码来找到更多的特性,尽情探索吧!
项目地址TiledMapView
最新代码请关注github项目>>>TiledMapView,谢谢大家支持!
网友评论