Dynamic symbols

68 views
Skip to first unread message

Harry Gibson

unread,
May 4, 2012, 8:50:51 AM5/4/12
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

Jason Sanford

unread,
May 8, 2012, 12:24:25 PM5/8/12
to leaflet-ve...@googlegroups.com
Hi Harry

I think this is a great idea. Would you be will to file a pull request so we can discuss more?

Thanks
Jason
Reply all
Reply to author
Forward
0 new messages