cccreator / GIS

Gis releated
1 stars 0 forks source link

实现map上车辆移动时,车图方向总是指向移动方向 #7

Open cccreator opened 6 years ago

cccreator commented 6 years ago
  1. 计算旋转角

    
                if(cityName.equals("SZ") && i+1 < list.size() && firstLat != null && firstLon != null){
    
                    double[] offSetDateFist = GpsUtil.toGCJ02Point(Double.parseDouble(String.valueOf(list.get(i)[5])),Double.parseDouble(String.valueOf(list.get(i)[4])));
                    double[] offSetDateNext = GpsUtil.toGCJ02Point(Double.parseDouble(String.valueOf(list.get(i+1)[5])),Double.parseDouble(String.valueOf(list.get(i+1)[4])));
    
                    Double firstOffSetLon = offSetDateFist[1];
                    Double firstOffSetLat = offSetDateFist[0];
                    Double nextOffSetLon = offSetDateNext[1];
                    Double nextOffSetLat = offSetDateNext[0];
    
                    double xgap = firstOffSetLon - nextOffSetLon;
                    double ygap = firstOffSetLat - nextOffSetLat;
    
                    double dou;
                    double dou1;
                    dou = Math.abs(xgap);
                    dou1 = Math.abs(ygap);
    
                    DecimalFormat df = new DecimalFormat("#.00000");
    
                    if(Double.parseDouble( df.format(dou)) > 0.00001 && Double.parseDouble( df.format(dou1)) >0.00001){
                        double angle = GpsUtil.getAngle(firstOffSetLon,firstOffSetLat,nextOffSetLon,nextOffSetLat);
    //                        double angle = GpsUtil.getAngle(firstOffSetLat,firstOffSetLon,nextOffSetLat ,nextOffSetLon);
                        map.put("angle",String.valueOf(angle));
                    }
                }

2. 计算旋转角的方法getAngle
public static double getAngle(double firstLon,double firstLat,double nextLon,double nextLat){
    double dRotateAngle = Math.atan2(Math.abs(firstLon - nextLon), Math.abs(firstLat - nextLat));
    if (nextLon >= firstLon) {
        if (nextLat >= firstLat) {
        } else {
            dRotateAngle = Math.PI - dRotateAngle;
        }
    } else {
        if (nextLat >= firstLat) {
            dRotateAngle = 2 * Math.PI - dRotateAngle;
        } else {
            dRotateAngle = Math.PI + dRotateAngle;
        }
    }
    dRotateAngle = dRotateAngle * 180 / Math.PI;
    return dRotateAngle;
}


3. 前端实现
`var symbolw =new esri.symbol.PictureMarkerSymbol(mapConfig.testDirection,mapConfig.playWaveSize, mapConfig.playWaveSize);` PictureMarkerSymbol有个设置旋转角的方法`symbolw.setAngle(app.angleData[playi]);`