Open cccreator opened 6 years ago
类似功能如图
思想:从java端利用相邻两个点的经纬度,算出旋转角;然后,用Arcgis API设置旋转角。此处注意不要在前端计算旋转角,在java端性能会更好。
计算旋转角
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]);`
类似功能如图
思想:从java端利用相邻两个点的经纬度,算出旋转角;然后,用Arcgis API设置旋转角。此处注意不要在前端计算旋转角,在java端性能会更好。
计算旋转角