How can we draw custom shapes as features on open layers map

1.4k views Asked by At

How can we draw custom shapes as features on open layers map?

in our project, we have to dislpay multi colored custom shapes (just like pushpins) as Features on the map. the colors in the shapes change according to the undelaying data that the Feature depicts. say, a released order shows green color and a free order shows red when these two are in a cluster, the feature should be colored in half green and half red depicting that the cluster contains both types of orders.

how can this be done?

Regards Jatin

1

There are 1 answers

5
Knarf On

To achieve this you must

  • attach an attribute to the Feature
  • attach a Style to the Vector layer in which you add the feature
  • attach Rules to this Style that check the attribute

An example can be found in the showcase : http://demo.gwt-openlayers.org/gwt_ol_showcase/GwtOpenLayersShowcase.html?example=Rule%20Based%20Style

In this example a random attribute 'foo' is attached to the features. Based on the value of this attribute the markers get coloured (less then 25 = blue ; between 25 and 50 = gold ; between 50 and 75 green ; else red)

Click the "View Source" button in the showcase to check out the code.