I have used the Leaflet open street map. With the API I have fetched the latitude, longitude array and placed the locations - something like this:
{
"Drone": {
"Droneid": 1001,
"latlong": [
{
"lat": 12.989839,
"lon": 80.198822
},
{
"lat": 13.051832,
"lon": 80.194480
},
{
"lat": 13.038453,
"lon": 80.227442
},
{
"lat": 13.009018,
"lon": 80.242550
},
{
"lat": 12.976903,
"lon": 80.237056
},
{
"lat": 12.956829,
"lon": 80.193107
},
{
"lat": 12.980917,
"lon": 80.150531
},
{
"lat": 13.007680,
"lon": 80.149158
},
{
"lat": 13.043805,
"lon": 80.154651
}
]
}
}
From the above array I have placed the circle of 3 km radius with index-0, and placed the drone icon with index-1 and with the remaining index values (lat, long) placed the dots on the map.
And created the movement of drone from one latitude, longitude to another starting from index-2.
Now I have to place an arc of 45 degrees angle inside the circle and if the drone comes inside the circle it has to changed to red color.
.component.ts
var map = L.map('map').setView([12.0827, 80.2707], 11);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
} ).addTo(map);
var TIME = 2000;
//var TIME = 1;
var latlngs = this.drones.Drone.latlong;
var START_IDX = 2;
var latlngIdx = START_IDX; // 0 = Circle, 1 = First position
var marker;
latlngs.forEach((latlong, idx)=>{
var latlng = L.latLng(latlong.lat,latlong.lon)
if(idx === 0){
L.circle(latlng,{radius:5000}).addTo(map);
marker = L.marker(latlng,{icon:sensoricon}).addTo(map)
// L.circle(latlng,{radius:100}).addTo(map);
}else if(idx===1){
marker = L.marker(latlng,{icon:myIcon})
.bindTooltip( this.drones.Drone.Droneid ).addTo(map)
}else if(idx>=2){
//L.circle(latlng,{color: '#3388ff'},{radius:70}).addTo(map)
var circleMarker = L.circle(latlng,{color: 'red'},{radius:100}).addTo(map)
}
});
function nextLatLng(){
if(marker){
if(latlngIdx === latlngs.length){
latlngIdx = START_IDX;
}
marker.setLatLng(latlngs[latlngIdx]);
//.bindPopup( this.latlngs.lat,this.latlngs.lon );
latlngIdx++;
//function () { marker.slideTo(START_IDX, {duration:5000}); };
setTimeout(nextLatLng,TIME);
}
}
nextLatLng();
I have tried many ways but it's not working. Can anyone help me with this?