Is it possible to style vector layer so there would be picture and label with its own background color for a feature? Something like this:

enter image description here

  • If style properties can be mapped to feature properties you can use a stylemap as in this example dev.openlayers.org/examples/vector-features-with-text.html (view source to see how it's done) otherwise you could loop through features and style them individually feature.style = { ... } where the style object is a set of key name and value pairs, see dev.openlayers.org/releases/OpenLayers-2.13.1/doc/apidocs/files/… for all the available options – Mike Jan 23 '19 at 13:12
  • And how to put colored rectangle under label? If I simply increase labelOutlineWidth, it looks bad. – Feofilakt Jan 24 '19 at 2:17
  • 1
    You could probably use externalGraphic for the main image and backgroundGraphic with its own offsets for a label background. Instead of having to find physical image files for each color you could use one pixel data urls generated by png-pixel.com and stretch them by setting whatever backgroundWidth and backgroundHeight you want (maybe based on the number of characters in the text). – Mike Jan 24 '19 at 19:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.