Harry Gibson
unread,May 4, 2012, 8:50:51 AM5/4/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Leaflet Vector Layers
Hi,
I thought it would be handy to have a dynamic option for symbology -
so that the symbol for a given feature can be set based on some
property or properties of the feature. I know that the range option
kind of does that but
a) it could be a bit unwieldy to write out the range specification if
there's lots, and potentially a function could return this more easily
b) as far as I can figure out it doesn't let you take account of more
than one field.
I wanted to use a different symbol for different categorical values in
one property, and size the symbol according to a different (smoothly-
varying) property.
I added a fourth case for switch (this.options.symbology.type) in
Layer.js, namely:
case "dynamic":
for (var key in this.options.symbology.vectorOptions){
if (typeof (this.options.symbology.vectorOptions[key]=="function")){
vectorOptions[key] =
this.options.symbology.vectorOptions[key].call(this,feature);
}
else {
vectorOptions[key] = this.options.symbology.vectorOptions[key];
}
}
break;
Then when I'm defining the layer (CartoDB) I can say:
symbology: {type:"dynamic, icon:"getCustomIcon"}
and getCustomIcon is a function which builds and returns an
appropriate icon based on the properties of the feature ,determining
the iconUrl from one property and the iconSize from another property
(actually, calculated from several things)
I've tried this (with points only) and it seems to work ok. Anything
I'm missing ?
Harry