From 817009953cc165e376198fe0ad5c3d56b676af4f Mon Sep 17 00:00:00 2001 From: xiaoyan Date: Wed, 30 Aug 2023 11:05:56 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E6=96=87=E5=AD=97obj?= =?UTF-8?q?ect=E7=9A=84=E6=B8=B2=E6=9F=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/assets/omdb_config.json | 16 ++++ .../personalcenter/PersonalCenterFragment.kt | 2 +- .../src/main/assets/editormarker.xml | 44 +++++++++++ .../collect/library/enums/DataCodeEnum.kt | 1 + .../map/handler/LayerManagerHandler.kt | 12 ++- .../map/source/NavinfoTileThemeHook.java | 73 +++++++++++++++++++ vtm | 2 +- 7 files changed, 145 insertions(+), 5 deletions(-) create mode 100644 collect-library/src/main/java/com/navinfo/collect/library/map/source/NavinfoTileThemeHook.java diff --git a/app/src/main/assets/omdb_config.json b/app/src/main/assets/omdb_config.json index 43317f3c..e1023ac8 100644 --- a/app/src/main/assets/omdb_config.json +++ b/app/src/main/assets/omdb_config.json @@ -160,6 +160,22 @@ "zoomMax": 20, "transformer2Code": "" }, + "3002":{ + "table": "OMDB_OBJECT_TEXT", + "code": 3002, + "name": "文字", + "zoomMin": 15, + "zoomMax": 20, + "transformer2Code": "" + }, + "3003":{ + "table": "OMDB_OBJECT_SYMBOL", + "code": 3003, + "name": "符号", + "zoomMin": 15, + "zoomMax": 20, + "transformer2Code": "" + }, "3005":{ "table": "OMDB_TRAFFIC_SIGN", "code": 3005, diff --git a/app/src/main/java/com/navinfo/omqs/ui/fragment/personalcenter/PersonalCenterFragment.kt b/app/src/main/java/com/navinfo/omqs/ui/fragment/personalcenter/PersonalCenterFragment.kt index eeafd079..151672d8 100644 --- a/app/src/main/java/com/navinfo/omqs/ui/fragment/personalcenter/PersonalCenterFragment.kt +++ b/app/src/main/java/com/navinfo/omqs/ui/fragment/personalcenter/PersonalCenterFragment.kt @@ -129,7 +129,7 @@ class PersonalCenterFragment(private var indoorDataListener: ((Boolean) -> Unit? // 定位到指定位置 niMapController.mMapView.vtmMap.animator() // .animateTo(GeoPoint( 40.05108004733645, 116.29187746293708 )) - .animateTo(GeoPoint( 40.45250049995882, 115.85967482434108 )) + .animateTo(GeoPoint( 40.50716396962102, 115.80381067125272)) } R.id.personal_center_menu_open_all_layer -> { MapParamUtils.setDataLayerEnum(DataLayerEnum.SHOW_ALL_LAYERS) diff --git a/collect-library/src/main/assets/editormarker.xml b/collect-library/src/main/assets/editormarker.xml index ebc1e764..6834def5 100644 --- a/collect-library/src/main/assets/editormarker.xml +++ b/collect-library/src/main/assets/editormarker.xml @@ -2330,6 +2330,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/collect-library/src/main/java/com/navinfo/collect/library/enums/DataCodeEnum.kt b/collect-library/src/main/java/com/navinfo/collect/library/enums/DataCodeEnum.kt index ad6c96bb..8959d09d 100644 --- a/collect-library/src/main/java/com/navinfo/collect/library/enums/DataCodeEnum.kt +++ b/collect-library/src/main/java/com/navinfo/collect/library/enums/DataCodeEnum.kt @@ -63,6 +63,7 @@ enum class DataCodeEnum(var tableName: String, var code: String) { OMDB_SPEEDLIMIT_COND("条件点限速", "4003"), OMDB_SPEEDLIMIT_VAR("可变点限速", "4004"), OMDB_RESTRICTION("普通交限", "4006"), + OMDB_WARNINGSIGN("警示信息", "4009"), OMDB_ELECTRONICEYE("电子眼", "4010"), OMDB_TRAFFICLIGHT("交通灯", "4022"), OMDB_TOLLGATE("收费站", "4023"), diff --git a/collect-library/src/main/java/com/navinfo/collect/library/map/handler/LayerManagerHandler.kt b/collect-library/src/main/java/com/navinfo/collect/library/map/handler/LayerManagerHandler.kt index fbf22a22..ff17f5f2 100644 --- a/collect-library/src/main/java/com/navinfo/collect/library/map/handler/LayerManagerHandler.kt +++ b/collect-library/src/main/java/com/navinfo/collect/library/map/handler/LayerManagerHandler.kt @@ -6,6 +6,7 @@ import com.navinfo.collect.library.data.entity.RenderEntity import com.navinfo.collect.library.map.NIMapView import com.navinfo.collect.library.map.source.MapLifeNiLocationTileSource import com.navinfo.collect.library.map.source.NavinfoMultiMapFileTileSource +import com.navinfo.collect.library.map.source.NavinfoTileThemeHook import com.navinfo.collect.library.map.source.OMDBReferenceTileSource import com.navinfo.collect.library.map.source.OMDBTileSource import com.navinfo.collect.library.system.Constant @@ -57,6 +58,8 @@ class LayerManagerHandler(context: AppCompatActivity, mapView: NIMapView, traceP private val omdbTileSource by lazy { OMDBTileSource() } private val omdbReferenceTileSource by lazy { OMDBReferenceTileSource() } + private val labelTileLoaderHook = LabelTileLoaderHook() + private val navinfoTileThemeHook = NavinfoTileThemeHook() init { initMap() @@ -76,7 +79,7 @@ class LayerManagerHandler(context: AppCompatActivity, mapView: NIMapView, traceP vectorNiLocationTileLayer = VectorTileLayer(mMapView.vtmMap, mapLifeNiLocationTileSource) labelNiLocationLayer = - LabelLayer(mMapView.vtmMap, vectorNiLocationTileLayer, LabelTileLoaderHook()) + LabelLayer(mMapView.vtmMap, vectorNiLocationTileLayer, labelTileLoaderHook) if (vectorNiLocationTileLayer != null) { addLayer(vectorNiLocationTileLayer, NIMapView.LAYER_GROUPS.BASE) @@ -114,7 +117,7 @@ class LayerManagerHandler(context: AppCompatActivity, mapView: NIMapView, traceP omdbReferenceLabelLayer = LabelLayer( mMapView.vtmMap, omdbReferenceTileLayer, - LabelTileLoaderHook() + labelTileLoaderHook ) if (omdbReferenceTileLayer != null) { addLayer(omdbReferenceTileLayer, NIMapView.LAYER_GROUPS.VECTOR_TILE) @@ -127,7 +130,7 @@ class LayerManagerHandler(context: AppCompatActivity, mapView: NIMapView, traceP omdbLabelLayer = LabelLayer( mMapView.vtmMap, omdbVectorTileLayer, - LabelTileLoaderHook() + labelTileLoaderHook ) if (omdbVectorTileLayer != null) { addLayer(omdbVectorTileLayer, NIMapView.LAYER_GROUPS.VECTOR_TILE) @@ -135,6 +138,9 @@ class LayerManagerHandler(context: AppCompatActivity, mapView: NIMapView, traceP if (omdbLabelLayer != null) { addLayer(omdbLabelLayer, NIMapView.LAYER_GROUPS.LABEL) } + // 向两个Vector图层增加hook钩子,加载数据前对style或数据进行二次处理 + omdbVectorTileLayer.addHook(navinfoTileThemeHook) + omdbReferenceTileLayer.addHook(navinfoTileThemeHook) } private fun resetOMDBVectorTileLayer() { diff --git a/collect-library/src/main/java/com/navinfo/collect/library/map/source/NavinfoTileThemeHook.java b/collect-library/src/main/java/com/navinfo/collect/library/map/source/NavinfoTileThemeHook.java new file mode 100644 index 00000000..6be00dc7 --- /dev/null +++ b/collect-library/src/main/java/com/navinfo/collect/library/map/source/NavinfoTileThemeHook.java @@ -0,0 +1,73 @@ +package com.navinfo.collect.library.map.source; + +import org.oscim.core.MapElement; +import org.oscim.layers.tile.MapTile; +import org.oscim.layers.tile.vector.VectorTileLayer; +import org.oscim.renderer.bucket.RenderBuckets; +import org.oscim.theme.styles.RenderStyle; + +import java.util.HashMap; +import java.util.Map; + +/** + * 数据在加载前对MapElement做处理 + * + * */ +public class NavinfoTileThemeHook implements VectorTileLayer.TileLoaderThemeHook { + // 缓存样式,如果存在相同的文字图片,从缓存直接获取 + private Map styleMap = new HashMap<>(); + + @Override + public boolean process(MapTile tile, RenderBuckets buckets, MapElement element, RenderStyle style, int level) { +// if (style instanceof AreaStyle) { +// AreaStyle area = (AreaStyle) style; +// if (area.src!=null&&area.texture==null) { +// String textValue = null; +// if (area.src.startsWith("@text-src:")) { +// String tagKey = area.src.replace("@text-src:", ""); +// // 根据配置的tagKey获取对应的文字值 +// textValue = element.tags.getValue(tagKey); +// } else if (area.src.startsWith("@text:")) { +// // 构建一个文字图片 +// textValue = area.src.substring(5); +// } +// +// // 使用文本值生成纹理图片 +// if (textValue==null) { +// return false; +// } +// +// // 根据引用字段,生成新的style样式 +// RenderStyle cacheStyle = styleMap.get(textValue); +// if (cacheStyle!=null) { +// style.set(cacheStyle); +// } else { // 不存在缓存style,需要按照文字生成对应的图片纹理 +// AreaStyle.AreaBuilder builder = new AreaStyle.AreaBuilder(); +// builder.set((AreaStyle) style); +// // 构建一个文字图片 +// Canvas canvas = CanvasAdapter.newCanvas(); +// Paint paint = CanvasAdapter.newPaint(); +// paint.setColor(Color.WHITE); +// paint.setTextSize(15); +// +// Bitmap bitmap = CanvasAdapter.newBitmap(Math.round(paint.getTextWidth(textValue)+10), Math.round(paint.getTextHeight(textValue)+10), 0); +// canvas.setBitmap(bitmap); +// canvas.drawText(textValue, 5 +// , 5+paint.getTextHeight(textValue), paint, paint); +// builder.texture = new TextureItem(Utils.potBitmap(bitmap), area.repeat); +// builder.src = null; // 清空原有的带@的src配置 +// area = builder.build(); +// styleMap.put(textValue, area); +// style.set(area); +// } +// } +// } +// style.update(); + return false; // 如果返回true,后续的hook将不会执行 + } + + @Override + public void complete(MapTile tile, boolean success) { + + } +} diff --git a/vtm b/vtm index 163b9f07..fdf36bde 160000 --- a/vtm +++ b/vtm @@ -1 +1 @@ -Subproject commit 163b9f0773f8216621d2a2c46aa7fa1ee98e431f +Subproject commit fdf36bde1364241a6d2ebfad686ee3b2311b73b0