Search code examples
openlayerspoint

OpenLayers - how to add multiple points to layer


I have two arrays, these are latitude and longitude coordinates

this works when I add 1 coordinate, but how i can add all coordinates?

var marker = new Feature(
          new Point([stringLongitude[0],stringLatitude[0]])
      );

Solution

  • Multipoint is a class in Openlayers. Not having stated an explicit version I assume you work with the latest.

    From the Openlayers documentation:

    https://openlayers.org/en/latest/apidoc/module-ol_geom_MultiPoint-MultiPoint.html

    The multipoint class may receive an array of lat lng

    new MultiPoint([
      [lng, lat]
      [lng, lat], opt_layout)