From 745bed4e771465784fd856c91b63407ebd62f80c Mon Sep 17 00:00:00 2001 From: David Read Date: Tue, 22 May 2012 10:51:44 +0100 Subject: [PATCH] Customising extent map for dgu. --- README.rst | 5 ++++ ckanext/spatial/html.py | 10 ++++++- ckanext/spatial/plugin.py | 27 +++++++++++-------- .../public/ckanext/spatial/js/dataset_map.js | 4 +-- 4 files changed, 32 insertions(+), 14 deletions(-) diff --git a/README.rst b/README.rst index d5b0873..7b7e3db 100644 --- a/README.rst +++ b/README.rst @@ -85,6 +85,11 @@ The Dataset Extent Map provides two different map types. It defaults to 'osm' bu ckan.spatial.dataset_extent_map.map_type = os +The Dataset Extent Map will be inserted by default at the end of the dataset page. This can be changed by supplying an alternative element_id to the default:: + + ckan.spatial.dataset_extent_map.element_id = dataset + + SOLR Configuration ------------------ diff --git a/ckanext/spatial/html.py b/ckanext/spatial/html.py index f592e12..f8c6c58 100644 --- a/ckanext/spatial/html.py +++ b/ckanext/spatial/html.py @@ -4,7 +4,14 @@ MAP_VIEW=""" """ -PACKAGE_MAP=""" +PACKAGE_MAP_BASIC=""" +
+
+%(map_attribution)s +
+""" + +PACKAGE_MAP_EXTENDED="""

%(title)s

@@ -25,6 +32,7 @@ PACKAGE_MAP_EXTRA_FOOTER=""" $(document).ready(function(){ CKAN.DatasetMap.map_type = '%(map_type)s'; CKAN.DatasetMap.extent = '%(extent)s'; + CKAN.DatasetMap.element = '#%(element_id)s'; CKAN.DatasetMap.setup(); }) //]]> diff --git a/ckanext/spatial/plugin.py b/ckanext/spatial/plugin.py index ff9dd45..7d17ff6 100644 --- a/ckanext/spatial/plugin.py +++ b/ckanext/spatial/plugin.py @@ -174,13 +174,6 @@ class DatasetExtentMap(SingletonPlugin): def filter(self, stream): from pylons import request, tmpl_context as c - map_type = config.get('ckan.spatial.dataset_extent_map.map_type', 'osm') - if map_type == 'osm': - js_library_links = '' - map_attribution = html.MAP_ATTRIBUTION_OSM - elif map_type == 'os': - js_library_links = '' - map_attribution = '' # done in the js instead route_dict = request.environ.get('pylons.routes_dict') route = '%s/%s' % (route_dict.get('controller'), route_dict.get('action')) @@ -189,13 +182,25 @@ class DatasetExtentMap(SingletonPlugin): extent = c.pkg.extras.get('spatial',None) if extent: + map_element_id = config.get('ckan.spatial.dataset_extent_map.element_id', 'dataset') + title = config.get('ckan.spatial.dataset_extent_map.title', 'Geographic extent') + body_html = html.PACKAGE_MAP_EXTENDED if title else html.PACKAGE_MAP_BASIC + map_type = config.get('ckan.spatial.dataset_extent_map.map_type', 'osm') + if map_type == 'osm': + js_library_links = '' + map_attribution = html.MAP_ATTRIBUTION_OSM + elif map_type == 'os': + js_library_links = '' + map_attribution = '' # done in the js instead + data = {'extent': extent, - 'title': _('Geographic extent'), + 'title': _(title), 'map_type': map_type, 'js_library_links': js_library_links, - 'map_attribution': map_attribution} - stream = stream | Transformer('body//div[@id="dataset"]')\ - .append(HTML(html.PACKAGE_MAP % data)) + 'map_attribution': map_attribution, + 'element_id': map_element_id} + stream = stream | Transformer('body//div[@id="%s"]' % map_element_id)\ + .append(HTML(body_html % data)) stream = stream | Transformer('head')\ .append(HTML(html.PACKAGE_MAP_EXTRA_HEADER % data)) stream = stream | Transformer('body')\ diff --git a/ckanext/spatial/public/ckanext/spatial/js/dataset_map.js b/ckanext/spatial/public/ckanext/spatial/js/dataset_map.js index a414756..8e5b9e9 100644 --- a/ckanext/spatial/public/ckanext/spatial/js/dataset_map.js +++ b/ckanext/spatial/public/ckanext/spatial/js/dataset_map.js @@ -44,11 +44,11 @@ CKAN.DatasetMap = function($){ return false; // Setup some sizes - var width = $("#dataset").width(); + var width = $(CKAN.DatasetMap.element).width(); if (width > 1024) { width = 1024; } - var height = width/2; + var height = ($(CKAN.DatasetMap.element).height() || width/2); $("#dataset-map-container").width(width); $("#dataset-map-container").height(height);