Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 3162 recline view #3200

Merged
merged 8 commits into from Aug 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 24 additions & 0 deletions ckanext/reclineview/plugin.py
Expand Up @@ -5,13 +5,23 @@
from ckan.common import json
import ckan.plugins as p
import ckan.plugins.toolkit as toolkit
from pylons import config

log = getLogger(__name__)
ignore_empty = p.toolkit.get_validator('ignore_empty')
natural_number_validator = p.toolkit.get_validator('natural_number_validator')
Invalid = p.toolkit.Invalid


def get_mapview_config():
'''
Extracts and returns map view configuration of the reclineview extension.
'''
namespace = 'ckanext.spatial.common_map.'
return dict([(k.replace(namespace, ''), v) for k, v in config.iteritems()
if k.startswith(namespace)])


def in_list(list_possible_values):
'''
Validator that checks that the input value is one of the given
Expand Down Expand Up @@ -77,6 +87,8 @@ class ReclineView(ReclineViewBase):
This extension views resources using a Recline MultiView.
'''

p.implements(p.ITemplateHelpers, inherit=True)

def info(self):
return {'name': 'recline_view',
'title': 'Data Explorer',
Expand All @@ -98,6 +110,11 @@ def can_view(self, data_dict):
else:
return False

def get_helpers(self):
return {
'get_map_config': get_mapview_config
}


class ReclineGridView(ReclineViewBase):
'''
Expand Down Expand Up @@ -174,6 +191,8 @@ class ReclineMapView(ReclineViewBase):
This extension views resources using a Recline map.
'''

p.implements(p.ITemplateHelpers, inherit=True)

map_field_types = [{'value': 'lat_long',
'text': 'Latitude / Longitude fields'},
{'value': 'geojson', 'text': 'GeoJSON'}]
Expand Down Expand Up @@ -234,3 +253,8 @@ def setup_template_variables(self, context, data_dict):

def form_template(self, context, data_dict):
return 'recline_map_form.html'

def get_helpers(self):
return {
'get_mapview_config': get_mapview_config
}
48 changes: 41 additions & 7 deletions ckanext/reclineview/theme/public/recline_view.js
Expand Up @@ -46,7 +46,7 @@ this.ckan.module('recline_view', function (jQuery, _) {
}
}

var errorMsg, dataset;
var errorMsg, dataset, map_config;

if (!resourceData.datastore_active) {
recline.Backend.DataProxy.timeout = 10000;
Expand All @@ -58,6 +58,8 @@ this.ckan.module('recline_view', function (jQuery, _) {

dataset = new recline.Model.Dataset(resourceData);

map_config = this.options.map_config;

var query = new recline.Model.Query();
query.set({ size: reclineView.limit || 100 });
query.set({ from: reclineView.offset || 0 });
Expand Down Expand Up @@ -119,9 +121,9 @@ this.ckan.module('recline_view', function (jQuery, _) {
state.lonField = reclineView.longitude_field;
}

view = new recline.View.Map({model: dataset, state: state});
view = new recline.View.Map(this._reclineMapViewOptions(dataset, this.options.map_config));
} else if(reclineView.view_type === "recline_view") {
view = this._newDataExplorer(dataset);
view = this._newDataExplorer(dataset, this.options.map_config);
} else {
// default to Grid
view = new recline.View.SlickGrid({model: dataset});
Expand All @@ -148,7 +150,41 @@ this.ckan.module('recline_view', function (jQuery, _) {
}
},

_newDataExplorer: function (dataset) {
_reclineMapViewOptions: function(dataset, map_config) {
var tile_url, attribution, subdomains;
tile_url = attribution = subdomains = '';

if (map_config.type == 'mapbox') {
// MapBox base map
if (!map_config['mapbox.map_id'] || !map_config['mapbox.access_token']) {
throw '[CKAN Map Widgets] You need to provide a map ID ([account].[handle]) and an access token when using a MapBox layer. ' +
'See http://www.mapbox.com/developers/api-overview/ for details';
}

tile_url = '//{s}.tiles.mapbox.com/v4/' + map_config['mapbox.map_id'] + '/{z}/{x}/{y}.png?access_token=' + map_config['mapbox.access_token'];
handle = map_config['mapbox.map_id'];
subdomains = map_config.subdomains || 'abcd';
attribution = map_config.attribution || 'Data: <a href="http://osm.org/copyright" target="_blank">OpenStreetMap</a>, Design: <a href="http://mapbox.com/about/maps" target="_blank">MapBox</a>';

} else if (map_config.type == 'custom') {
// Custom XYZ layer
tile_url = map_config['custom.url'] || '';
attribution = map_config.attribution || '';
subdomains = map_config.subdomains || '';

if (map_config['custom.tms'])
var tms = map_config['custom.tms'];
}

return {
model: dataset,
mapTilesURL: tile_url,
mapTilesAttribution: attribution,
mapTilesSubdomains: subdomains
};
},

_newDataExplorer: function (dataset, map_config) {
var views = [
{
id: 'grid',
Expand All @@ -167,9 +203,7 @@ this.ckan.module('recline_view', function (jQuery, _) {
{
id: 'map',
label: 'Map',
view: new recline.View.Map({
model: dataset
})
view: new recline.View.Map(this._reclineMapViewOptions(dataset, map_config))
}
];

Expand Down
2 changes: 2 additions & 0 deletions ckanext/reclineview/theme/templates/recline_view.html
Expand Up @@ -2,10 +2,12 @@

{% block page %}

{% set map_config = h.get_map_config() or h.get_mapview_config() %}
<div data-module="recline_view"
data-module-site_url="{{ h.dump_json(h.url('/', locale='default', qualified=true)) }}"
data-module-resource = "{{ h.dump_json(resource_json) }}";
data-module-resource-view = "{{ h.dump_json(resource_view_json) }}";
data-module-map_config= "{{ h.dump_json(map_config) }}";
>
<h4 class="loading-dialog">
<div class="loading-spinner"></div>
Expand Down
18 changes: 18 additions & 0 deletions doc/maintaining/data-viewer.rst
Expand Up @@ -157,6 +157,24 @@ to the rendered features.

This plugin requires data to be in the DataStore.

There is partial support to change the map tiles to a different service, such
as Mapbox. Look below for an example to add to your configuration file::

#Mapbox example:
ckanext.spatial.common_map.type = mapbox
ckanext.spatial.common_map.mapbox.map_id = <id>
ckanext.spatial.common_map.mapbox.access_token = <token>
ckanext.spatial.common_map.attribution=© <a target=_blank href='https://www.mapbox.com/map-feedback/'>Mapbox</a> © <a target=_blank href='http://www.openstreetmap.org/copyright'>OpenStreetMap</a>
ckanext.spatial.common_map.subdomains = <subdomains>

#Custom example:
ckanext.spatial.common_map.type = custom
ckanext.spatial.common_map.custom.url = <url>
ckanext.spatial.common_map.custom.tms = <tms>
ckanext.spatial.common_map.attribution = <copyright link>
ckanext.spatial.common_map.subdomains = <subdomains>


Text view
+++++++++

Expand Down