1

I have a problem adding a list of points to a vector source, a layer and finally to the map in Openlayers. In the beginning I create an empty array, after that I iterate over a given data set and create a new Point with an Icon and a text field for every feature and store the marker in the list. In the end I want to create a new ol.source.Vector() with the array, which leads to the error 'c.Xa is not a function'. If I just take a single marker out of the list and add it to the vector source and the map everything works just fine with the right position on the map, right icon and right text.

var markers=[];

for(var i=1; i<ResearchStations.length; i++){
  var mark=new ol.Feature({
      geometry: new ol.geom.Point(
        ol.proj.fromLonLat([lon, lat], proj3031)
      ),
 });
  var icon = new ol.style.Style({
          image: new ol.style.Icon({
              ...
            }),
           text: new ol.style.Text({
              ...
           })
   })
  mark.setStyle(icon);
  markers[i]=mark;
}

console.log(1) 
var vectorSource = new ol.source.Vector({
    features: [markers],
});
console.log(2)
var StationLayer = new ol.layer.Vector({
    source: vectorSource,
 });
console.log(3)
map.addLayer(StationLayer);

The error occurs after console.log(1)

  • 3
    It's probably because you have an empty entry at markers[0]. Are you are intentionally omitting `ResearchStations[0]`? If so to fill the markers array from the start replace `markers[i]=mark;` with `markers.push(mark);` – Mike Mar 08 '19 at 11:19
  • 1
    Oh yeah indeed, I have to handle a Matlab Project simultaneously :( Thank you! – SurveyingSurveyor Mar 08 '19 at 12:17
  • 1
    @Mike Can you post your comments as answers? Because I saw a few posts where your comments are answering the question but not posted as answer and accepted. – pavankguduru Mar 14 '19 at 07:34

0 Answers0