Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The proper way to utilize a MultiLineStringM geometry in OpenLayers is to create a new feature with this geometry and add it to a vector layer.

Example code:

var multiLineStringM = new ol.geom.MultiLineStringM([...]);

var feature = new ol.Feature({
  geometry: multiLineStringM
});

var vectorLayer = new ol.layer.Vector({
  source: new ol.source.Vector({
    features: [feature]
  })
});

map.addLayer(vectorLayer);

In this code:

  • ol.geom.MultiLineStringM([...]) creates a new MultiLineStringM geometry object. Inside the brackets, you need to provide an array of coordinate arrays. Each coordinate array represents one line string within the MultiLineStringM object.
  • ol.Feature({geometry: multiLineStringM}) creates a new feature object with the MultiLineStringM geometry.
  • new ol.layer.Vector({...}) creates a new vector layer.
  • new ol.source.Vector({features: [feature]}) creates a new vector source and adds the feature to it.
  • map.addLayer(vectorLayer) adds the vector layer to the map.

Note that the MultiLineStringM geometry is just one type of geometry that OpenLayers supports. The exact code you need to use may differ depending on the geometry you are working with, but the basic idea is the same: create a feature with the geometry and add it to a vector layer.