[Update]Map按照新架构重构
This commit is contained in:
@@ -0,0 +1,135 @@
|
||||
package com.mogo.map.utils;
|
||||
|
||||
import com.mogo.eagle.core.data.map.MogoLatLng;
|
||||
import com.mogo.map.exception.MogoMapException;
|
||||
import com.zhidaoauto.map.sdk.open.camera.LatLngBounds;
|
||||
import com.zhidaoauto.map.sdk.open.query.LonLatPoint;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020-03-04
|
||||
* <p>
|
||||
* 地图工具类
|
||||
*/
|
||||
public class MogoMapUtils {
|
||||
|
||||
private static final String TAG = "MogoMapUtils";
|
||||
|
||||
public static LatLngBounds getLatLngBounds(MogoLatLng carPosition, List< MogoLatLng > lonLats, boolean lockCarPosition ) throws Exception {
|
||||
|
||||
if ( lonLats == null || lonLats.isEmpty() ) {
|
||||
throw new MogoMapException( "经纬度不能为null或空集合" );
|
||||
}
|
||||
LatLngBounds.Builder builder = new LatLngBounds.Builder();
|
||||
for ( MogoLatLng lonLat : lonLats ) {
|
||||
builder.include( ObjectUtils.fromMogo( lonLat ) );
|
||||
}
|
||||
if ( carPosition != null && !lockCarPosition ) {
|
||||
builder.include( ObjectUtils.fromMogo( carPosition ) );
|
||||
}
|
||||
LatLngBounds latLngBounds = builder.build();
|
||||
if ( !lockCarPosition ) {
|
||||
return latLngBounds;
|
||||
}
|
||||
|
||||
if ( carPosition == null ) {
|
||||
throw new MogoMapException( "自车位置经纬度信息不能为空" );
|
||||
}
|
||||
|
||||
if ( latLngBounds.getNortheast() == null && latLngBounds.getSouthwest() == null ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
double south = 0.0;
|
||||
double west = 0.0;
|
||||
|
||||
double east = 0.0;
|
||||
double north = 0.0;
|
||||
|
||||
double dLat = 0.0;
|
||||
double dLon = 0.0;
|
||||
|
||||
if ( latLngBounds.getNortheast() == null ) {
|
||||
dLat = Math.abs( carPosition.lat - latLngBounds.getSouthwest().getLatitude() );
|
||||
dLon = Math.abs( carPosition.lon - latLngBounds.getSouthwest().getLongitude() );
|
||||
} else if ( latLngBounds.getSouthwest() == null ) {
|
||||
dLat = Math.abs( carPosition.lat - latLngBounds.getNortheast().getLatitude() );
|
||||
dLon = Math.abs( carPosition.lon - latLngBounds.getNortheast().getLongitude() );
|
||||
} else {
|
||||
final double dLat1 = Math.abs( carPosition.lat - latLngBounds.getSouthwest().getLatitude() );
|
||||
final double dLon1 = Math.abs( carPosition.lon - latLngBounds.getSouthwest().getLongitude() );
|
||||
final double dLat2 = Math.abs( carPosition.lat - latLngBounds.getNortheast().getLatitude() );
|
||||
final double dLon2 = Math.abs( carPosition.lon - latLngBounds.getNortheast().getLongitude() );
|
||||
dLat = dLat1 > dLat2 ? dLat1 : dLat2;
|
||||
dLon = dLon1 > dLon2 ? dLon1 : dLon2;
|
||||
}
|
||||
|
||||
west = carPosition.lat - dLat;
|
||||
south = carPosition.lon + dLon;
|
||||
|
||||
east = carPosition.lat + dLat;
|
||||
north = carPosition.lon - dLon;
|
||||
|
||||
if ( south == 0.0 || west == 0.0 || east == 0.0 || north == 0.0 ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ( east < west ) {
|
||||
double tmp = east;
|
||||
east = west;
|
||||
west = tmp;
|
||||
}
|
||||
|
||||
if( north < south ){
|
||||
double tmp = north;
|
||||
north = south;
|
||||
south = tmp;
|
||||
}
|
||||
|
||||
return new LatLngBounds.Builder().include( new LonLatPoint( east, north ) ).include( new LonLatPoint( west, south ) ).build();
|
||||
}
|
||||
|
||||
public static float calculateLineDistance(LonLatPoint var0, LonLatPoint var1) {
|
||||
if (var0 != null && var1 != null) {
|
||||
try {
|
||||
double var2 = var0.getLongitude();
|
||||
double var4 = var0.getLatitude();
|
||||
double var6 = var1.getLongitude();
|
||||
double var8 = var1.getLatitude();
|
||||
var2 *= 0.01745329251994329D;
|
||||
var4 *= 0.01745329251994329D;
|
||||
var6 *= 0.01745329251994329D;
|
||||
var8 *= 0.01745329251994329D;
|
||||
double var10 = Math.sin(var2);
|
||||
double var12 = Math.sin(var4);
|
||||
double var14 = Math.cos(var2);
|
||||
double var16 = Math.cos(var4);
|
||||
double var18 = Math.sin(var6);
|
||||
double var20 = Math.sin(var8);
|
||||
double var22 = Math.cos(var6);
|
||||
double var24 = Math.cos(var8);
|
||||
double[] var28 = new double[3];
|
||||
double[] var29 = new double[3];
|
||||
var28[0] = var16 * var14;
|
||||
var28[1] = var16 * var10;
|
||||
var28[2] = var12;
|
||||
var29[0] = var24 * var22;
|
||||
var29[1] = var24 * var18;
|
||||
var29[2] = var20;
|
||||
return (float)(Math.asin(Math.sqrt((var28[0] - var29[0]) * (var28[0] - var29[0]) + (var28[1] - var29[1]) * (var28[1] - var29[1]) + (var28[2] - var29[2]) * (var28[2] - var29[2])) / 2.0D) * 1.27420015798544E7D);
|
||||
} catch (Throwable var26) {
|
||||
var26.printStackTrace();
|
||||
return 0.0F;
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
throw new Exception("非法坐标值");
|
||||
} catch (Exception var27) {
|
||||
var27.printStackTrace();
|
||||
return 0.0F;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,707 @@
|
||||
package com.mogo.map.utils;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
|
||||
import com.mogo.eagle.core.data.map.MogoLatLng;
|
||||
import com.mogo.eagle.core.data.map.MogoLocation;
|
||||
import com.mogo.eagle.core.data.traffic.TrafficData;
|
||||
import com.mogo.map.marker.MogoMarkerOptions;
|
||||
import com.mogo.map.overlay.MogoPolylineOptions;
|
||||
import com.mogo.map.search.geo.MogoGeocodeAddress;
|
||||
import com.mogo.map.search.geo.MogoGeocodeResult;
|
||||
import com.mogo.map.search.geo.MogoPoiItem;
|
||||
import com.mogo.map.search.geo.MogoRegeocodeAddress;
|
||||
import com.mogo.map.search.geo.MogoRegeocodeResult;
|
||||
import com.mogo.map.search.geo.query.MogoGeocodeQuery;
|
||||
import com.mogo.map.search.geo.query.MogoRegeocodeQuery;
|
||||
import com.mogo.map.search.inputtips.MogoTip;
|
||||
import com.mogo.map.search.inputtips.query.MogoInputtipsQuery;
|
||||
import com.mogo.map.search.poisearch.MogoPoiResult;
|
||||
import com.mogo.map.search.poisearch.MogoSearchBound;
|
||||
import com.mogo.map.search.poisearch.query.MogoPoiSearchQuery;
|
||||
import com.mogo.map.uicontroller.MapCameraPosition;
|
||||
import com.zhidaoauto.map.sdk.open.camera.CameraPosition;
|
||||
import com.zhidaoauto.map.sdk.open.marker.BitmapDescriptor;
|
||||
import com.zhidaoauto.map.sdk.open.marker.BitmapDescriptorFactory;
|
||||
import com.zhidaoauto.map.sdk.open.marker.MarkerOptions;
|
||||
import com.zhidaoauto.map.sdk.open.marker.MarkerSimpleData;
|
||||
import com.zhidaoauto.map.sdk.open.poyline.PolylineOptions;
|
||||
import com.zhidaoauto.map.sdk.open.query.GeocodeAddress;
|
||||
import com.zhidaoauto.map.sdk.open.query.GeocodeQuery;
|
||||
import com.zhidaoauto.map.sdk.open.query.GeocodeResult;
|
||||
import com.zhidaoauto.map.sdk.open.query.InputtipsQuery;
|
||||
import com.zhidaoauto.map.sdk.open.query.LonLatPoint;
|
||||
import com.zhidaoauto.map.sdk.open.query.PoiItem;
|
||||
import com.zhidaoauto.map.sdk.open.query.PoiSearchItem;
|
||||
import com.zhidaoauto.map.sdk.open.query.PoiSearchResult;
|
||||
import com.zhidaoauto.map.sdk.open.query.Query;
|
||||
import com.zhidaoauto.map.sdk.open.query.RegeocodeAddress;
|
||||
import com.zhidaoauto.map.sdk.open.query.RegeocodeQuery;
|
||||
import com.zhidaoauto.map.sdk.open.query.RegeocodeResult;
|
||||
import com.zhidaoauto.map.sdk.open.query.SearchBound;
|
||||
import com.zhidaoauto.map.sdk.open.query.Tip;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import mogo.telematics.pad.MessagePad;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2019-12-18
|
||||
* <p>
|
||||
* 业务对象和实际对象转换
|
||||
*/
|
||||
public class ObjectUtils {
|
||||
|
||||
public static MarkerOptions fromMogo(MogoMarkerOptions opt) {
|
||||
|
||||
if (opt == null) {
|
||||
return null;
|
||||
}
|
||||
ArrayList<BitmapDescriptor> descriptors = new ArrayList<>();
|
||||
final ArrayList<Bitmap> icons = opt.getIcons();
|
||||
if (icons != null && !icons.isEmpty()) {
|
||||
for (Bitmap icon : icons) {
|
||||
if (icon == null || icon.isRecycled()) {
|
||||
continue;
|
||||
}
|
||||
descriptors.add(new BitmapDescriptor(icon));
|
||||
}
|
||||
}
|
||||
|
||||
MarkerOptions markerOptions = new MarkerOptions()
|
||||
.setGps(opt.isGps())
|
||||
.position(new LonLatPoint(opt.getLongitude(), opt.getLatitude()))
|
||||
.anchor(opt.getU(), opt.getV())
|
||||
.icons(descriptors)
|
||||
.period(opt.getPeriod())
|
||||
.controlAngle(opt.isControlAngle())
|
||||
.rotateAngle(opt.getRotate())
|
||||
.setFlat(opt.isFlat())
|
||||
.visible(opt.isVisible())
|
||||
.infoWindowEnable(opt.isInifoWindowEnable())
|
||||
.scale(opt.getScale())
|
||||
.alpha(opt.getAlpha())
|
||||
.setInfoWindowOffset(opt.getOffsetX(), opt.getOffsetY())
|
||||
.zIndex(opt.getzIndex());
|
||||
|
||||
try {
|
||||
if (!TextUtils.isEmpty(opt.getAnchorColor())) {
|
||||
Color.parseColor(opt.getAnchorColor());
|
||||
markerOptions.anchorColor(opt.getAnchorColor());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
//e.printStackTrace();
|
||||
}
|
||||
markerOptions.vrEnable(opt.is3DMode());
|
||||
if (!TextUtils.isEmpty(opt.getResName())) {
|
||||
markerOptions.setMarkerIconName(opt.getResName());
|
||||
} else {
|
||||
BitmapDescriptor descriptor = getBitmapDescriptorFromMogo(opt);
|
||||
if (descriptor != null) {
|
||||
markerOptions.markerIcon(descriptor);
|
||||
}
|
||||
if (opt.getIcon3DRes() != 0) {
|
||||
markerOptions.marker3DIcon(opt.getIcon3DRes());
|
||||
}
|
||||
}
|
||||
if (!TextUtils.isEmpty(opt.getTitle())) {
|
||||
markerOptions.title(opt.getTitle());
|
||||
}
|
||||
if (!TextUtils.isEmpty(opt.getSnippet())) {
|
||||
markerOptions.snippet(opt.getSnippet());
|
||||
}
|
||||
return markerOptions;
|
||||
}
|
||||
|
||||
public static MarkerSimpleData fromTrafficData(MessagePad.TrackedObject trafficData) {
|
||||
if (trafficData == null) {
|
||||
return null;
|
||||
}
|
||||
MarkerSimpleData markerOptions = null;
|
||||
try {
|
||||
markerOptions = new MarkerSimpleData();
|
||||
markerOptions.setId(trafficData.getUuid());
|
||||
markerOptions.setMarkerType(trafficData.getType());
|
||||
markerOptions.setRotateAngle((float) trafficData.getHeading());
|
||||
markerOptions.setLat(trafficData.getLatitude());
|
||||
markerOptions.setLon(trafficData.getLongitude());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return markerOptions;
|
||||
}
|
||||
|
||||
private static BitmapDescriptor getBitmapDescriptorFromMogo(MogoMarkerOptions options) {
|
||||
if (options == null) {
|
||||
return null;
|
||||
}
|
||||
Bitmap icon = options.getIcon();
|
||||
if (icon != null) {
|
||||
return BitmapDescriptorFactory.INSTANCE.fromBitmap(icon);
|
||||
}
|
||||
View view = options.getIconView();
|
||||
if (view != null) {
|
||||
return BitmapDescriptorFactory.INSTANCE.fromView(view);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public static MogoLocation fromLocation(com.zhidaoauto.map.sdk.open.location.MogoLocation aLocation) {
|
||||
if (aLocation == null) {
|
||||
return null;
|
||||
}
|
||||
MogoLocation location = new MogoLocation();
|
||||
location.setLocType(1); // 定位类型
|
||||
location.setSatellite(4);
|
||||
location.setSpeed(aLocation.getSpeed());
|
||||
location.setLatitude(aLocation.getLat());
|
||||
location.setLongitude(aLocation.getLon());
|
||||
location.setAltitude(aLocation.getAltitude());
|
||||
location.setBearing((float) aLocation.getHeading());
|
||||
location.setCityCode(aLocation.getCityCode());
|
||||
location.setCityName(aLocation.getCity());
|
||||
location.setProvider(aLocation.getProvider());
|
||||
location.setAddress(aLocation.getAddress());
|
||||
location.setDistrict(aLocation.getDistrict());
|
||||
location.setProvince(aLocation.getProvince());
|
||||
location.setAdCode(aLocation.getAdCode());
|
||||
// location.setAccuracy( aLocation.getAccuracy() );
|
||||
// location.setTime( aLocation.getTime() );
|
||||
// location.setLocationDetail( aLocation.getLocationDetail() );
|
||||
// location.setPoiName( aLocation.getPoiName() );
|
||||
// location.setAoiName( aLocation.getAoiName() );
|
||||
// location.setErrCode( aLocation.getErrorCode() );
|
||||
// location.setErrInfo( aLocation.getErrorInfo() );
|
||||
// location.setStreetNum( aLocation.getStreetNum() );
|
||||
// location.setDescription( aLocation.getDescription() );
|
||||
// location.setBuildingId( aLocation.getBuildingId() );
|
||||
// location.setFloor( aLocation.getFloor() );
|
||||
// location.setGpsAccuracyStatus( aLocation.getGpsAccuracyStatus() );
|
||||
return location;
|
||||
}
|
||||
|
||||
public static LonLatPoint fromMogo(MogoLatLng latLng) {
|
||||
if (latLng == null) {
|
||||
return null;
|
||||
}
|
||||
return new LonLatPoint(latLng.lon, latLng.lat);
|
||||
}
|
||||
|
||||
// public static NaviLatLng fromMogoAsNavi( MogoLatLng latLng ) {
|
||||
// if ( latLng == null ) {
|
||||
// return null;
|
||||
// }
|
||||
// return new NaviLatLng( latLng.lat, latLng.lng );
|
||||
// }
|
||||
|
||||
// public static LatLng fromMogo2( MogoLatLng latLng ) {
|
||||
// if ( latLng == null ) {
|
||||
// return null;
|
||||
// }
|
||||
// return new LatLng( latLng.lat, latLng.lng );
|
||||
// }
|
||||
|
||||
public static MogoLatLng fromAMap(LonLatPoint point) {
|
||||
if (point == null) {
|
||||
return null;
|
||||
}
|
||||
return new MogoLatLng(point.getLatitude(), point.getLongitude());
|
||||
}
|
||||
|
||||
// public static MogoLatLng CameraPositionfromAMap( LatLng point ) {
|
||||
// if ( point == null ) {
|
||||
// return null;
|
||||
// }
|
||||
// return new MogoLatLng( point.latitude, point.longitude );
|
||||
// }
|
||||
|
||||
public static GeocodeQuery fromMogo(MogoGeocodeQuery query) {
|
||||
if (query == null) {
|
||||
return null;
|
||||
}
|
||||
GeocodeQuery q = new GeocodeQuery(query.getLocationName(), query.getCity());
|
||||
return q;
|
||||
}
|
||||
|
||||
public static RegeocodeQuery fromMogo(MogoRegeocodeQuery query) {
|
||||
if (query == null) {
|
||||
return null;
|
||||
}
|
||||
RegeocodeQuery q = new RegeocodeQuery(fromMogo(query.getPoint()), 1000);
|
||||
return q;
|
||||
}
|
||||
|
||||
// public static MogoAoiItem fromAMap( AoiItem amapItem ) {
|
||||
// if ( amapItem == null ) {
|
||||
// return null;
|
||||
// }
|
||||
// MogoAoiItem mogoAoiItem = new MogoAoiItem();
|
||||
// mogoAoiItem.setAdCode( amapItem.getAdCode() );
|
||||
// mogoAoiItem.setAoiArea( amapItem.getAoiArea() );
|
||||
// mogoAoiItem.setAoiCenterPoint( fromAMap( amapItem.getAoiCenterPoint() ) );
|
||||
// mogoAoiItem.setAoiId( amapItem.getAoiId() );
|
||||
// mogoAoiItem.setAoiName( amapItem.getAoiName() );
|
||||
// return mogoAoiItem;
|
||||
// }
|
||||
//
|
||||
// public static MogoBusinessArea fromAMap( BusinessArea amapItem ) {
|
||||
// if ( amapItem == null ) {
|
||||
// return null;
|
||||
// }
|
||||
// MogoBusinessArea mogoBusinessArea = new MogoBusinessArea();
|
||||
// mogoBusinessArea.setCenterPoint( fromAMap( amapItem.getCenterPoint() ) );
|
||||
// mogoBusinessArea.setName( amapItem.getName() );
|
||||
// return mogoBusinessArea;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// public static MogoCrossroad fromAMap( Crossroad amapItem ) {
|
||||
// if ( amapItem == null ) {
|
||||
// return null;
|
||||
// }
|
||||
// MogoCrossroad mogoCrossroad = new MogoCrossroad();
|
||||
// mogoCrossroad.setDirection( amapItem.getDirection() );
|
||||
// mogoCrossroad.setDistance( amapItem.getDistance() );
|
||||
// mogoCrossroad.setFirstRoadId( amapItem.getFirstRoadId() );
|
||||
// mogoCrossroad.setFirstRoadName( amapItem.getFirstRoadName() );
|
||||
// mogoCrossroad.setSecondRoadId( amapItem.getSecondRoadId() );
|
||||
// mogoCrossroad.setSecondRoadName( amapItem.getSecondRoadName() );
|
||||
// return mogoCrossroad;
|
||||
// }
|
||||
|
||||
public static MogoGeocodeAddress fromAMap(GeocodeAddress address) {
|
||||
if (address == null) {
|
||||
return null;
|
||||
}
|
||||
MogoGeocodeAddress mogoGeocodeAddress = new MogoGeocodeAddress();
|
||||
mogoGeocodeAddress.setAdcode(address.getAdcode());
|
||||
mogoGeocodeAddress.setBuilding(address.getBuilding());
|
||||
mogoGeocodeAddress.setCity(address.getCity());
|
||||
mogoGeocodeAddress.setDistrict(address.getDistrict());
|
||||
mogoGeocodeAddress.setFormatAddress(address.getFormatAddress());
|
||||
mogoGeocodeAddress.setLatlng(fromAMap(address.getLonlat()));
|
||||
mogoGeocodeAddress.setLevel(address.getLevel());
|
||||
mogoGeocodeAddress.setNeighborhood(address.getNeighborhood());
|
||||
mogoGeocodeAddress.setProvince(address.getProvince());
|
||||
mogoGeocodeAddress.setTownship(address.getTownship());
|
||||
return mogoGeocodeAddress;
|
||||
}
|
||||
|
||||
public static MogoGeocodeResult fromAMap(GeocodeResult result) {
|
||||
if (result == null || result.getGeocodeAddressList() == null) {
|
||||
return null;
|
||||
}
|
||||
MogoGeocodeResult mogoGeocodeResult = new MogoGeocodeResult();
|
||||
final List<MogoGeocodeAddress> addresses = new ArrayList<>();
|
||||
List<GeocodeAddress> list = result.getGeocodeAddressList();
|
||||
for (GeocodeAddress geocodeAddress : list) {
|
||||
final MogoGeocodeAddress mogoGeocodeAddress = fromAMap(geocodeAddress);
|
||||
if (mogoGeocodeAddress != null) {
|
||||
addresses.add(mogoGeocodeAddress);
|
||||
}
|
||||
}
|
||||
|
||||
mogoGeocodeResult.setAddresses(addresses);
|
||||
return mogoGeocodeResult;
|
||||
}
|
||||
|
||||
// public static MogoIndoorData fromAMap( IndoorData data ) {
|
||||
// if ( data == null ) {
|
||||
// return null;
|
||||
// }
|
||||
// MogoIndoorData mogoIndoorData = new MogoIndoorData();
|
||||
// mogoIndoorData.setFloor( data.getFloor() );
|
||||
// mogoIndoorData.setFloorName( data.getFloorName() );
|
||||
// mogoIndoorData.setPoiId( data.getPoiId() );
|
||||
// return mogoIndoorData;
|
||||
// }
|
||||
//
|
||||
// public static MogoPhoto fromAMap( Photo photo ) {
|
||||
// if ( photo == null ) {f
|
||||
// return null;
|
||||
// }
|
||||
// MogoPhoto mogoPhoto = new MogoPhoto();
|
||||
// mogoPhoto.setTitle( photo.getTitle() );
|
||||
// mogoPhoto.setUrl( photo.getUrl() );
|
||||
// return mogoPhoto;
|
||||
// }
|
||||
//
|
||||
// public static MogoPoiItemExtension fromAMap( PoiItemExtension poiItemExtension ) {
|
||||
// if ( poiItemExtension == null ) {
|
||||
// return null;
|
||||
// }
|
||||
// MogoPoiItemExtension mogoPoiItemExtension = new MogoPoiItemExtension();
|
||||
// mogoPoiItemExtension.setOpentime( poiItemExtension.getOpentime() );
|
||||
// mogoPoiItemExtension.setRating( poiItemExtension.getmRating() );
|
||||
// return mogoPoiItemExtension;
|
||||
// }
|
||||
//
|
||||
// public static MogoRegeocodeRoad fromAMap( RegeocodeRoad regeocodeRoad ) {
|
||||
// if ( regeocodeRoad == null ) {
|
||||
// return null;
|
||||
// }
|
||||
// MogoRegeocodeRoad mogoRegeocodeRoad = new MogoRegeocodeRoad();
|
||||
// mogoRegeocodeRoad.setDirection( regeocodeRoad.getDirection() );
|
||||
// mogoRegeocodeRoad.setDistance( regeocodeRoad.getDistance() );
|
||||
// mogoRegeocodeRoad.setId( regeocodeRoad.getId() );
|
||||
// mogoRegeocodeRoad.setName( regeocodeRoad.getName() );
|
||||
// mogoRegeocodeRoad.setPoint( fromAMap( regeocodeRoad.getLatLngPoint() ) );
|
||||
// return mogoRegeocodeRoad;
|
||||
// }
|
||||
//
|
||||
// public static MogoStreetNumber fromAMap( StreetNumber streetNumber ) {
|
||||
// if ( streetNumber == null ) {
|
||||
// return null;
|
||||
// }
|
||||
// MogoStreetNumber mogoStreetNumber = new MogoStreetNumber();
|
||||
// mogoStreetNumber.setDirection( streetNumber.getDirection() );
|
||||
// mogoStreetNumber.setDistance( streetNumber.getDistance() );
|
||||
// mogoStreetNumber.setLatLonPoint( fromAMap( streetNumber.getLatLonPoint() ) );
|
||||
// mogoStreetNumber.setNumber( streetNumber.getNumber() );
|
||||
// mogoStreetNumber.setStreet( streetNumber.getStreet() );
|
||||
// return mogoStreetNumber;
|
||||
// }
|
||||
|
||||
// public static MogoSubPoiItem fromAMap( SubPoiItem subPoiItem ) {
|
||||
// if ( subPoiItem == null ) {
|
||||
// return null;
|
||||
// }
|
||||
// MogoSubPoiItem mogoSubPoiItem = new MogoSubPoiItem();
|
||||
// mogoSubPoiItem.setDistance( subPoiItem.getDistance() );
|
||||
// mogoSubPoiItem.setPoiId( subPoiItem.getPoiId() );
|
||||
// mogoSubPoiItem.setPoint( fromAMap( subPoiItem.getLatLonPoint() ) );
|
||||
// mogoSubPoiItem.setSnippet( subPoiItem.getSnippet() );
|
||||
// mogoSubPoiItem.setSubName( mogoSubPoiItem.getSubName() );
|
||||
// mogoSubPoiItem.setSubTypeDes( mogoSubPoiItem.getSubTypeDes() );
|
||||
// mogoSubPoiItem.setTitle( mogoSubPoiItem.getTitle() );
|
||||
// return mogoSubPoiItem;
|
||||
// }
|
||||
|
||||
public static MogoPoiItem fromAMap(PoiItem poiItem) {
|
||||
if (poiItem == null) {
|
||||
return null;
|
||||
}
|
||||
MogoPoiItem mogoPoiItem = new MogoPoiItem();
|
||||
mogoPoiItem.setAdCode(poiItem.getAdCode());
|
||||
mogoPoiItem.setAdName(poiItem.getAdName());
|
||||
mogoPoiItem.setBusinessArea(poiItem.getBusinessArea());
|
||||
mogoPoiItem.setCityCode(poiItem.getCityCode());
|
||||
mogoPoiItem.setCityName(poiItem.getCityName());
|
||||
mogoPoiItem.setDirection(poiItem.getDirection());
|
||||
mogoPoiItem.setDistance(poiItem.getDistance());
|
||||
mogoPoiItem.setEmail(poiItem.getEmail());
|
||||
mogoPoiItem.setEnter(fromAMap(poiItem.getEnter()));
|
||||
mogoPoiItem.setExit(fromAMap(poiItem.getExit()));
|
||||
// mogoPoiItem.setIndoorData( fromAMap( poiItem.getIndoorData() ) );
|
||||
mogoPoiItem.setParkingType(poiItem.getParkingType());
|
||||
// mogoPoiItem.setIndoorMap( poiItem.isIndoorMap() );
|
||||
// if ( poiItem.getPhotos() != null ) {
|
||||
// List< MogoPhoto > mogoPhotos = new ArrayList<>();
|
||||
// for ( Photo photo : poiItem.getPhotos() ) {
|
||||
// MogoPhoto mogoPhoto = fromAMap( photo );
|
||||
// if ( mogoPhoto != null ) {
|
||||
// mogoPhotos.add( mogoPhoto );
|
||||
// }
|
||||
// }
|
||||
// mogoPoiItem.setPhotos( mogoPhotos );
|
||||
// }
|
||||
// mogoPoiItem.setPoiExtension( fromAMap( poiItem.getPoiExtension() ) );
|
||||
mogoPoiItem.setPoiId(poiItem.getPoiId());
|
||||
mogoPoiItem.setPoint(fromAMap(poiItem.getLonLatPoint()));
|
||||
mogoPoiItem.setPostcode(poiItem.getPostcode());
|
||||
mogoPoiItem.setProvinceCode(poiItem.getProvinceCode());
|
||||
mogoPoiItem.setProvinceName(poiItem.getProvinceName());
|
||||
mogoPoiItem.setShopID(poiItem.getShopID());
|
||||
mogoPoiItem.setSnippet(poiItem.getSnippet());
|
||||
// if ( poiItem.getSubPois() != null ) {
|
||||
// List< MogoSubPoiItem > mogoSubPoiItems = new ArrayList<>();
|
||||
// for ( SubPoiItem subPois : poiItem.getSubPois() ) {
|
||||
// MogoSubPoiItem mogoSubPoiItem = fromAMap( subPois );
|
||||
// if ( mogoPoiItem != null ) {
|
||||
// mogoSubPoiItems.add( mogoSubPoiItem );
|
||||
// }
|
||||
// }
|
||||
// mogoPoiItem.setSubPois( mogoSubPoiItems );
|
||||
// }
|
||||
mogoPoiItem.setTel(poiItem.getTel());
|
||||
mogoPoiItem.setTypeCode(poiItem.getTypeCode());
|
||||
mogoPoiItem.setTitle(poiItem.getTitle());
|
||||
mogoPoiItem.setTypeDes(poiItem.getTypeDes());
|
||||
mogoPoiItem.setWebsite(poiItem.getWebsite());
|
||||
return mogoPoiItem;
|
||||
}
|
||||
|
||||
public static MogoRegeocodeAddress fromAMap(RegeocodeAddress regeocodeAddress) {
|
||||
if (regeocodeAddress == null) {
|
||||
return null;
|
||||
}
|
||||
MogoRegeocodeAddress mogoRegeocodeAddress = new MogoRegeocodeAddress();
|
||||
mogoRegeocodeAddress.setAdCode(regeocodeAddress.getAdCode());
|
||||
// if ( regeocodeAddress.getAois() != null ) {
|
||||
// List< MogoAoiItem > items = new ArrayList<>();
|
||||
// for ( AoiItem aois : regeocodeAddress.getAois() ) {
|
||||
// final MogoAoiItem mogoAoiItem = fromAMap( aois );
|
||||
// if ( mogoAoiItem != null ) {
|
||||
// items.add( mogoAoiItem );
|
||||
// }
|
||||
// }
|
||||
// mogoRegeocodeAddress.setAois( items );
|
||||
// }
|
||||
|
||||
mogoRegeocodeAddress.setBuilding(regeocodeAddress.getBuilding());
|
||||
// if ( regeocodeAddress.getBusinessAreas() != null ) {
|
||||
// List< MogoBusinessArea > mogoBusinessAreas = new ArrayList<>();
|
||||
// for ( BusinessArea businessArea : regeocodeAddress.getBusinessAreas() ) {
|
||||
// MogoBusinessArea mogoBusinessArea = fromAMap( businessArea );
|
||||
// if ( mogoBusinessArea != null ) {
|
||||
// mogoBusinessAreas.add( mogoBusinessArea );
|
||||
// }
|
||||
// }
|
||||
// mogoRegeocodeAddress.setBusinessAreas( mogoBusinessAreas );
|
||||
// }
|
||||
|
||||
mogoRegeocodeAddress.setCity(regeocodeAddress.getCity());
|
||||
mogoRegeocodeAddress.setCityCode(regeocodeAddress.getCityCode());
|
||||
mogoRegeocodeAddress.setCountry(regeocodeAddress.getCountry());
|
||||
// if ( regeocodeAddress.getCrossroads() != null ) {
|
||||
// List< MogoCrossroad > mogoCrossroads = new ArrayList<>();
|
||||
// for ( Crossroad crossroad : regeocodeAddress.getCrossroads() ) {
|
||||
//
|
||||
// MogoCrossroad mogoCrossroad = fromAMap( crossroad );
|
||||
// if ( mogoCrossroad != null ) {
|
||||
// mogoCrossroads.add( mogoCrossroad );
|
||||
// }
|
||||
// }
|
||||
// mogoRegeocodeAddress.setCrossroads( mogoCrossroads );
|
||||
// }
|
||||
mogoRegeocodeAddress.setDistrict(regeocodeAddress.getDistrict());
|
||||
mogoRegeocodeAddress.setFormatAddress(regeocodeAddress.getFormatAddress());
|
||||
mogoRegeocodeAddress.setNeighborhood(regeocodeAddress.getNeighborhood());
|
||||
if (regeocodeAddress.getPoiList() != null) {
|
||||
List<MogoPoiItem> mogoPoiItems = new ArrayList<>();
|
||||
List<PoiItem> list = regeocodeAddress.getPoiList();
|
||||
for (PoiItem pois : list) {
|
||||
MogoPoiItem mogoPoiItem = fromAMap(pois);
|
||||
mogoPoiItems.add(mogoPoiItem);
|
||||
}
|
||||
mogoRegeocodeAddress.setPois(mogoPoiItems);
|
||||
}
|
||||
mogoRegeocodeAddress.setProvince(regeocodeAddress.getProvince());
|
||||
// if ( regeocodeAddress.getRoads() != null ) {
|
||||
// List< MogoRegeocodeRoad > mogoRegeocodeRoads = new ArrayList<>();
|
||||
// for ( RegeocodeRoad road : regeocodeAddress.getRoads() ) {
|
||||
// MogoRegeocodeRoad mogoRegeocodeRoad = fromAMap( road );
|
||||
// if ( mogoRegeocodeRoad != null ) {
|
||||
// mogoRegeocodeRoads.add( mogoRegeocodeRoad );
|
||||
// }
|
||||
// }
|
||||
// mogoRegeocodeAddress.setRoads( mogoRegeocodeRoads );
|
||||
// }
|
||||
// mogoRegeocodeAddress.setStreetNumber( fromAMap( regeocodeAddress.getStreetNumber() ) );
|
||||
mogoRegeocodeAddress.setTowncode(regeocodeAddress.getTowncode());
|
||||
mogoRegeocodeAddress.setTownship(regeocodeAddress.getTownship());
|
||||
return mogoRegeocodeAddress;
|
||||
}
|
||||
|
||||
public static MogoRegeocodeResult fromAMap(RegeocodeResult regeocodeResult) {
|
||||
if (regeocodeResult == null) {
|
||||
return null;
|
||||
}
|
||||
MogoRegeocodeResult mogoRegeocodeResult = new MogoRegeocodeResult();
|
||||
mogoRegeocodeResult.setRegeocodeAddress(fromAMap(regeocodeResult.getRegeocodeAddress()));
|
||||
return mogoRegeocodeResult;
|
||||
}
|
||||
|
||||
public static InputtipsQuery fromMogo(MogoInputtipsQuery query) {
|
||||
if (query == null) {
|
||||
return null;
|
||||
}
|
||||
InputtipsQuery inputtipsQuery = new InputtipsQuery(query.getKeyword(), query.getCity());
|
||||
inputtipsQuery.setCityLimit(query.isCityLimit());
|
||||
inputtipsQuery.setLocation(fromMogo(query.getLocation()));
|
||||
inputtipsQuery.setType(query.getType());
|
||||
return inputtipsQuery;
|
||||
}
|
||||
|
||||
public static MogoTip fromAMap(Tip tip) {
|
||||
if (tip == null) {
|
||||
return null;
|
||||
}
|
||||
MogoTip mogoTip = new MogoTip();
|
||||
mogoTip.setAdCode(tip.getAdcode());
|
||||
mogoTip.setAddress(tip.getAddress());
|
||||
mogoTip.setDistrict(tip.getDistrict());
|
||||
mogoTip.setName(tip.getName());
|
||||
mogoTip.setPoiID(tip.getPoiID());
|
||||
mogoTip.setPoint(fromAMap(tip.getLatPoint()));
|
||||
mogoTip.setTypeCode(tip.getTypeCode());
|
||||
return mogoTip;
|
||||
}
|
||||
|
||||
// public static MogoPoi fromAMap( Poi poi ) {
|
||||
// if ( poi == null ) {
|
||||
// return null;
|
||||
// }
|
||||
// MogoPoi mogoPoi = new MogoPoi();
|
||||
// mogoPoi.setCoordinate( fromAMap( poi.getCoordinate() ) );
|
||||
// mogoPoi.setName( poi.getName() );
|
||||
// mogoPoi.setPoiId( poi.getPoiId() );
|
||||
// return mogoPoi;
|
||||
// }
|
||||
|
||||
public static MogoPoiSearchQuery fromAMap(Query query) {
|
||||
if (query == null) {
|
||||
return null;
|
||||
}
|
||||
MogoPoiSearchQuery mogoPoiSearchQuery = new MogoPoiSearchQuery(query.getKeyword(), query.getCategory(), query.getCity());
|
||||
// mogoPoiSearchQuery.setBuilding( query.getBuilding() );
|
||||
mogoPoiSearchQuery.setCityLimit(query.getCityLimit());
|
||||
mogoPoiSearchQuery.setDistanceSort(query.getDistanceSort());
|
||||
mogoPoiSearchQuery.setLocation(fromAMap(query.getLocation()));
|
||||
mogoPoiSearchQuery.setPageNum(query.getPageNum());
|
||||
mogoPoiSearchQuery.setPageSize(query.getPageSize());
|
||||
return mogoPoiSearchQuery;
|
||||
}
|
||||
|
||||
public static Query fromMogo(MogoPoiSearchQuery query) {
|
||||
if (query == null || query.getQuery() == null) {
|
||||
return null;
|
||||
}
|
||||
Query psq = new Query(query.getQuery(), "", "");
|
||||
String category = getCategory(query.getQuery());
|
||||
if (!category.equals(""))
|
||||
psq = new Query("", "", getCategory(query.getQuery()));
|
||||
// psq.setBuilding( query.getBuilding() );
|
||||
psq.setCityLimit(query.isCityLimit());
|
||||
psq.setDistanceSort(query.isDistanceSort());
|
||||
psq.setLocation(fromMogo(query.getLocation()));
|
||||
psq.setPageNum(query.getPageNum());
|
||||
psq.setPageSize(query.getPageSize());
|
||||
return psq;
|
||||
}
|
||||
|
||||
public static MogoSearchBound fromAMap(SearchBound bound) {
|
||||
if (bound == null) {
|
||||
return null;
|
||||
}
|
||||
if (bound.getShape() == SearchBound.BOUND_SHAPE) {
|
||||
return new MogoSearchBound(fromAMap(bound.getCenter()), bound.getRange(), bound.isDistanceSort());
|
||||
} else if (bound.getShape() == SearchBound.POLYGON_SHAPE) {
|
||||
return new MogoSearchBound(fromAMap(bound.getPolyGonList()));
|
||||
} else if (bound.getShape() == SearchBound.RECTANGLE_SHAPE) {
|
||||
return new MogoSearchBound(fromAMap(bound.getLowerLeft()), fromAMap(bound.getUpperRight()));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static List<MogoLatLng> fromAMap(List<LonLatPoint> latLngs) {
|
||||
if (latLngs == null) {
|
||||
return null;
|
||||
}
|
||||
List<MogoLatLng> result = new ArrayList<>(latLngs.size());
|
||||
for (LonLatPoint latLng : latLngs) {
|
||||
result.add(fromAMap(latLng));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static List<LonLatPoint> fromMogo(List<MogoLatLng> latLngs) {
|
||||
if (latLngs == null) {
|
||||
return null;
|
||||
}
|
||||
List<LonLatPoint> result = new ArrayList<>(latLngs.size());
|
||||
for (MogoLatLng latLng : latLngs) {
|
||||
result.add(fromMogo(latLng));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public static SearchBound fromMogo(MogoSearchBound bound) {
|
||||
if (bound == null) {
|
||||
return null;
|
||||
}
|
||||
if (bound.getShape() == MogoSearchBound.SHAPE_BOUND) {
|
||||
return new SearchBound(fromMogo(bound.getCenterPoint()), bound.getRadiusInMeters(), bound.isDistanceSort());
|
||||
} else if (bound.getShape() == MogoSearchBound.SHAPE_POLYGON) {
|
||||
return new SearchBound(fromMogo(bound.getPolyGonList()));
|
||||
} else if (bound.getShape() == MogoSearchBound.SHAPE_RECTANGLE) {
|
||||
return new SearchBound(fromMogo(bound.getLowerLeft()), fromMogo(bound.getUpperRight()));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static MogoPoiResult fromAMap(PoiSearchResult result) {
|
||||
if (result == null) {
|
||||
return null;
|
||||
}
|
||||
MogoPoiResult mogoPoiResult = new MogoPoiResult();
|
||||
if (result.getItems() != null) {
|
||||
final List<PoiSearchItem> poiItems = result.getItems();
|
||||
final ArrayList<MogoPoiItem> mogoPoiItems = new ArrayList<>(poiItems.size());
|
||||
for (PoiSearchItem poiItem : poiItems) {
|
||||
mogoPoiItems.add(fromAMap(poiItem.getPoi()));
|
||||
}
|
||||
mogoPoiResult.setPois(mogoPoiItems);
|
||||
}
|
||||
return mogoPoiResult;
|
||||
}
|
||||
|
||||
public static PolylineOptions fromMogo(MogoPolylineOptions options) {
|
||||
if (options == null) {
|
||||
return null;
|
||||
}
|
||||
PolylineOptions target = new PolylineOptions();
|
||||
target.setGps(options.gps());
|
||||
if (options.getPoints() != null) {
|
||||
List<LonLatPoint> points = new ArrayList<>();
|
||||
for (MogoLatLng point : options.getPoints()) {
|
||||
points.add(fromMogo(point));
|
||||
}
|
||||
target.lonLatPoints(points);
|
||||
}
|
||||
target.setLineWidth(options.getWidth());
|
||||
target.zIndex(options.getZIndex());
|
||||
target.setColor(options.getColor());
|
||||
target.useGradient(options.isGradient());
|
||||
if (options.getColorValues() != null) {
|
||||
target.colorValues(options.getColorValues());
|
||||
}
|
||||
// target.transparency( options.getTransparency() );
|
||||
// target.aboveMaskLayer( options.isAboveMaskLayer() );
|
||||
// target.lineCapType( PolylineOptions.LineCapType.LineCapRound );
|
||||
// target.lineJoinType( PolylineOptions.LineJoinType.LineJoinRound );
|
||||
// target.setDottedLineType( PolylineOptions.DOTTEDLINE_TYPE_CIRCLE );
|
||||
return target;
|
||||
}
|
||||
|
||||
|
||||
public static MapCameraPosition fromAMap(CameraPosition position) {
|
||||
if (position == null) {
|
||||
return null;
|
||||
}
|
||||
return new MapCameraPosition(fromAMap(position.getTarget()), position.getBearing(), position.getTilt(), position.getZoom());
|
||||
}
|
||||
|
||||
private static String getCategory(String key) {
|
||||
String category = "";
|
||||
if (key.equals("加油站")) {
|
||||
category = "6";
|
||||
} else if (key.equals("停车场")) {
|
||||
category = "12";
|
||||
} else if (key.equals("餐馆")) {
|
||||
category = "22";
|
||||
} else if (key.equals("洗车")) {
|
||||
category = "8";
|
||||
} else if (key.equals("厕所")) {
|
||||
|
||||
}
|
||||
return category;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
package com.mogo.map.utils;
|
||||
|
||||
import com.mogo.cloud.commons.utils.CoordinateUtils;
|
||||
import com.mogo.eagle.core.data.map.MogoLatLng;
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.Logger;
|
||||
import com.zhidaoauto.map.sdk.open.query.LonLatPoint;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 点之间插值工具类
|
||||
*
|
||||
* @author tongchenfei
|
||||
*/
|
||||
public class PointInterpolatorUtil {
|
||||
private static final String TAG = "PointInterpolatorUtil";
|
||||
private static final int DISTANCE_THRESHOLD = 2;
|
||||
|
||||
/**
|
||||
* 在(x1,y1) (x2,y2)中间插入一些点,使每两个点之间距离<={@link #DISTANCE_THRESHOLD},利用如下公式进行计算
|
||||
* xn = x1 + (x2 - x1)*n/a
|
||||
* yn = y1 + (y2 - y1)*n/a
|
||||
* a = (distance/{@link #DISTANCE_THRESHOLD}) +1
|
||||
* n in 1 .. a-1
|
||||
* n == 0 时,xn = x1
|
||||
* n == a 时,xn = x2
|
||||
* <p>
|
||||
* 将xn依次插入x1到x2之间
|
||||
*
|
||||
* @param points 待插值点集
|
||||
* @deprecated 这个方法有问题,并不能算出来想要的值
|
||||
*/
|
||||
@Deprecated
|
||||
public static void interpolate(List<MogoLatLng> points) {
|
||||
if (points.size() >= 2) {
|
||||
// 插值
|
||||
for (int i = 0; i < points.size() - 1; i++) {
|
||||
MogoLatLng current = points.get(i);
|
||||
MogoLatLng next = points.get(i + 1);
|
||||
float distance = CoordinateUtils.calculateLineDistance(current.lon, current.lat, next.lon, next.lat);
|
||||
Logger.d(TAG, i + ": " + distance);
|
||||
if (distance > DISTANCE_THRESHOLD) {
|
||||
int inter = (int) (distance / DISTANCE_THRESHOLD) + 1;
|
||||
for (int j = 1; j < inter; j++) {
|
||||
double newLat = current.lat + (next.lat - current.lat) * j / inter;
|
||||
double newLon = current.lon + (next.lon - current.lon) * j / inter;
|
||||
Logger.d(TAG, "distance: " + distance + ", j: " + j + ", nextLat: " + next.lat + ", nextLon: " + next.lon + ", newLat: " + newLat + ", newLon: " + newLon);
|
||||
points.add(i + 1, new MogoLatLng(newLat, newLon));
|
||||
current = points.get(++i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 道路吸附算法
|
||||
* <p>
|
||||
* 所谓的道路数据,实际就是道路对应的点集,每两个点之间是直线,但是两点间距并不固定,点集内点的数量也不固定,点集是有序的,按道路方向排序,road[0]是起点。
|
||||
* 为了避免拐弯道路的问题,先使用{@link #getCloseTwoPoint(int, int, double, double, List)}从道路数据里面找出距离目标点最近的两个点,记为A、B,最近的两个点就在目标点一前一后排列,
|
||||
* 这样的话,求一下目标点到AB的垂直映射以及距离{@link #getFootAndMinDistance(double, double, double, double, double, double)},就是吸附后的经纬度和距离
|
||||
*
|
||||
* @param lon 目标经度
|
||||
* @param lat 目标纬度
|
||||
* @param road 目标道路数据
|
||||
* @return double[]{吸附后的经度,吸附后的纬度,目标经纬度距离道路的垂直距离}
|
||||
*/
|
||||
public static double[] mergeToRoad(double lon, double lat, List<LonLatPoint> road) {
|
||||
int closeStart = 0;
|
||||
int closeEnd = road.size() - 1;
|
||||
int[] result = getCloseTwoPoint(closeStart, closeEnd, lon, lat, road);
|
||||
LonLatPoint start = road.get(result[0]);
|
||||
LonLatPoint end = road.get(result[1]);
|
||||
return getFootAndMinDistance(lon, lat, start.getLongitude(), start.getLatitude(), end.getLongitude(), end.getLatitude());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取距离目标点经纬度最近的道路点index
|
||||
* <p>
|
||||
* 采用二分查找思想,先用道路数据的起点和终点分别计算距离目标点的距离:
|
||||
* 若起点距离较远,则说明目标点在整条道路的后半段,则将起点后移至原起点和终点的中间,继续递归计算;
|
||||
* 同理,若终点距离较远,则目标点在前半段,则终点前移,继续递归计算;
|
||||
* 递归结束条件是起点index和终点index间隔是1;
|
||||
*
|
||||
* @param closeStart 距离目标点最近的起始点index
|
||||
* @param closeEnd 距离目标点最近的终点index
|
||||
* @param lon 目标点经度
|
||||
* @param lat 目标点纬度
|
||||
* @param road 目标道路
|
||||
* @return int[]{距离目标点最近的起始点index,距离目标点最近的终点index}
|
||||
*/
|
||||
private static int[] getCloseTwoPoint(int closeStart, int closeEnd, double lon, double lat, List<LonLatPoint> road) {
|
||||
if (closeEnd - closeStart == 1) {
|
||||
return new int[]{closeStart, closeEnd};
|
||||
}
|
||||
LonLatPoint start = road.get(closeStart);
|
||||
LonLatPoint end = road.get(closeEnd);
|
||||
float startDistance = CoordinateUtils.calculateLineDistance(start.getLongitude(), start.getLatitude(), lon, lat);
|
||||
float endDistance = CoordinateUtils.calculateLineDistance(end.getLongitude(), end.getLatitude(), lon, lat);
|
||||
if (startDistance > endDistance) {
|
||||
closeStart += (closeEnd - closeStart) / 2;
|
||||
} else {
|
||||
closeEnd -= (closeEnd - closeStart) / 2;
|
||||
}
|
||||
return getCloseTwoPoint(closeStart, closeEnd, lon, lat, road);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算垂足以及最短距离
|
||||
*
|
||||
* @param x target point lon
|
||||
* @param y target point lat
|
||||
* @param x1 线段起点 lon
|
||||
* @param y1 起点起点 lat
|
||||
* @param x2 线段终点 lon
|
||||
* @param y2 线段终点 lat
|
||||
* @return double[]{footLon,footLat,minDistance} if(footLon == -1) => no foot or foot not in line
|
||||
*/
|
||||
private static double[] getFootAndMinDistance(double x, double y, double x1, double y1, double x2, double y2) {
|
||||
double[] result = new double[]{-1, -1, -1};
|
||||
double cross = (x2 - x1) * (x - x1) + (y2 - y1) * (y - y1);
|
||||
if (cross < 0) {
|
||||
// 垂足没有在线段内,所以也无需计算最短距离
|
||||
return result;
|
||||
}
|
||||
double d2 = (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);
|
||||
if (cross > d2) {
|
||||
// 垂足没有在线段内,所以也无需计算最短距离
|
||||
return result;
|
||||
}
|
||||
double r = cross / d2;
|
||||
result[0] = x1 + (x2 - x1) * r;
|
||||
result[1] = y1 + (y2 - y1) * r;
|
||||
result[2] = CoordinateUtils.calculateLineDistance(result[0], result[1], x, y);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.mogo.map.utils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2021/3/8
|
||||
*
|
||||
* 描述
|
||||
*/
|
||||
public class ResIdCache {
|
||||
|
||||
public static Map< String, String > sMarkerCachesResMd5Values = new HashMap<>();
|
||||
|
||||
public static String getVal( String name ) {
|
||||
return sMarkerCachesResMd5Values.get( name );
|
||||
}
|
||||
|
||||
public static void putVal( String name, String val ) {
|
||||
sMarkerCachesResMd5Values.put( name, val );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user