简体   繁体   中英

Rotate the icons in the direction of the line

I'm trying to add direction to the line using an icon and coordinates from a geoJson file, and the arrows dont follow the line here is an examle: Example

and here is the php function that i use to turn the arrows:

function getRotationAngle($long1, $lat1, $long2, $lat2) {

$latit1 = deg2rad($lat1);
$latit2 = deg2rad($lat2);
$longi1 = deg2rad($long1);
$longi2 = deg2rad($long2);

$dLon = $longi2 - $longi1;

$y = sin($dLon) * cos($latit1);
$x = cos($latit2) * sin($latit1) - sin($latit2) * cos($lati1) * cos($dLon);

$brng = atan2($y, $x) ;

$angle = $brng * 180 / pi();
$angle1 =fmod($angle + 180,180);
//echo "rotation angle =". $angle1."<br>";
return $angle1;
}

I want the arrows to follow the lineString made from geoJson coordinates, the angle is saved in geojosn as a feature

$ angle = 360-((rad2deg(atan2($ y,$ x))+ 360)%360);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM