[geojquery] To plug in or not to plug in?

Volker Mische volker.mische at gmail.com
Sat Mar 13 15:48:26 EST 2010


Hi Oliver,

the way I have imagined it is like gquery does it. Once you apply the
map object, you are not in the DOM world any more. Any future call in
the chain will be applied to the map. Here's an example:

$('#map').map({someoptions}).center(lonlat);

This won't work (except if we implement out own hide method):
$('#map').map({someoptions}).hide();

I think this approach is alright. jQuery is about DOM, so it always
returns DOM nodes. Our plugin is about maps, so it should return a map
object. To get back to the DOM chain we could easily implement a dom()
method:

$('#map').map({someoptions}).center(lonlat).dom().hide();

It would be kind of what end() in jQuery does.

Cheers,
  Volker

Oliver Tonnhofer wrote:
> Hi everyone,
> 
> I was playing with the jQuery plugin idea and I am not really sure if a plugin is the right way for doing this.
> 
> All existing jQuery plugins are - more or less - just playing with DOM objects. Hide that, fade this in, add this event, etc.  But we want to work with another library, we don't need access to the DOM elements where we added our maps, we need access to the actual map object (OpenLayer or our own geojquery map objects).
> 
> I don't see how this can be implemented in an elegant way when we just want to write a plugin. 
> 
> Let me give you an example with some code I have[1]:
> 
> $('#map').map({
>  size: [400, 400],
>  zoom: 7,
>  center: [8.19884, 53.1495],
>  layers: [$.map.tms({host:"http://osm.omniscale.net/proxy/tiles/", layer:"osm_EPSG900913"})]
> });
> 
> Pretty simple. I just created a map inside the #map element. But how do I interact with the map? $('#map') gives me a jQuery object where I can manipulate all attributes from the DOM object, but not the actual map. We can add the OpenLayers map or some geojQuery object as .data() to the element, but $('#map').data('map').center(lonlat) is rather quirky.
> 
> One solution would be to add another jQuery method for everything we intend to do with our map.
> 
> $('#map').center(lonlat);
> $('#map').add_layer(...);
> 
> That would work, but it would also pollute the $-namespace. PHP developers might like that but I'm strongly against that. ;)
> 
> Maybe I'm missing something, please enlighten me :)
> 
> [1] http://bitbucket.org/olt/geojquery-playground/src/
> 
> Regards, 
> Oliver
> 




More information about the Mapquery mailing list