1

I've got an OpenLayers 2 map with a lot of point features that need to be represented using a number of different SVG-symbols. Unfortunately, the marker icons need to be displayed in different colours that I read from a config file. However, until now I couldn't figure out how to achieve a dynamic colouring. For a number of reasons, switching to a more recent version of OL is not possible. Does anyone now, how to colour SVG-Icons in OL 2?

  • Have you tried setting a class and styling the svg using CSS? Please add a code snippet and provide a jsfiddle.net – Stefan Nov 13 '18 at 8:26
  • I haven't tried this, but since the colours need to be read from a json file I guess defining a CSS class in my case is not an option. – TobsenB Nov 13 '18 at 8:53
  • 1
    It can be done, you would need to parse the json to build the CSS string, then you can set the inner html of an existing style element or create a new element and append it to document head. – Mike Nov 13 '18 at 10:18

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.