Turf #1506

by Stefano

HTML

<script src="https://npmcdn.com/@turf/turf/turf.min.js"></script>
<div id="output"></div>

JavaScript

function parseArcByCenterPoint(segment) {
  const centrePoint = [-4.78333, 51.63750];
  const radius = 11.34 * 1.852;
  const startAngle = parseFloat(segment.startAngle);
  const endAngle = parseFloat(segment.endAngle);
  // lineArc passes units to destination, which expects options, hence this...
  const options = { steps: 64, units: { units: 'kilometers' } };
  return turf.lineArc(centrePoint, radius, startAngle, endAngle, options);
}  
  
var arc = parseArcByCenterPoint({
  "startAngle": "113.3093407942986914349603466689586639404296875",
  "endAngle": "237.4093138210736242399434559047222137451171875"
});

var collection = turf.featureCollection([
	turf.lineString([
    [-4.83667,51.6375],
    [-4.73,  51.6375],
    [-4.50528, 51.5625]
  ]),
  turf.lineString([
  	[-5.03833, 51.53556],
    [-4.83667, 51.63750]
  ]),
  arc
]);

display(collection);


/* output function */
function display(data, target) {
	target = target || 'output';
  var el = document.getElementById(target);
  // if not available create target element
  if (!el) {
  	el = document.createElement('div');
    el.setAttribute("id", target);
    document.body.appendChild(el);
  }
  // inject text
	var json = JSON.stringify(data, null, '\t');
  document.getElementById(target).innerHTML = json;
}