[#6] Update dataset map to be a pure snippet
No need to load an extension.
This commit is contained in:
parent
21a85a6b3f
commit
3da5807eb4
|
@ -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 = '<script type="text/javascript" src="/ckanext/spatial/js/openlayers/OpenLayers_dataset_map.js"></script>'
|
||||
map_attribution = html.MAP_ATTRIBUTION_OSM
|
||||
elif map_type == 'os':
|
||||
js_library_links = '<script src="http://osinspiremappingprod.ordnancesurvey.co.uk/libraries/openlayers-openlayers-56e25fc/lib/OpenLayers.js" type="text/javascript"></script>'
|
||||
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)
|
||||
|
|
|
@ -2,6 +2,10 @@
|
|||
height: 200px;
|
||||
}
|
||||
|
||||
.module-content #dataset-map-container{
|
||||
height: 250px;
|
||||
}
|
||||
|
||||
#dataset-map-attribution{
|
||||
font-size: x-small;
|
||||
}
|
||||
|
|
|
@ -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] <br>" + "Contains Royal Mail data (c) Royal Mail copyright and database right [2012]<br>" + "Contains bathymetry data by GEBCO (c) Copyright [2012]<br>" + "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] <br>" + "Contains Royal Mail data (c) Royal Mail copyright and database right [2012]<br>" + "Contains bathymetry data by GEBCO (c) Copyright [2012]<br>" + "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/";
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 %}
|
||||
|
||||
#}
|
||||
<article class="module prose">
|
||||
<section class="module-content">
|
||||
<h3>Dataset Extent</h3>
|
||||
<div class="dataset-map">
|
||||
<div id="dataset-map-container"></div>
|
||||
<div id="dataset-map-attribution">
|
||||
Map data CC-BY-SA by <a href="http://openstreetmap.org">OpenStreetMap</a> |
|
||||
Tiles by <a href="http://www.mapquest.com">MapQuest</a>
|
||||
</div>
|
||||
</div>
|
||||
<h3>{{ _('Dataset extent') }}</h3>
|
||||
{% snippet "spatial/snippets/dataset_map_base.html", extent=extent %}
|
||||
</section>
|
||||
</article>
|
||||
|
|
|
@ -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 %}
|
||||
|
||||
#}
|
||||
<div class="dataset-map" data-module="dataset-map" data-extent="{{ extent }}">
|
||||
<div id="dataset-map-container"></div>
|
||||
<div id="dataset-map-attribution">
|
||||
<div>Map data CC-BY-SA by <a href="http://openstreetmap.org">OpenStreetMap</a></div>
|
||||
<div>Tiles by <a href="http://www.mapquest.com">MapQuest</a></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% resource 'ckanext-spatial/dataset_map' %}
|
|
@ -1,9 +0,0 @@
|
|||
<script src="{% url_for_static '/base/vendor/jquery.js' %}"></script>
|
||||
<script src="{% url_for_static '/js/vendor/openlayers/OpenLayers_dataset_map.js' %}"></script>
|
||||
<script src="{% url_for_static '/js/dataset_map.js' %}"></script>
|
||||
<script>
|
||||
$(document).ready(function(){
|
||||
CKAN.DatasetMap.extent = '{{ h.escape_js(dataset_extent) | safe}}';
|
||||
CKAN.DatasetMap.setup();
|
||||
})
|
||||
</script>
|
|
@ -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 %}
|
||||
|
||||
#}
|
||||
|
||||
<section class="module module-narrow dataset-map">
|
||||
<h2 class="module-heading"><i class="icon-medium icon-globe"></i> Dataset extent</h2>
|
||||
<div class="dataset-map">
|
||||
<div id="dataset-map-container"></div>
|
||||
<div id="dataset-map-attribution">
|
||||
<div>Map data CC-BY-SA by <a href="http://openstreetmap.org">OpenStreetMap</a></div>
|
||||
<div>Tiles by <a href="http://www.mapquest.com">MapQuest</a></div>
|
||||
</div>
|
||||
</div>
|
||||
<h2 class="module-heading"><i class="icon-medium icon-globe"></i> {{ _('Dataset extent') }}</h2>
|
||||
{% snippet "spatial/snippets/dataset_map_base.html", extent=extent %}
|
||||
</section>
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
<link type="text/css" rel="stylesheet" media="all" href="/ckanext/spatial/css/dataset_map.css" />
|
1
setup.py
1
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
|
||||
|
|
Loading…
Reference in New Issue