3

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:

  1. 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 ...

  1. 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 ....

enter image description here

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);
                    })

enter image description here

2
  • 1
    Your map is in EPSG:3875 (Web Mercator) and your points are initially in EPSG:4326 and subsequently in EPSG:31700 which is why they are spread out around Null Island
    – Ian Turton
    Jan 3, 2021 at 10:48
  • how could I solve this an example code please very nice if possible? Jan 3, 2021 at 11:18

1 Answer 1

4

Feature coordinates must always be transformed to the view projection

var marker = new ol.Feature(new ol.geom.Point(coordinates).transform('EPSG:4326', map.getView().getProjection()));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.