I am working on a project that from the ads-b data puts on the OpenLayers map the position of the intercepted planes ....
I encounter 2 problems:
- The coordinates are in latitude and longitude and receive the following error:
Collection.js: 292 Uncaught e {code: 58, name: "AssertionError", message: "Assertion failed. See https://openlayers.org/en/v5.3.0/doc/errors/#58 for details."}
Two plane icons are displayed but there are many more ...
- I think it is a problem with the projection of coordinates because the coordinates should somehow fall in Romania or at least near Romania and they fall in southern Africa ....
The code that takes json from ads-b:
$.post( "data.php",
{
get_data: 1
},
function( data ) {
var obj = JSON.parse(data);
var aircrafts = obj.acList;
//console.log(aircrafts);
for(var i = 0; i<aircrafts.length; i++ ){
if(aircrafts[i].Long || aircrafts[i].Lat){
var coordinates = [aircrafts[i].Long, aircrafts[i].Lat];
console.log(coordinates);
addMarker(coordinates);
}
}
})
The code with which I try to display on the map the icons at the position in latitude and longitude:
function addMarker(coordinates) {
proj4.defs('EPSG:31700','+proj=sterea +lat_0=46 +lon_0=25 +k=0.99975 +x_0=500000 +y_0=500000 +ellps=krass +towgs84=28,-121,-77,0,0,0,0 +units=m +no_defs');
ol.proj.proj4.register(proj4);
console.log(coordinates);
var marker = new ol.Feature(new ol.geom.Point(coordinates).transform('EPSG:4326', 'EPSG:31700'));
console.log(marker);
var zIndex = 1;
marker.setStyle(new ol.style.Style({
image: new ol.style.Icon(({
anchor: [0.5, 36],
anchorXUnits: "fraction",
anchorYUnits: "pixels",
opacity: 1,
src: "img/airport.png",
zIndex: zIndex
})),
zIndex: zIndex
}));
vectorSource.aircraft.addFeature(marker);
map.addLayer(aircraft);
}
Exemple coordinate:
[29.746857, 42.511047]
!!!!!UPDATE!!!!
I was able to display all the intercepted planes in ads-b:
The line had to be moved: map.addLayer(aircraft); when taking over json
$.post( "data.php",
{
get_data: 1
},
function( data ) {
var obj = JSON.parse(data);
var aircrafts = obj.acList;
//console.log(aircrafts);
for(var i = 0; i<aircrafts.length; i++ ){
if(aircrafts[i].Long || aircrafts[i].Lat){
var coordinates = [aircrafts[i].Long, aircrafts[i].Lat];
console.log(coordinates);
addMarker(coordinates);
}
}
map.addLayer(aircraft);
})