I am trying to draw some default line between two location (Location A, Location B) using location latitude and longitude with the help of OpenLayers and ReactJS. But defaulted line is not getting drawn. Unfortunately, I couldn't find the root cause. How can I solve this?
Code:
componentDidMount() {
var map;
var raster=new Tile({
source: new OSM()
});
//Location A - Latitude and Longitude
var iconFeature1 =new Feature({
geometry: new Point(proj.transform([79.2652587890625,19.532871485421026], 'EPSG:4326', 'EPSG:3857')),
name: 'Marker 1' });
//Location B - Latitude and Longitude
var iconFeature2 =new Feature({
geometry: new Point(proj.transform([81.24279785156249,18.02679570052561], 'EPSG:4326', 'EPSG:3857')),
name: 'Marker 2' });
var source = new SourceVector({
features: [iconFeature1,iconFeature2],
wrapX: false
});
var vector = new LayerVector({
source: source,
style: new Style({
fill: new Fill({
color: 'white'
}),
stroke: new Stroke({
color: 'red'
})
})
});
map = new Map({
target: 'map',
layers: [raster,vector],
view: new View({
center: proj.fromLonLat([78.8718, 21.7679]),
zoom: 4
})
})
//To draw Line
var draw = new Draw({
source: source,
type: "LineString"
});
map.addInteraction(draw);
});