Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
Checking mergeability… Don't worry, you can still create the pull request.
  • 20 commits
  • 7 files changed
  • 0 commit comments
  • 5 contributors
Commits on Jun 01, 2011
@slinkp slinkp Add a hook that Map widget subclasses can use to provide more data to…
… the javascript... useful for eg. adding custom base layers
58e9ace
Commits on Sep 26, 2011
@slinkp slinkp SUpport a 'custom' constructor. Closes #60 d255a1f
@philipn philipn Use Django settings for custom base layers, registerCustomBaseLayers(…
…) JS method.
84cbe0b
@philipn philipn Add custom base layers init to map widget template. 5992ecb
Commits on Sep 27, 2011
@philipn philipn As discussed, JS-style custom map layers. edeb0cc
Commits on Oct 04, 2011
@philipn philipn We need to /not/ have the 'new' call in settings.py. The old way of d…
…oing this (in previous commit) works, but it doesn't allow for multiple maps with the same layer on the same page.
6efb215
Commits on Feb 24, 2012
@versae versae Update django-olwidget/olwidget/templates/olwidget/editable_layer.html c513fea
@versae versae Update django-olwidget/olwidget/templates/olwidget/multi_layer_map.html 24ac22b
@versae versae Update django-olwidget/olwidget/templates/olwidget/editable_layer.html 51b0bde
@versae versae Update django-olwidget/olwidget/templates/olwidget/editable_layer.html 41640f6
@versae versae Update django-olwidget/olwidget/templates/olwidget/editable_layer.html df8eb6d
Commits on Mar 29, 2012
@slinkp slinkp Merge branch 'yourcelf-master' into extra_context_hook 18ce4cc
@slinkp slinkp Add get_extra_context() hook on the widgets too ebb2527
Commits on Apr 03, 2012
@yourcelf yourcelf Merge pull request #100 from openplans/slinkp-js-syntax-fixes
Slinkp js syntax fixes
2de264e
@yourcelf yourcelf Merge pull request #99 from openplans/extra_context_hook
Extra context hook: also useful on widgets
af7a98f
@yourcelf yourcelf Merge pull request #96 from versae/master
Storing the object olwidget.InfoMap into a variable
099ea68
@yourcelf yourcelf removing osmarender, as it seems to be dead. issue#98 067c769
@yourcelf yourcelf switching providers example to use google v3 api url; adding 'terrain…
…' alias for physical
1a82d65
@yourcelf yourcelf limiting to google API v 3.6 due to openlayers/openlayers@b17c7b6 ; a…
…ddressing issue #95
6e45292
@yourcelf yourcelf merging custom layer types from issue #84 (thanks philipn) 9600335
View
3  django-olwidget/olwidget/templates/olwidget/multi_layer_map.html
@@ -1,7 +1,8 @@
<div id="{{ id }}"></div>
{{ layer_html|join:"" }}
<script type="text/javascript">
- new olwidget.Map("{{ id }}", [
+ {{ setup_custom_layer_types|safe }}
+ var olwidget_{{ id }} = new olwidget.Map("{{ id }}", [
{{ layer_js|join:"," }}
],
{{ map_opts|safe }}
View
3  django-olwidget/olwidget/utils.py
@@ -11,6 +11,9 @@ def get_options(o):
options.update(o or {})
return options
+def get_custom_layer_types():
+ return getattr(settings, 'OLWIDGET_CUSTOM_LAYER_TYPES', {})
+
def url_join(*args):
return reduce(_reduce_url_parts, args)
View
23 django-olwidget/olwidget/widgets.py
@@ -59,6 +59,7 @@ def __init__(self, vector_layers=None, options=None, template=None,
# Though this layer is the olwidget.js default, it must be explicitly
# set so {{ form.media }} knows to include osm.
self.options['layers'] = self.options.get('layers', ['osm.mapnik'])
+ self.custom_layer_types = utils.get_custom_layer_types()
self.template = template or self.default_template
super(Map, self).__init__()
@@ -96,6 +97,7 @@ def render(self, name, value, attrs=None):
'layer_js': layer_js,
'layer_html': layer_html,
'map_opts': simplejson.dumps(utils.translate_options(self.options)),
+ 'setup_custom_layer_types': self._custom_layer_types_js(),
'STATIC_URL': settings.STATIC_URL,
}
context.update(self.get_extra_context())
@@ -117,6 +119,13 @@ def value_from_datadict(self, data, files, name):
""" Return an array of all layers' values. """
return [vl.value_from_datadict(data, files, lyr_name) for vl, lyr_name in zip(self.vector_layers, self._get_layer_names(name))]
+ def _custom_layer_types_js(self):
+ layer_types_js = ""
+ for typename in self.custom_layer_types:
+ js_def = self.custom_layer_types[typename]
+ layer_types_js += "olwidget.%s = {map: function() { return new %s }};" % (typename, js_def)
+ return layer_types_js
+
def _get_layer_names(self, name):
"""
If the user gave us a layer_names parameter, use that. Otherwise,
@@ -215,6 +224,18 @@ def render(self, name, value, attrs=None):
(javascript, html) = self.prepare(name, value, attrs)
return javascript
+ def get_extra_context(self):
+ """Hook that subclasses can override to add extra data for use
+ by the javascript in self.template. This should be invoked by
+ self.prepare().
+
+ Note that the base class itself doesn't invoke this, but
+ subclasses which render templates typically do. You'll also
+ want to override relevant templates to make use of the
+ provided data.
+ """
+ return {}
+
def __unicode__(self):
return self.render(None, None)
@@ -251,6 +272,7 @@ def prepare(self, name, value, attrs=None):
'options': simplejson.dumps(utils.translate_options(self.options)),
'STATIC_URL': settings.STATIC_URL,
}
+ context.update(self.get_extra_context())
js = mark_safe(render_to_string(self.template, context))
html = ""
return (js, html)
@@ -281,6 +303,7 @@ def prepare(self, name, value, attrs=None):
'options': simplejson.dumps(utils.translate_options(self.options)),
'STATIC_URL': settings.STATIC_URL,
}
+ context.update(self.get_extra_context())
js = mark_safe(render_to_string(self.template, context))
html = mark_safe(forms.Textarea().render(name, wkt, attrs))
return (js, html)
View
30 docs/_static/examples/other_providers.html
@@ -11,12 +11,12 @@
<script type='text/javascript' src='http://api.maps.yahoo.com/ajaxymap?v=3.0&appid=JNrvOMXV34Ft.LUs2zzCI9yVPrIX1KDJ1tiNHFam9mLWl64qgtbSjenTP.ua1UWbPCbp0w6r.A--'></script>
<!-- Google API key generated for olwidget.org -->
- <script type="text/javascript" src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAARaukg-vCnyMKCmf7W1mdOhRjXvsKc3juVddS1EQML_-vy6qUDRS3299mtIKSRBHXPVQ04fZiM38NdA"></script>
+ <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false&v=3.6"></script>
<!-- CloudMade API key generated for olwidget.org -->
<script type="text/javascript" src="js/cloudmade.js#06c005818e31487cb270b0bdfc71e115"></script>
- <script type='text/javascript' src='js/olwidget.js'></script>
+<script type="text/javascript" src="http://127.0.0.1:8000/static/olwidget/js/olwidget.js"></script>
<link rel="stylesheet" type="text/css" media="all" href="css/olwidget.css" />
<title>Other Map Providers</title>
<style type='text/css'>
@@ -31,6 +31,24 @@
<p>An example using all the available layers, including Google, Yahoo, Microsoft, Open Street Maps, and CloudMade. Additional layers from other providers supported by OpenLayers can be added manually (see this page's source for an example). Also, see an examle of <a href="just_custom_layer.html">using a custom tile layer alone</a>.</p>
<textarea id='my_textarea'></textarea>
<script type='text/javascript'>//<![CDATA[
+ // Adding a custom layer type
+ olwidget.registerCustomBaseLayers(
+ {
+ '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
+ },
+ ],
+ }
+ })
+
var map = new olwidget.EditableMap('my_textarea', {
geometry: 'polygon',
layers: [
@@ -47,12 +65,14 @@
've.hybrid',
'yahoo.map',
'osm.mapnik',
- 'osm.osmarender',
'wms.map',
- 'wms.nasa'
+ 'wms.nasa',
+ // Our custom layer type
+ 'custom.opengeo_osm',
]
});
- // How to add other layers from other providers
+
+ // Adding layers from other providers using the OpenLayers API directly:
map.addLayer(new OpenLayers.Layer.WMS( "OpenLayers WMS again",
"http://labs.metacarta.com/wms/vmap0", {layers: 'basic'} ));
//]]></script>
View
20 docs/django-olwidget.rst
@@ -550,6 +550,26 @@ General map display
Remember to include ``GOOGLE_API_KEY``, ``YAHOO_APP_ID``, or
``CLOUDMADE_API_KEY`` in your ``settings.py`` if you use any of those
layers.
+
+ Custom layer types from other providers can be used by listing their
+ JavaScript construction string in the ``OLWIDGET_CUSTOM_LAYER_TYPES``
+ setting option. Here's an example::
+
+ OLWIDGET_CUSTOM_LAYER_TYPES = {
+ 'opengeo_osm': """OpenLayers.Layer.WMS(
+ 'OpenStreetMap (OpenGeo)',
+ 'http://maps.opengeo.org/geowebcache/service/wms',
+ {
+ layers: 'openstreetmap',
+ format: 'image/png',
+ bgColor: '#A1BDC4',
+ },
+ {wrapDateLine: true}
+ )"""
+ }
+
+ We can then access this layer type as ``opengeo_osm``.
+
``default_lat`` (float; default 0)
Latitude for the center point of the map.
``default_lon`` (float; default 0)
View
4 docs/olwidget.js.rst
@@ -307,7 +307,9 @@ General map display
``'wms.nasa'``, ``'yahoo.map'``, ``'yahoo.satellite'``, ``'yahoo.hybrid'``
and ``'cloudmade.<num>'`` (where ``<num>``
is the number for a cloudmade style). A blank map can be obtained using
- ``'wms.blank'``. Additional providers or options can be manually added
+ ``'wms.blank'``.
+
+ Additional options and layers can also be manually added
using the normal OpenLayers apis (see `this provider example
<examples/other_providers.html>`_).
View
19 js/olwidget.js
@@ -81,10 +81,6 @@ var olwidget = {
"http://c.tile.openstreetmap.org/${z}/${x}/${y}.png"
],
{ numZoomLevels: 19 });
- },
- osmarender: function() {
- return new OpenLayers.Layer.OSM.Osmarender(
- 'OpenStreetMap (Osmarender)');
}
},
google: {
@@ -96,7 +92,10 @@ var olwidget = {
{sphericalMercator: true, numZoomLevels: 20});
},
physical: function() {
- return new OpenLayers.Layer.Google("Google Physical",
+ return this.terrain();
+ },
+ terrain: function() {
+ return new OpenLayers.Layer.Google("Google Terrain",
{sphericalMercator: true, type: google.maps.MapTypeId.TERRAIN});
},
satellite: function() {
@@ -188,10 +187,13 @@ var olwidget = {
}
return destination;
},
-
isCollectionEmpty: function(geom) {
/* Is the provided collection empty? */
return !(geom && (geom.constructor != Array || geom[0] != undefined));
+ },
+ _customBaseLayers: {},
+ registerCustomBaseLayers: function(layer_descriptions) {
+ OpenLayers.Util.extend(this._customBaseLayers, layer_descriptions);
}
};
@@ -269,7 +271,10 @@ olwidget.Map = OpenLayers.Class(OpenLayers.Map, {
var layers = [];
for (var i = 0; i < opts.layers.length; i++) {
var parts = opts.layers[i].split(".");
- layers.push(olwidget[parts[0]].map(parts[1]));
+ var map_service = olwidget[parts[0]];
+ var map_type = parts[1];
+
+ layers.push(map_service.map(map_type));
// workaround for problems with Microsoft layers and vector layer
// drift (see http://openlayers.com/dev/examples/ve-novibrate.html)

No commit comments for this range

Something went wrong with that request. Please try again.