0

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 Answers1

0

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.

Knarf
  • 2,077
  • 1
  • 16
  • 24
  • Yes, this is the way we add the cluster feature. but my question is slightly different. – user2163450 Dec 23 '13 at 04:57
  • Yes, this is the way we add the cluster feature. but my question is slightly different. Basically, we either add an External graphic to a feature or leave it to the default circle (ofcource, we can format the circle) but, what if i want to draw a different graphic insted of the circle?? I agree we can add polygon etc but that will not retain its original size when we zoom in and out. i mean the shape will also zoom in or out. what i am looking at is to draw a shape like a feature. I am unable to attach the screen shot to explain you better (reputation is low)... – user2163450 Dec 23 '13 at 05:03
  • if you can provide me your email id then i can send you the screenshot that will give you more clarity about the requirement – user2163450 Dec 23 '13 at 05:37
  • Hello, Can you please reply? Regards – user2163450 Jan 02 '14 at 05:37
  • You can post your question on the Google+ group : https://plus.google.com/u/0/communities/109137404279382952520 – Knarf Jan 06 '14 at 08:54