olwidget
olwidget copied to clipboard
Feature request: custom WMS layers for django-olwidget
Much like #47 ... I'd like to be able to add any WMS server as a base layer option, via some array or something in settings.py.
If the wms server didn't need any extra options, one expedient hack might be to interpret unknown types as URLs, eg. do this in olwidget.js at the end of the wms function: {{{ ... } else if (type === "blank") { return new OpenLayers.Layer("", {isBaseLayer: true}); } else { return new OpenLayers.Layer.WMS("custom WMS server", type); } }}}
but this is pretty obviously lame: you're going to need to pass options somehow. I have one possibly better idea to pursue, will check it out.
Okay, I've added a 'custom.foo' constructor. This gist shows how it works, with an example in the docs - though rather than applying this to my olwidget fork, so far I'm applying this as a monkeypatch in my own javascript. https://gist.github.com/1128539
On second thought, I pushed it to my fork as the custom_base_layers branch.
We need this functionality too.
I think the ideal way to do this would be to have, in settings.py:
OLWIDGET_CUSTOM_BASE_LAYERS = {
'opengeo_osm': # to use this, your olwidget layers would include ['custom.opengeo_osm']
{"class": "WMS", # The OpenLayers.Layer subclass to use.
"args": [ # These are passed as arguments to the constructor.
"OpenStreetMap (OpenGeo)",
"http://maps.opengeo.org/geowebcache/service/wms",
{"layers": "openstreetmap",
"format": "image/png",
"bgcolor": "#A1BDC4",
},
{"wrapDateLine": True
},
],
}
}
rather than declare this explicitly in JS-land. Then in JS we can allow olwidget.registerCustomBaseLayers() which acts in much the same way.
I've added this to my fork's custom_base_layers_fixed branch. I'll issue a pull request after we've played with it in production for a bit.
Interested to see how this plays out, could be major win for one of my current projects too. Please keep us posted.
I've issued a pull request after using this in production for a few weeks.
yourcelf, any thoughts on this?