[geojquery] Playing with the prototype GeojQuery Widget

Volker Mische volker.mische at gmail.com
Fri Sep 24 11:47:37 EDT 2010


On 09/24/2010 11:06 AM, Anne Blankert wrote:
>  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

To clearify things a bit. I'm +1 for using the jQuery UI factory for
normal widgets that operate on DOM. But geoMap() is something different.
This is the part we were refering to as geojquery-core. It doesn't
return a DOM/jQuery object, therefore we don't need the strange
geoMap('function-name', options) convention. It returns a geoMap object.
We can add layers to the object and so on. We can just call functions
directly on the object (like geoMap(...).layer(...)) [1].

Therefore I proposed that we don't use the jQuery widget factory for it,
as it adds the dependency on it and we don't need the full feature set
(like automatic getters, setters, the special trigger etc. (see the link
Anne posted above)).

[1] http://gitorious.org/geojquery/pages/Api

Cheers,
  Volker




More information about the Mapquery mailing list