I am specifying the coordinates of
[-122, 47], (in USA)
[147, -32] (in Australia)
The image it produces is:
I was under the false impression that OpenLayers would draw the shortest line between two coordinates.
What would I need to change so the line drawn is the shortest?
(In this case, the line would cross over the Pacific instead of Atlantic Ocean)
let coordinates = [
[-122, 47],
[147, -32]
];
const myFeature = new ol.Feature({
geometry: new ol.geom.LineString(coordinates),
name: "Line"
});
myFeature.setStyle(
new ol.style.Style({
stroke: new ol.style.Stroke({ color: "green", width: 8 })
})
);
const vectorSource = new ol.source.Vector({
features: [myFeature]
});
const vectorLayer = new ol.layer.Vector({
source: vectorSource
});
const map = new ol.Map({
target: "map",
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
}),
vectorLayer
],
view: new ol.View({
projection: "EPSG:4326",
center: [0, 0],
zoom: 1
})
});
#map {
height: 450px;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/openlayers/7.1.0/ol.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/openlayers/7.1.0/dist/ol.min.js"></script>
<div id="map"></div>