Conflicts:
	app/src/main/java/com/navinfo/omqs/util/SignUtil.kt
This commit is contained in:
qiji4215
2023-09-21 10:01:21 +08:00
23 changed files with 1291 additions and 552 deletions

View File

@@ -1568,7 +1568,7 @@
<!-- 交通标牌 -->
<m v="OMDB_TRAFFIC_SIGN">
<symbol repeat="false" repeat-gap="2000" repeat-start="0" rotate="true"
src="@src" symbol-height="24" symbol-width="24" degree="-90"></symbol>
src="@src" symbol-height="24" symbol-width="24" degree="-90" dy="-30"></symbol>
</m>
<m v="OMDB_AREA">

View File

@@ -10,7 +10,7 @@ abstract class BaseHandler(context: AppCompatActivity, mapView: NIMapView) {
protected val mMapView: NIMapView = mapView
fun addLayer(layer: Layer, groupType: NIMapView.LAYER_GROUPS) {
Log.e("jingo", "增加了图层 ${layer.toString()}")
// Log.e("jingo", "增加了图层 ${layer.toString()}")
mMapView.vtmMap.layers().add(
layer,
groupType.groupIndex

View File

@@ -10,6 +10,7 @@ import com.navinfo.collect.library.map.layers.MultiLinesLayer
import com.navinfo.collect.library.map.layers.OmdbTaskLinkLayer
import com.navinfo.collect.library.utils.GeometryTools
import org.oscim.android.canvas.AndroidBitmap
import org.oscim.core.GeoPoint
import org.oscim.layers.marker.ItemizedLayer
import org.oscim.layers.marker.ItemizedLayer.OnItemGestureListener
import org.oscim.layers.marker.MarkerInterface
@@ -112,6 +113,18 @@ class LineHandler(context: AppCompatActivity, mapView: NIMapView) : BaseHandler(
layer
}
/**
* 高亮一条线
*/
fun showLine(list:List<GeoPoint>) {
try {
mDefaultPathLayer.clearPath()
mDefaultPathLayer.setPoints(list)
mDefaultPathLayer.isEnabled = true
} catch (e: Exception) {
Toast.makeText(mContext, "高亮路线失败 ${e.message}", Toast.LENGTH_SHORT).show()
}
}
/**
* 高亮一条线
@@ -126,6 +139,7 @@ class LineHandler(context: AppCompatActivity, mapView: NIMapView) : BaseHandler(
}
}
/**
* 取消高亮线
*/

View File

@@ -77,7 +77,7 @@ public class OMDBDataDecoder extends TileDecoder {
properties.putAll(renderEntity.getProperties());
parseGeometry(renderEntity.getTable(), renderEntity.getWkt(), properties);
}else{
Log.e("qj","render"+renderEntity.name+"=="+renderEntity.getZoomMin()+"==="+renderEntity.getZoomMax()+"==="+renderEntity.getEnable());
// Log.e("qj","render"+renderEntity.name+"=="+renderEntity.getZoomMin()+"==="+renderEntity.getZoomMax()+"==="+renderEntity.getEnable());
}
}
});

View File

@@ -0,0 +1,145 @@
package com.navinfo.collect.library.utils
import org.locationtech.jts.geom.*
import org.locationtech.jts.io.WKTWriter
import org.oscim.core.GeoPoint
class FootAndDistance(private val point: GeoPoint) {
private val pt = arrayOf(Coordinate(), Coordinate())
private var distance = Double.NaN
private var isNull = true
var footIndex = 0
/**
* Initializes this instance.
*/
fun initialize() {
isNull = true
}
/**
* Initializes the points, computing the distance between them.
* @param p0 the 1st point
* @param p1 the 2nd point
*/
fun initialize(p0: Coordinate, p1: Coordinate) {
initialize(p0, p1, p0.distance(p1))
}
/**
* Initializes the points, avoiding recomputing the distance.
* @param p0 the 1st point
* @param p1 the 2nd point
* @param distance the distance between p0 and p1
*/
fun initialize(p0: Coordinate, p1: Coordinate, distance: Double) {
pt[0].setCoordinate(p0)
pt[1].setCoordinate(p1)
this.distance = distance
isNull = false
}
/**
* Gets the distance between the paired points
* @return the distance between the paired points
*/
fun getDistance(): Double {
return distance
}
/**
* Gets the paired points
* @return the paired points
*/
fun getCoordinates(): Array<Coordinate> {
return pt
}
/**
* Gets one of the paired points
* @param i the index of the paired point (0 or 1)
* @return A point
*/
fun getCoordinate(i: Int): Coordinate {
return pt[i]
}
fun setMinimum(p0: Coordinate, p1: Coordinate): Boolean {
if (isNull) {
initialize(p0, p1)
return true
}
val dist = p0.distance(p1)
if (dist < distance) {
initialize(p0, p1, dist)
return true
}
return false
}
override fun toString(): String {
return WKTWriter.toLineString(pt[0], pt[1])
}
fun getMeterDistance(): Double {
return if (!distance.isNaN() && pt.isNotEmpty())
GeometryTools.getDistance(
point.latitude,
point.longitude,
pt[0].y,
pt[0].x
)
else {
Double.NaN
}
}
fun computeDistance(geom: Geometry, pt: Coordinate) {
when (geom) {
is LineString -> {
computeDistance(geom, pt)
}
is Polygon -> {
computeDistance(geom, pt)
}
is GeometryCollection -> {
for (i in 0 until geom.numGeometries) {
val g = geom.getGeometryN(i)
computeDistance(g, pt)
}
}
else -> { // assume geom is Point
setMinimum(geom.coordinate, pt)
}
}
}
fun computeDistance(line: LineString, pt: Coordinate) {
val tempSegment = LineSegment()
val coords = line.coordinates
for (i in 0 until (coords.size - 1)) {
tempSegment.setCoordinates(coords[i], coords[i + 1])
// this is somewhat inefficient - could do better
val closestPt = tempSegment.closestPoint(pt)
if (setMinimum(closestPt, pt)) {
footIndex = i
}
}
}
fun computeDistance(segment: LineSegment, pt: Coordinate) {
val closestPt = segment.closestPoint(pt)
setMinimum(closestPt, pt)
}
fun computeDistance(poly: Polygon, pt: Coordinate) {
computeDistance(poly.exteriorRing, pt)
for (i in 0 until poly.numInteriorRing) {
computeDistance(poly.getInteriorRingN(i), pt)
}
}
}

View File

@@ -4,9 +4,6 @@ import android.graphics.Point;
import android.os.Build;
import android.util.Log;
import org.jetbrains.annotations.NotNull;
import org.locationtech.jts.algorithm.distance.DistanceToPoint;
import org.locationtech.jts.algorithm.distance.PointPairDistance;
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.geom.GeometryFactory;
@@ -446,148 +443,15 @@ public class GeometryTools {
}
public static GeoPoint getLineStringCenter(String lineString) {
List<GeoPoint> points = getGeoPoints(lineString);
return getLineStringCenter(points);
public static double distanceToDouble(Geometry startGeoPoint, Geometry endGeoPoint) {
if (startGeoPoint != null && endGeoPoint != null) {
double d = startGeoPoint.distance(endGeoPoint);
return convertDistanceToDegree(d, startGeoPoint.getCoordinate().y);
}
return 0;
}
public static GeoPoint getLineStringCenter(List<GeoPoint> points) {
if (points != null && points.size() > 1) {
if (points.size() == 2) {
double x1 = points.get(0).getLongitude();
double y1 = points.get(0).getLatitude();
double x2 = points.get(1).getLongitude();
double y2 = points.get(1).getLatitude();
GeoPoint newPoint = new GeoPoint((y1 + y2) / 2, (x1 + x2) / 2);
return newPoint;
} else {
double total = 0;
ArrayList<Double> dList = new ArrayList<Double>();
for (int i = 0; i < points.size() - 1; i++) {
double lt = total;
double dis = distanceToDouble(points.get(i), points.get(i + 1));
dList.add(lt + dis);
total += dis;
}
total = total / 2;
for (int i = 0; i < dList.size(); i++) {
double a = dList.get(i);
double b = 0;
if (i > 0) {
b = dList.get(i - 1);
}
if (a > total) {
if (a - total < 4) {
return points.get(i);
}
double dx = (a - total) * 0.5 / (a - b);
GeoPoint point1 = points.get(i);
GeoPoint point2 = points.get(i + 1);
double x;
if (point1.getLongitude() < point2.getLongitude()) {
x = (point2.getLongitude() - point1.getLongitude()) * dx;
x = point2.getLongitude() - x;
} else {
x = (point1.getLongitude() - point2.getLongitude()) * dx;
x = point2.getLongitude() + x;
}
double y;
if (point1.getLatitude() > point2.getLatitude()) {
y = (point1.getLatitude() - point2.getLatitude()) * dx;
y = point2.getLatitude() + y;
} else {
y = (point2.getLatitude() - point1.getLatitude()) * dx;
y = point2.getLatitude() - y;
}
GeoPoint geoPoint = new GeoPoint(y, x);
return geoPoint;
} else {
if (total - a < 4) {
return points.get(i + 1);
}
}
}
}
}
return null;
}
public static GeoPoint getLineStringCenter(List<GeoPoint> points, int[] index) {
if (points != null && points.size() > 1) {
if (points.size() == 2) {
double x1 = points.get(0).getLongitude();
double y1 = points.get(0).getLatitude();
double x2 = points.get(1).getLongitude();
double y2 = points.get(1).getLatitude();
GeoPoint newPoint = new GeoPoint((y1 + y2) / 2, (x1 + x2) / 2);
if (index != null && index.length > 1) {
index[0] = 0;
index[1] = 1;
}
return newPoint;
} else {
double total = 0;
ArrayList<Double> dList = new ArrayList<Double>();
for (int i = 0; i < points.size() - 1; i++) {
double lt = total;
double dis = distance(points.get(i).toString(), points.get(i + 1).toString());
dList.add(lt + dis);
total += dis;
}
total = total / 2;
for (int i = 0; i < dList.size(); i++) {
double a = dList.get(i);
double b = 0;
if (i > 0) {
b = dList.get(i - 1);
}
if (a > total) {
if (a - total < 4) {
if (index != null && index.length > 1) {
index[0] = i;
index[1] = i + 1;
}
return points.get(i);
}
double dx = (a - total) * 0.5 / (a - b);
GeoPoint point1 = points.get(i);
GeoPoint point2 = points.get(i + 1);
double x;
if (point1.getLongitude() < point2.getLongitude()) {
x = (point2.getLongitude() - point1.getLongitude()) * dx;
x = point2.getLongitude() - x;
} else {
x = (point1.getLongitude() - point2.getLongitude()) * dx;
x = point2.getLongitude() + x;
}
double y;
if (point1.getLatitude() > point2.getLatitude()) {
y = (point1.getLatitude() - point2.getLatitude()) * dx;
y = point2.getLatitude() + y;
} else {
y = (point2.getLatitude() - point1.getLatitude()) * dx;
y = point2.getLatitude() - y;
}
GeoPoint geoPoint = new GeoPoint(y, x);
if (index != null && index.length > 1) {
index[0] = i;
index[1] = i + 1;
}
return geoPoint;
} else {
if (total - a < 4) {
if (index != null && index.length > 1) {
index[0] = i;
index[1] = i + 1;
}
return points.get(i + 1);
}
}
}
}
}
return null;
}
/**
* LINESTRING (116.4206899999999933 39.9620999999999995,
@@ -1160,39 +1024,6 @@ public class GeometryTools {
return null;
}
/**
* 点与几何最近点位置
*
* @param list
* @param geoPoint
* @return geopoint
* @author qiji
*/
public static GeoPoint getZuijinGeoPoint(List<GeoPoint> list, GeoPoint geoPoint) {//MapManager.getInstance().getMap().getMapCenterGeoLocation()屏幕中心点
if (list == null || list.size() == 0 || geoPoint == null)
return null;
double dis = 0;
GeoPoint geo = null;
for (GeoPoint geopoint : list) {
double disTemp = distanceToDouble(geoPoint, geopoint);
if (dis == 0 || dis < disTemp) {
dis = disTemp;
geo = geopoint;
}
}
return geo;
}
public static String GeometryFormatDouble5(String geometry) {
try {
@@ -1333,8 +1164,6 @@ public class GeometryTools {
}
public enum SNAP_TYPE {
/**
* 像素
@@ -1570,7 +1399,7 @@ public class GeometryTools {
*/
public static double getDistance(List<GeoPoint> list) {
if (list.size() < 2) {
return 0;
return -1;
}
double dis = 0;
for (int i = 0; i < list.size() - 1; i++) {
@@ -1618,6 +1447,12 @@ public class GeometryTools {
*/
private static final double EARTH_RADIUS = 6371000.0;
/**
* 距离转米
* @param distance
* @param latitude
* @return
*/
public static double convertDistanceToDegree(double distance, double latitude) {
double radianDistance = distance / EARTH_RADIUS;
double radianLatitude = Math.toRadians(latitude);
@@ -1669,28 +1504,13 @@ public class GeometryTools {
return point;
}
public static List<GeoPoint> pointToLineDistance(GeoPoint point, List<GeoPoint> pointList) {
Coordinate coordinate = geoPointToMercator(point);
Coordinate[] cs = new Coordinate[pointList.size()];
public static FootAndDistance pointToLineDistance(GeoPoint point, Geometry geometry) {
//定义垂线
FootAndDistance pointPairDistance = new FootAndDistance(point);
Coordinate coordinate = new Coordinate(point.getLongitude(), point.getLatitude());
pointPairDistance.computeDistance(geometry,coordinate);
for (int i = 0; i < pointList.size(); i++) {
Coordinate c = geoPointToMercator(pointList.get(i));
cs[i] = c;
}
GeometryFactory factory = new GeometryFactory();
LineString lineString = factory.createLineString(cs);
PointPairDistance pointPairDistance = new PointPairDistance();
DistanceToPoint.computeDistance(
lineString,
coordinate,
pointPairDistance
);
List newPoints = new ArrayList<GeoPoint>();
for (int i = 0; i < pointPairDistance.getCoordinates().length; i++) {
newPoints.add(mercatorToGeoPoint(pointPairDistance.getCoordinate(i)));
}
return newPoints;
return pointPairDistance;
}
}