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 96e7543f..ab78744b 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.04315565069137, 116.28669540538765)) + .animateTo(GeoPoint(40.08785792571823, 116.27562659540283)) } R.id.personal_center_menu_open_all_layer -> { MapParamUtils.setDataLayerEnum(DataLayerEnum.SHOW_ALL_LAYERS) diff --git a/collect-library/src/main/java/com/navinfo/collect/library/map/source/OMDBReferenceDataSource.java b/collect-library/src/main/java/com/navinfo/collect/library/map/source/OMDBReferenceDataSource.java index b9ba60de..3722aec3 100644 --- a/collect-library/src/main/java/com/navinfo/collect/library/map/source/OMDBReferenceDataSource.java +++ b/collect-library/src/main/java/com/navinfo/collect/library/map/source/OMDBReferenceDataSource.java @@ -7,14 +7,17 @@ import androidx.annotation.RequiresApi; import com.navinfo.collect.library.data.entity.ReferenceEntity; import com.navinfo.collect.library.system.Constant; +import com.navinfo.collect.library.utils.GeometryTools; import com.navinfo.collect.library.utils.MapParamUtils; +import org.locationtech.jts.geom.Polygon; import org.oscim.layers.tile.MapTile; import org.oscim.tiling.ITileDataSink; import org.oscim.tiling.ITileDataSource; import org.oscim.tiling.QueryResult; import java.util.List; +import java.util.stream.Collectors; import io.realm.Realm; import io.realm.RealmQuery; @@ -33,7 +36,7 @@ public class OMDBReferenceDataSource implements ITileDataSource { @Override public void query(MapTile tile, ITileDataSink mapDataSink) { // 获取tile对应的坐标范围 - if (tile.zoomLevel >= Constant.OMDB_MIN_ZOOM && tile.zoomLevel <= Constant.OVER_ZOOM) { + if (tile.zoomLevel >= Constant.OMDB_MIN_ZOOM && tile.zoomLevel < Constant.OVER_ZOOM) { int m = Constant.OVER_ZOOM - tile.zoomLevel; int xStart = (int) tile.tileX << m; int xEnd = (int) ((tile.tileX + 1) << m); @@ -64,12 +67,16 @@ public class OMDBReferenceDataSource implements ITileDataSource { } List listResult = realmQuery/*.distinct("id")*/.findAll(); if (!listResult.isEmpty()) { + Polygon tilePolygon = GeometryTools.getTilePolygon(tile); + listResult = listResult.stream().filter((ReferenceEntity referenceEntity) -> referenceEntity.getWkt().intersects(tilePolygon)).collect(Collectors.toList()); mThreadLocalDecoders.get().decode(tile.zoomLevel, tile, mapDataSink, listResult); + mapDataSink.completed(QueryResult.SUCCESS); + } else { + mapDataSink.completed(QueryResult.TILE_NOT_FOUND); } - mapDataSink.completed(QueryResult.SUCCESS); // Log.d("RealmDBTileDataSource", "tile:"+tile.getBoundingBox().toString()); } else { - mapDataSink.completed(QueryResult.SUCCESS); + mapDataSink.completed(QueryResult.TILE_NOT_FOUND); } } diff --git a/collect-library/src/main/java/com/navinfo/collect/library/map/source/OMDBTileDataSource.java b/collect-library/src/main/java/com/navinfo/collect/library/map/source/OMDBTileDataSource.java index e5720e14..49dbba31 100644 --- a/collect-library/src/main/java/com/navinfo/collect/library/map/source/OMDBTileDataSource.java +++ b/collect-library/src/main/java/com/navinfo/collect/library/map/source/OMDBTileDataSource.java @@ -7,14 +7,17 @@ import androidx.annotation.RequiresApi; import com.navinfo.collect.library.data.entity.RenderEntity; import com.navinfo.collect.library.system.Constant; +import com.navinfo.collect.library.utils.GeometryTools; import com.navinfo.collect.library.utils.MapParamUtils; +import org.locationtech.jts.geom.Polygon; import org.oscim.layers.tile.MapTile; import org.oscim.tiling.ITileDataSink; import org.oscim.tiling.ITileDataSource; import org.oscim.tiling.QueryResult; import java.util.List; +import java.util.stream.Collectors; import io.realm.Realm; import io.realm.RealmQuery; @@ -32,7 +35,7 @@ public class OMDBTileDataSource implements ITileDataSource { @Override public void query(MapTile tile, ITileDataSink mapDataSink) { // 获取tile对应的坐标范围 - if (tile.zoomLevel >= Constant.OMDB_MIN_ZOOM && tile.zoomLevel <= Constant.OVER_ZOOM) { + if (tile.zoomLevel >= Constant.OMDB_MIN_ZOOM && tile.zoomLevel < Constant.OVER_ZOOM) { int m = Constant.OVER_ZOOM - tile.zoomLevel; int xStart = (int) tile.tileX << m; int xEnd = (int) ((tile.tileX + 1) << m); @@ -61,12 +64,17 @@ public class OMDBTileDataSource implements ITileDataSource { realmQuery.endGroup(); } List listResult = realmQuery/*.distinct("id")*/.findAll(); + // 数据记录的tile号是以正外接tile号列表,此处过滤并未与当前tile相交的数据 if (!listResult.isEmpty()) { + Polygon tilePolygon = GeometryTools.getTilePolygon(tile); + listResult = listResult.stream().filter((RenderEntity renderEntity) -> renderEntity.getWkt().intersects(tilePolygon)).collect(Collectors.toList()); mThreadLocalDecoders.get().decode(tile.zoomLevel, tile, mapDataSink, listResult); + mapDataSink.completed(QueryResult.SUCCESS); + } else { + mapDataSink.completed(QueryResult.TILE_NOT_FOUND); } - mapDataSink.completed(QueryResult.SUCCESS); } else { - mapDataSink.completed(QueryResult.SUCCESS); + mapDataSink.completed(QueryResult.TILE_NOT_FOUND); } } diff --git a/collect-library/src/main/java/com/navinfo/collect/library/utils/GeometryTools.java b/collect-library/src/main/java/com/navinfo/collect/library/utils/GeometryTools.java index 02d1e1ff..8fe0be1e 100644 --- a/collect-library/src/main/java/com/navinfo/collect/library/utils/GeometryTools.java +++ b/collect-library/src/main/java/com/navinfo/collect/library/utils/GeometryTools.java @@ -2,6 +2,7 @@ package com.navinfo.collect.library.utils; import android.graphics.Point; import android.util.Log; + import org.locationtech.jts.geom.Coordinate; import org.locationtech.jts.geom.Geometry; import org.locationtech.jts.geom.GeometryFactory; @@ -13,7 +14,10 @@ import org.locationtech.jts.geom.Polygon; import org.locationtech.jts.io.WKTReader; import org.locationtech.jts.operation.linemerge.LineMerger; import org.oscim.core.GeoPoint; +import org.oscim.core.MercatorProjection; +import org.oscim.core.Tile; import org.oscim.map.Map; + import java.math.BigDecimal; import java.util.ArrayList; import java.util.Collection; @@ -251,6 +255,22 @@ public class GeometryTools { return gon.toString(); } + /** + * 创建多边形几何 + * + * @param coords [] + * @return Geometry + */ + public static Polygon createPolygonFromCoords(Coordinate[] coords) { + GeometryFactory factory = new GeometryFactory(); + + Polygon gon = factory.createPolygon(coords); + + if (gon == null) + return null; + return gon; + } + /** * 创建多边形几何 * @@ -1579,4 +1599,14 @@ public class GeometryTools { double radianDegree = 2 * Math.asin(Math.sin(radianDistance / 2) / Math.cos(radianLatitude)); return Math.toDegrees(radianDegree); } + + public static Polygon getTilePolygon(Tile tile) { + // 获取当前tile的起点坐标 + double startLongitude = MercatorProjection.tileXToLongitude(tile.tileX, tile.zoomLevel); + double startLatitude = MercatorProjection.tileYToLatitude(tile.tileY, tile.zoomLevel); + double endLongitude = MercatorProjection.tileXToLongitude(tile.tileX+1, tile.zoomLevel); + double endLatitude = MercatorProjection.tileYToLatitude(tile.tileY+1, tile.zoomLevel); + return GeometryTools.createPolygonFromCoords(new Coordinate[]{new Coordinate(startLongitude, startLongitude), new Coordinate(endLongitude, startLatitude), + new Coordinate(endLongitude, endLatitude), new Coordinate(startLongitude, endLatitude), new Coordinate(startLongitude, startLongitude)}); + } } diff --git a/vtm b/vtm index a087521b..d1ac330c 160000 --- a/vtm +++ b/vtm @@ -1 +1 @@ -Subproject commit a087521b6e1b312d7ed2bdf20f83b0e674fad9b5 +Subproject commit d1ac330cf7a8727bb2065093e72d60521775ba6d