[geojquery] Playing with the prototype GeojQuery Widget
Anne Blankert
anne.blankert at geodan.nl
Fri Sep 24 05:06:55 EDT 2010
Hello list,
I do like how the ui-widgets work, although they add a dependency on
jquery-ui. I did not find full reference documentation though, is there
one on-line?
In my attempt at creating a mapwidget plugin, I tried to depend on
jQuery only and wrap jQuery-ui widgets (like 'layout', 'dialog' or
'sortable') around them.
So where do we go from here? Many of the widgets do not require
jQuery-ui. At this moment I think only a widget like 'sortableLegend'
would require jQuery-ui.
Volker proposes we implement a subset of the widget factory ourselves.
According to
http://bililite.com/blog/understanding-jquery-ui-widgets-a-tutorial/ the
core problem of plugins are memory management:
Memory leaks me be caused by DOM elements referencing Javascript
elements and vice versa. jQuery solved this by adding the $.fn.data
plugin, but this results in a lot of bookkeeping.
The jQuery-ui widgets generally work as follows:
// create the widget
$.widget("widgetName", WidgetClass);
// now instantiate the widget in the DOM
$(selector).widgetName({defaultOption1: value1, defaultOption2: value2});
// use some WidgetClass methods
// call a chainable WidgetClass setter named 'setterMethod':
$(selector).widgetName('setterMethod', setterParameter1, setterParameter2);
// call a WidgetClass getter named 'getterMethod'
var aValue = $(selector).widgetName('getterMethod', getterParameter1,
getterParameter2);
Now if we want get rid of the jQuery-ui dependency, we may still want
the to be able to do something like:
// instantiate geoMap
$(selector).geoMap ({ olMap: myOlMap, allOverlays: false});
// use a setter method:
$(selector).geoMap(‘layer’, ‘blue_marble’, {
'type': 'WMS',
'label': 'Blue Marble',
'url': 'http://sigma.openplans.org/geoserver/gwc/service/wms?',
'layers': 'bluemarble'
});
// get the class instance:
var myMap = $(selector).geoMap('geoMap');
// get some value
var myValue = $(selector).geoMap('getOption', 'keyName');
// set some value
$(selector).geoMap('setOption', 'keyName', keyValue);
I think the above examples can be done without the need for the
jQuery-ui widget factory. I think I even see some advantages of not
using the widget factory here.
What kind of functionality would we lose if we let go of the jQuery-ui
widget factory altogether?
Anne
More information about the Geojquery
mailing list