nstillwell
nstillwell

Reputation: 51

Multiple labels for an object in OpenLayers

Questions

  1. How can one achieve the desired result described below using the OpenLayers6 library without rendering the object multiple times?
  2. If 1 is not possible what is a suitable method for achieving this result (custom library extension?)?

Desired Result

Apply different styles to multiple labels for an object (line) depending on the attributes attached to the line/label. Note there are many more scenarios for the attribute values than the ones included in the image.

enter image description here

Current Method

At present, I have achieved the desired result by rendering the object (line) multiple times, and fiddling with the styling each time it is rendered - this is not performing well and is very clunky.

Upvotes: 0

Views: 666

Answers (1)

Mike
Mike

Reputation: 17897

You can use a style array

feature.setStyle([
  new Style({
     stroke: new Stroke({
       ...
     }),
     text: new Text({
       ...
     })
  }),
  new Style({
     text: new Text({
       ...
     })
  })
]);

Upvotes: 2

Related Questions