diff --git a/ckanext/spatial/plugin.py b/ckanext/spatial/plugin.py index 4371731..39caae0 100644 --- a/ckanext/spatial/plugin.py +++ b/ckanext/spatial/plugin.py @@ -168,66 +168,6 @@ class SpatialQueryWidget(p.SingletonPlugin): return stream -class DatasetExtentMap(p.SingletonPlugin): - - p.implements(p.IGenshiStreamFilter) - p.implements(p.IConfigurer, inherit=True) - - def filter(self, stream): - from pylons import request, tmpl_context as c - - route_dict = request.environ.get('pylons.routes_dict') - route = '%s/%s' % (route_dict.get('controller'), route_dict.get('action')) - routes_to_filter = config.get('ckan.spatial.dataset_extent_map.routes', 'package/read').split(' ') - if route in routes_to_filter and c.pkg.id: - - 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': p.toolkit._(title), - 'map_type': map_type, - 'js_library_links': js_library_links, - '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')\ - .append(HTML(html.PACKAGE_MAP_EXTRA_FOOTER % data)) - - - - return stream - - def update_config(self, config): - - - here = os.path.dirname(__file__) - - template_dir = os.path.join(here, 'templates') - public_dir = os.path.join(here, 'public') - - if config.get('extra_template_paths'): - config['extra_template_paths'] += ','+template_dir - else: - config['extra_template_paths'] = template_dir - if config.get('extra_public_paths'): - config['extra_public_paths'] += ','+public_dir - else: - config['extra_public_paths'] = public_dir - class CatalogueServiceWeb(p.SingletonPlugin): p.implements(p.IConfigurable) p.implements(p.IRoutes) diff --git a/ckanext/spatial/public/css/dataset_map.css b/ckanext/spatial/public/css/dataset_map.css index 920a3f6..e43a760 100644 --- a/ckanext/spatial/public/css/dataset_map.css +++ b/ckanext/spatial/public/css/dataset_map.css @@ -2,6 +2,10 @@ height: 200px; } +.module-content #dataset-map-container{ + height: 250px; +} + #dataset-map-attribution{ font-size: x-small; } diff --git a/ckanext/spatial/public/js/dataset_map.js b/ckanext/spatial/public/js/dataset_map.js index 87a37be..8bf39a3 100644 --- a/ckanext/spatial/public/js/dataset_map.js +++ b/ckanext/spatial/public/js/dataset_map.js @@ -1,161 +1,166 @@ -var CKAN = CKAN || {}; +// Dataset map module +this.ckan.module('dataset-map', function (jQuery, _) { -CKAN.DatasetMap = function($){ + return { + options: { + i18n: { + }, + styles: { + "point":{ + "externalGraphic": "/img/marker.png", + "graphicWidth":14, + "graphicHeight":25, + "fillOpacity":1 + }, + "default":{ + "fillColor":"#FCF6CF", + "strokeColor":"#B52", + "strokeWidth":2, + "fillOpacity":0.4 + } + } + }, - // Private + initialize: function () { - var getGeomType = function(feature){ + this.extent = this.el.data("extent"); + + jQuery.proxyAll(this, /_on/); + this.el.ready(this._onReady); + + }, + + map: null, + + _onReady: function(){ + + if (!this.extent) + return false; + + this.map_type = this.map_type || "osm"; + + // Setup some sizes + var width = $(this.el).width(); + if (width > 1024) { + width = 1024; + } + var height = ($(this.el).height() || width/2); + $("#dataset-map-container").width(width); + $("#dataset-map-container").height(height); + + var showZoomControls = (width > 300); + + if (this.map_type=='osm') { + var mapquestTiles = [ + "http://otile1.mqcdn.com/tiles/1.0.0/osm/${z}/${x}/${y}.jpg", + "http://otile2.mqcdn.com/tiles/1.0.0/osm/${z}/${x}/${y}.jpg", + "http://otile3.mqcdn.com/tiles/1.0.0/osm/${z}/${x}/${y}.jpg", + "http://otile4.mqcdn.com/tiles/1.0.0/osm/${z}/${x}/${y}.jpg"]; + + var layers = [ + new OpenLayers.Layer.OSM("MapQuest-OSM Tiles", mapquestTiles) + ]; + + // Create a new map + this.map = new OpenLayers.Map("dataset-map-container" , + { + "projection": new OpenLayers.Projection("EPSG:900913"), + "displayProjection": new OpenLayers.Projection("EPSG:4326"), + "units": "m", + "numZoomLevels": 18, + "maxResolution": 156543.0339, + "maxExtent": new OpenLayers.Bounds(-20037508, -20037508, 20037508, 20037508.34), + "controls": [ + new OpenLayers.Control.Navigation() + ], + "theme":"/js/vendor/openlayers/theme/default/style.css" + }); + if (showZoomControls) this.map.addControl(new OpenLayers.Control.PanZoom()); + var internalProjection = new OpenLayers.Projection("EPSG:900913"); + } else if (this.map_type=='os') { + + var copyrightStatements = "Contains Ordnance Survey data (c) Crown copyright and database right [2012]
" + "Contains Royal Mail data (c) Royal Mail copyright and database right [2012]
" + "Contains bathymetry data by GEBCO (c) Copyright [2012]
" + "Contains data by Land & Property Services (Northern Ireland) (c) Crown copyright [2012]"; + + // Create a new map + var layers = [ + new OpenLayers.Layer.WMS("Geoserver layers - Tiled", +'http://osinspiremappingprod.ordnancesurvey.co.uk/geoserver/gwc/service/wms', { + LAYERS: 'InspireETRS89', + STYLES: '', + format: 'image/png', + tiled: true + }, { + buffer: 0, + displayOutsideMaxExtent: true, + isBaseLayer: true, + attribution: copyrightStatements, + transitionEffect: 'resize' + } + ) + ]; + OpenLayers.DOTS_PER_INCH = 90.71428571428572; + + var options = { + size: new OpenLayers.Size(width, height), + scales: [15000000, 10000000, 5000000, 1000000, 250000, 75000], + maxExtent: new OpenLayers.Bounds(-30, 48.00, 3.50, 64.00), + restrictedExtent: new OpenLayers.Bounds(-30, 48.00, 3.50, 64.00), + tileSize: new OpenLayers.Size(250, 250), + units: 'degrees', + projection: "EPSG:4258" + }; + + this.map = new OpenLayers.Map("dataset-map-container", {}); + + + + + // Set the options on the map +this.map.setOptions(options); + + var internalProjection = new OpenLayers.Projection("EPSG:4258"); + } + this.map.addLayers(layers); + + var getGeomType = function(feature){ return feature.geometry.CLASS_NAME.split(".").pop().toLowerCase() - } + } - var getStyle = function(geom_type){ - var styles = CKAN.DatasetMap.styles; + var getStyle = function(geom_type, styles){ var style = (styles[geom_type]) ? styles[geom_type] : styles["default"]; return new OpenLayers.StyleMap(OpenLayers.Util.applyDefaults( - style, OpenLayers.Feature.Vector.style["default"])) + style, OpenLayers.Feature.Vector.style["default"])) + } + + var geojson_format = new OpenLayers.Format.GeoJSON({ + "internalProjection": internalProjection, + "externalProjection": new OpenLayers.Projection("EPSG:4326") + }); + + // Add the Dataset Extent box + var features = geojson_format.read(this.extent) + var geom_type = getGeomType(features[0]) + + var vector_layer = new OpenLayers.Layer.Vector("Dataset Extent", + { + "projection": new OpenLayers.Projection("EPSG:4326"), + "styleMap": getStyle(geom_type, this.options.styles) + } + ); + + this.map.addLayer(vector_layer); + vector_layer.addFeatures(features); + if (geom_type == "point"){ + this.map.setCenter(new OpenLayers.LonLat(features[0].geometry.x,features[0].geometry.y), + this.map.numZoomLevels/2) + } else { + this.map.zoomToExtent(vector_layer.getDataExtent()); + } + + } + } +}); - // Public - return { - map: null, - - extent: null, - - styles: { - "point":{ - "externalGraphic": "/img/marker.png", - "graphicWidth":14, - "graphicHeight":25, - "fillOpacity":1 - }, - "default":{ -// "fillColor":"#ee9900", - "fillColor":"#FCF6CF", - "strokeColor":"#B52", - "strokeWidth":2, - "fillOpacity":0.4 -// "pointRadius":7 - } - }, - - setup: function(){ - if (!this.extent) - return false; - - CKAN.DatasetMap.map_type = CKAN.DatasetMap.map_type || "osm"; - CKAN.DatasetMap.element = CKAN.DatasetMap.element || "#dataset-map-container"; - - // Setup some sizes - var width = $(CKAN.DatasetMap.element).width(); - if (width > 1024) { - width = 1024; - } - var height = ($(CKAN.DatasetMap.element).height() || width/2); - $("#dataset-map-container").width(width); - $("#dataset-map-container").height(height); - - var showZoomControls = (width > 300); - - if (this.map_type=='osm') { - var mapquestTiles = [ - "http://otile1.mqcdn.com/tiles/1.0.0/osm/${z}/${x}/${y}.jpg", - "http://otile2.mqcdn.com/tiles/1.0.0/osm/${z}/${x}/${y}.jpg", - "http://otile3.mqcdn.com/tiles/1.0.0/osm/${z}/${x}/${y}.jpg", - "http://otile4.mqcdn.com/tiles/1.0.0/osm/${z}/${x}/${y}.jpg"]; - - var layers = [ - new OpenLayers.Layer.OSM("MapQuest-OSM Tiles", mapquestTiles) - ]; - - // Create a new map - this.map = new OpenLayers.Map("dataset-map-container" , - { - "projection": new OpenLayers.Projection("EPSG:900913"), - "displayProjection": new OpenLayers.Projection("EPSG:4326"), - "units": "m", - "numZoomLevels": 18, - "maxResolution": 156543.0339, - "maxExtent": new OpenLayers.Bounds(-20037508, -20037508, 20037508, 20037508.34), - "controls": [ - new OpenLayers.Control.Navigation() - ], - "theme":"/ckanext/spatial/js/openlayers/theme/default/style.css" - }); - if (showZoomControls) this.map.addControl(new OpenLayers.Control.PanZoom()); - var internalProjection = new OpenLayers.Projection("EPSG:900913"); - } else if (this.map_type=='os') { - - var copyrightStatements = "Contains Ordnance Survey data (c) Crown copyright and database right [2012]
" + "Contains Royal Mail data (c) Royal Mail copyright and database right [2012]
" + "Contains bathymetry data by GEBCO (c) Copyright [2012]
" + "Contains data by Land & Property Services (Northern Ireland) (c) Crown copyright [2012]"; - - // Create a new map - var layers = [ - new OpenLayers.Layer.WMS("Geoserver layers - Tiled", - 'http://osinspiremappingprod.ordnancesurvey.co.uk/geoserver/gwc/service/wms', { - LAYERS: 'InspireETRS89', - STYLES: '', - format: 'image/png', - tiled: true - }, { - buffer: 0, - displayOutsideMaxExtent: true, - isBaseLayer: true, - attribution: copyrightStatements, - transitionEffect: 'resize' - } - ) - ]; - OpenLayers.DOTS_PER_INCH = 90.71428571428572; - - var options = { - size: new OpenLayers.Size(width, height), - scales: [15000000, 10000000, 5000000, 1000000, 250000, 75000], - maxExtent: new OpenLayers.Bounds(-30, 48.00, 3.50, 64.00), - restrictedExtent: new OpenLayers.Bounds(-30, 48.00, 3.50, 64.00), - tileSize: new OpenLayers.Size(250, 250), - units: 'degrees', - projection: "EPSG:4258" - }; - - this.map = new OpenLayers.Map("dataset-map-container", {}); - - // Set the options on the map - this.map.setOptions(options); - - var internalProjection = new OpenLayers.Projection("EPSG:4258"); - } - this.map.addLayers(layers); - - var geojson_format = new OpenLayers.Format.GeoJSON({ - "internalProjection": internalProjection, - "externalProjection": new OpenLayers.Projection("EPSG:4326") - }); - - // Add the Dataset Extent box - var features = geojson_format.read(this.extent) - var geom_type = getGeomType(features[0]) - - var vector_layer = new OpenLayers.Layer.Vector("Dataset Extent", - { - "projection": new OpenLayers.Projection("EPSG:4326"), - "styleMap": getStyle(geom_type) - } - ); - - this.map.addLayer(vector_layer); - vector_layer.addFeatures(features); - if (geom_type == "point"){ - this.map.setCenter(new OpenLayers.LonLat(features[0].geometry.x,features[0].geometry.y), - this.map.numZoomLevels/2) - } else { - this.map.zoomToExtent(vector_layer.getDataExtent()); - } - - - } - } -}(jQuery) - - -OpenLayers.ImgPath = "/ckanext/spatial/js/openlayers/img/"; - +OpenLayers.ImgPath = "/js/vendor/openlayers/img/"; diff --git a/ckanext/spatial/public/resource.config b/ckanext/spatial/public/resource.config index 146997d..3bdbf02 100644 --- a/ckanext/spatial/public/resource.config +++ b/ckanext/spatial/public/resource.config @@ -4,8 +4,17 @@ main = base/main [groups] +dataset_map = + + js/vendor/openlayers/OpenLayers_dataset_map.js + + js/dataset_map.js + + css/dataset_map.css + + wms = - + js/vendor/openlayers/OpenLayers_wms_preview.js js/wms_preview.js diff --git a/ckanext/spatial/templates/spatial/snippets/dataset_map.html b/ckanext/spatial/templates/spatial/snippets/dataset_map.html index 5641a6b..6128e35 100644 --- a/ckanext/spatial/templates/spatial/snippets/dataset_map.html +++ b/ckanext/spatial/templates/spatial/snippets/dataset_map.html @@ -1,12 +1,20 @@ +{# +Displays a map showing the dataset extent on the dataset page main body + +extent + GeoJSON representation of the geometry to draw (ie the value of the + 'spatial' extra) + + e.g. + {% set dataset_extent = h.get_pkg_dict_extra(c.pkg_dict, 'spatial', '') %} + {% if dataset_extent %} + {% snippet "spatial/snippets/dataset_map.html", extent=dataset_extent %} + {% endif %} + +#}
-

Dataset Extent

-
-
-
- Map data CC-BY-SA by OpenStreetMap | - Tiles by MapQuest -
-
+

{{ _('Dataset extent') }}

+ {% snippet "spatial/snippets/dataset_map_base.html", extent=extent %}
diff --git a/ckanext/spatial/templates/spatial/snippets/dataset_map_base.html b/ckanext/spatial/templates/spatial/snippets/dataset_map_base.html new file mode 100644 index 0000000..0dcf533 --- /dev/null +++ b/ckanext/spatial/templates/spatial/snippets/dataset_map_base.html @@ -0,0 +1,20 @@ +{# +Displays a map showing the dataset extent on the dataset page sidebar + +extent + GeoJSON representation of the geometry to draw (ie the value of the + 'spatial' extra) + + e.g. + {% snippet "spatial/snippets/dataset_map_base.html", extent=extent %} + +#} +
+
+
+
Map data CC-BY-SA by OpenStreetMap
+
Tiles by MapQuest
+
+
+ +{% resource 'ckanext-spatial/dataset_map' %} diff --git a/ckanext/spatial/templates/spatial/snippets/dataset_map_scripts.html b/ckanext/spatial/templates/spatial/snippets/dataset_map_scripts.html deleted file mode 100644 index 7ffd86c..0000000 --- a/ckanext/spatial/templates/spatial/snippets/dataset_map_scripts.html +++ /dev/null @@ -1,9 +0,0 @@ - - - - diff --git a/ckanext/spatial/templates/spatial/snippets/dataset_map_sidebar.html b/ckanext/spatial/templates/spatial/snippets/dataset_map_sidebar.html index 655e40b..f562861 100644 --- a/ckanext/spatial/templates/spatial/snippets/dataset_map_sidebar.html +++ b/ckanext/spatial/templates/spatial/snippets/dataset_map_sidebar.html @@ -1,10 +1,19 @@ +{# +Displays a map showing the dataset extent on the dataset page sidebar + +extent + GeoJSON representation of the geometry to draw (ie the value of the + 'spatial' extra) + + e.g. + {% set dataset_extent = h.get_pkg_dict_extra(c.pkg_dict, 'spatial', '') %} + {% if dataset_extent %} + {% snippet "spatial/snippets/dataset_map_sidebar.html", extent=dataset_extent %} + {% endif %} + +#} +
-

Dataset extent

-
-
-
-
Map data CC-BY-SA by OpenStreetMap
-
Tiles by MapQuest
-
-
+

{{ _('Dataset extent') }}

+ {% snippet "spatial/snippets/dataset_map_base.html", extent=extent %}
diff --git a/ckanext/spatial/templates/spatial/snippets/dataset_map_styles.html b/ckanext/spatial/templates/spatial/snippets/dataset_map_styles.html deleted file mode 100644 index 4b8558b..0000000 --- a/ckanext/spatial/templates/spatial/snippets/dataset_map_styles.html +++ /dev/null @@ -1 +0,0 @@ - diff --git a/setup.py b/setup.py index b92e694..b3eb851 100644 --- a/setup.py +++ b/setup.py @@ -31,7 +31,6 @@ setup( spatial_metadata=ckanext.spatial.plugin:SpatialMetadata spatial_query=ckanext.spatial.plugin:SpatialQuery spatial_query_widget=ckanext.spatial.plugin:SpatialQueryWidget - dataset_extent_map=ckanext.spatial.plugin:DatasetExtentMap wms_preview=ckanext.spatial.nongeos_plugin:WMSPreview cswserver=ckanext.spatial.plugin:CatalogueServiceWeb spatial_harvest_metadata_api=ckanext.spatial.plugin:HarvestMetadataApi