增加离线地图下载流程

This commit is contained in:
squallzhjch
2023-03-30 10:50:20 +08:00
parent 97a48237ba
commit 3a80a4ee5d
129 changed files with 1590 additions and 13847 deletions

View File

@@ -1,7 +1,7 @@
package com.navinfo.collect.library.map
import android.content.Context
import com.navinfo.collect.library.data.entity.LayerManager
import android.util.Log
import com.navinfo.collect.library.map.handler.*
import com.navinfo.collect.library.map.maphandler.MeasureLayerHandler
import com.navinfo.collect.library.map.handler.ViewportHandler
@@ -9,23 +9,34 @@ import com.navinfo.collect.library.map.handler.ViewportHandler
/**
* 地图控制器
*/
class NIMapController {
open class NIMapController(
context: Context,
options: NIMapOptions? = null,
mapView: NIMapView? = null,
) {
private val mContext = context
var mMapView: NIMapView = mapView ?: NIMapView(mContext, options)
lateinit var mMapView: NIMapView
lateinit var layerManagerHandler: LayerManagerHandler
lateinit var locationLayerHandler: LocationLayerHandler
lateinit var animationHandler: AnimationHandler
lateinit var markerHandle: MarkHandler
lateinit var lineHandler: LineHandler
lateinit var polygonHandler: PolygonHandler
lateinit var viewportHandler: ViewportHandler
lateinit var measureLayerHandler: MeasureLayerHandler
val layerManagerHandler = LayerManagerHandler(mContext, mMapView)
val locationLayerHandler by lazy { LocationLayerHandler(mContext, mMapView) }
val animationHandler by lazy { AnimationHandler(mContext, mMapView) }
val markerHandle by lazy { MarkHandler(mContext, mMapView) }
val lineHandler by lazy { LineHandler(mContext, mMapView) }
val polygonHandler by lazy { PolygonHandler(mContext, mMapView) }
val viewportHandler by lazy { ViewportHandler(mContext, mMapView) }
val measureLayerHandler by lazy { MeasureLayerHandler(mContext, mMapView) }
fun init(context: Context, mapView: NIMapView, options: NIMapOptions? = null) {
layerManagerHandler = LayerManagerHandler(context, mapView)
locationLayerHandler = LocationLayerHandler(context, mapView)
animationHandler = AnimationHandler(context, mapView)
markerHandle = MarkHandler(context, mapView)
lineHandler = LineHandler(context, mapView)
polygonHandler = PolygonHandler(context, mapView)
viewportHandler = ViewportHandler(context, mapView)
measureLayerHandler = MeasureLayerHandler(context, mapView)
mMapView = mapView
mapView.setOptions(options)
}
fun print() {
Log.e("jingo", "NIMapController 哈希code ${hashCode()}")
}
}

View File

@@ -48,7 +48,6 @@ import org.oscim.tiling.source.mapfile.MultiMapFileTileSource;
import java.io.File;
/**
* 一个显示地图的视图View。它负责从服务端获取地图数据。它将会捕捉屏幕触控手势事件
*/
@@ -111,11 +110,16 @@ public final class NIMapView extends RelativeLayout {
// protected String mapFilePath = Constant.ROOT_PATH + "/map";
protected GroupLayer baseGroupLayer; // 用于盛放所有基础底图的图层组,便于统一管理
public void setOptions(NIMapOptions option) {
this.options = option;
initOptions();
}
/**
* 地图单击事件监听接口
*/
public interface OnMapClickListener {
public interface OnMapClickListener {
/**
* 地图单击事件回调函数
*
@@ -134,7 +138,7 @@ public final class NIMapView extends RelativeLayout {
/**
* 地图双击事件监听接口
*/
public interface OnMapDoubleClickListener {
public interface OnMapDoubleClickListener {
/**
* 地图双击事件监听回调函数
@@ -148,7 +152,7 @@ public final class NIMapView extends RelativeLayout {
/**
* 地图长按事件监听接口
*/
public interface OnMapLongClickListener {
public interface OnMapLongClickListener {
/**
* 地图长按事件监听回调函数
*
@@ -160,7 +164,7 @@ public final class NIMapView extends RelativeLayout {
/**
* 用户触摸地图时回调接口
*/
public interface OnMapTouchListener {
public interface OnMapTouchListener {
/**
* 当用户触摸地图时回调函数
*
@@ -170,12 +174,11 @@ public final class NIMapView extends RelativeLayout {
}
public NIMapView(Context context, NIMapOptions options) {
this(context, null, 0);
this.options = options;
initOptions();
}
// public NIMapView(Context context, NIMapOptions options) {
// this(context, null, 0);
// this.options = options;
// initOptions();
// }
/**
* 地图的单击事件监听

View File

@@ -1,76 +0,0 @@
package com.navinfo.collect.map;
import android.content.Context;
import android.os.Environment;
import com.navinfo.collect.library.map.source.NavinfoMapRastorTileSource;
import com.navinfo.collect.library.map.source.NavinfoMultiMapFileTileSource;
import org.oscim.android.cache.TileCache;
import org.oscim.layers.Layer;
import org.oscim.layers.tile.bitmap.BitmapTileLayer;
import org.oscim.layers.tile.vector.VectorTileLayer;
import org.oscim.map.Map;
import org.oscim.tiling.source.OkHttpEngine;
import java.io.File;
import java.util.Collections;
import java.util.HashMap;
import okhttp3.Cache;
import okhttp3.OkHttpClient;
public class NILayerManager {
private Map vtmMap;
public static String defaultDir = Environment.getExternalStorageDirectory() + "/" + "EditorMark";
private String defaultLocalMapPath = defaultDir + "/maps/";
public NILayerManager(Map vtmMap) {
this.vtmMap = vtmMap;
}
public Layer getRasterTileLayer(Context mContext, String url, String tilePath, boolean useCache) {
if (this.vtmMap == null) {
throw new IllegalStateException("无法获取到map对象");
}
NavinfoMapRastorTileSource mTileSource = NavinfoMapRastorTileSource.builder(url).httpFactory(new OkHttpEngine.OkHttpFactory()).tilePath(tilePath).build();
OkHttpClient.Builder builder = new OkHttpClient.Builder();
// 如果使用缓存
if (useCache) {
File cacheDirectory = new File(defaultDir, "tiles-raster");
int cacheSize = 300 * 1024 * 1024; // 300 MB
Cache cache = new Cache(cacheDirectory, cacheSize);
builder.cache(cache);
}
mTileSource.setHttpEngine(new OkHttpEngine.OkHttpFactory(builder));
mTileSource.setHttpRequestHeaders(Collections.singletonMap("User-Agent", "vtm-android-example"));
mTileSource.setCache(new TileCache(mContext, defaultDir, url.substring(url.indexOf(":")+1)));
BitmapTileLayer rasterLayer = new BitmapTileLayer(this.vtmMap, mTileSource);
return rasterLayer;
}
// 初始化请求在线底图数据
public Layer getDefaultVectorLayer(boolean useCache) {
OkHttpClient.Builder builder = new OkHttpClient.Builder();
if (useCache) {
// Cache the tiles into file system
File cacheDirectory = new File(defaultDir, "tiles-vector");
int cacheSize = 200 * 1024 * 1024; // 200 MB
Cache cache = new Cache(cacheDirectory, cacheSize);
builder.cache(cache);
}
NavinfoMultiMapFileTileSource tileSource = NavinfoMultiMapFileTileSource.builder()
.apiKey("4wTLZyXcQym31pxC_HGy7Q") // Put a proper API key
.httpFactory(new OkHttpEngine.OkHttpFactory(builder))
//.locale("en")
.build();
HashMap<String, String> headerMap = new HashMap<>();
headerMap.put("token", "eyJhbGciOiJIUzI1NiJ9.eyJjbGllbnRJZCI6MTAzLCJ1c2VyTmFtZSI6ImFkbWluIiwidXNlcklkIjoxLCJ1c2VyR3JvdXAiOiLnoJTlj5Hpg6giLCJvcmdJZCI6MSwiaWF0IjoxNjMwOTk4MzI5LCJleHAiOjE2MzEwODQ3Mjl9.0wFm8mAA9dCC2FmZj-u1dhxTFDRYx8AqVnh2C88hitk");
tileSource.setHttpRequestHeaders(headerMap);
VectorTileLayer l = new VectorTileLayer(this.vtmMap, tileSource);
return l;
}
}