Skip to content

Commit

Permalink
fix map functionalities (#436)
Browse files Browse the repository at this point in the history
* fix map functionalities
* replace the map qlr link name with the new wording in test_view
* use layer name for the zip file when download data layers in the map

fix #207
fix #390
fix #152
  • Loading branch information
boney-bun authored Jul 2, 2018
1 parent 30828ab commit ce61f45
Show file tree
Hide file tree
Showing 8 changed files with 748 additions and 14 deletions.
701 changes: 699 additions & 2 deletions geonode/client/templates/leaflet/maps/map_detail.html

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions geonode/client/templates/leaflet/maps/map_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,9 @@ <h4 class="modal-title">Map Updated</h4>
title: 'Zoom to global view',
zIndex: 1,
onClick: function (control) {
zoom_to_box(map, [0, 90, 0, -90]);
map.setZoom(2);
//zoom_to_box(map, [0, 90, 0, -90]);
zoom_to_box(map, {{ layer_bbox }});
map.setZoom(1);
}
}]
}).addTo(map);
Expand Down
16 changes: 16 additions & 0 deletions geonode/client/templates/leaflet/maps/map_embed.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,20 @@
<div id="map"></div>
</body>
</html>
{% else %}
{% load client_lib_tags %}

{% if TWITTER_CARD %}
{% include "base/_resourcebase_twittercard.html" %}
{% endif %}
{% if OPENGRAPH_ENABLED %}
{% include "base/_resourcebase_opengraph.html" %}
{% endif %}

{% get_map_detail %}
{{ block.super }}

<div id="embedded_map">
<div id="the_map"></div>
</div>
{% endif %}
23 changes: 20 additions & 3 deletions geonode/maps/qgis_server_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from django.core.urlresolvers import reverse
from django.shortcuts import render
from django.http import HttpResponse
from guardian.shortcuts import get_perms

from geonode.maps.views import _resolve_map, _PERMISSION_MSG_VIEW, \
snapshot_config, _resolve_layer
Expand Down Expand Up @@ -273,7 +274,7 @@ def get_form_kwargs(self):

class MapDetailView(DetailView):
model = Map
template_name = 'leaflet/maps/map_view.html'
template_name = 'leaflet/maps/map_detail.html'
context_object_name = 'map'

def get_context_data(self, **kwargs):
Expand All @@ -285,6 +286,7 @@ def get_context_data(self, **kwargs):

map_obj = _resolve_map(
request, mapid, 'base.view_resourcebase', _PERMISSION_MSG_VIEW)
links = map_obj.link_set.download()

if 'access_token' in request.session:
access_token = request.session['access_token']
Expand All @@ -298,14 +300,22 @@ def get_context_data(self, **kwargs):
access_token)
# list all required layers
layers = Layer.objects.all()

map_obj = _resolve_map(
request, mapid, 'base.view_resourcebase', _PERMISSION_MSG_VIEW)
map_layers = MapLayer.objects.filter(
map_id=mapid).order_by('stack_order')

context = {
'config': json.dumps(config),
'create': False,
'layers': layers,
'perms_list': get_perms(request.user, map_obj.get_self_resource()),
'map': map_obj,
'map_layers': map_layers,
'layer_bbox': map_obj.bbox_string,
'links': links,
'resource': map_obj,
'preview': getattr(
settings,
'GEONODE_CLIENT_LAYER_PREVIEW_LIBRARY',
Expand All @@ -319,7 +329,7 @@ def get_object(self):

class MapEmbedView(DetailView):
model = Map
template_name = 'leaflet/maps/map_detail.html'
template_name = 'leaflet/maps/map_embed.html'
context_object_name = 'map'

def get_context_data(self, **kwargs):
Expand All @@ -345,11 +355,17 @@ def get_context_data(self, **kwargs):
# list all required layers
map_layers = MapLayer.objects.filter(
map_id=mapid).order_by('stack_order')
layers = []
for layer in map_layers:
if layer.group != 'background':
layers.append(layer)

context = {
'config': json.dumps(config),
'create': False,
'resource': map_obj,
'layers': map_layers,
'map_layers': layers,
'for_download': False,
'preview': getattr(
settings,
'GEONODE_CLIENT_LAYER_PREVIEW_LIBRARY',
Expand Down Expand Up @@ -405,6 +421,7 @@ def get_context_data(self, **kwargs):
'layers': layers,
'map_layers': map_layers,
'map': map_obj,
'layer_bbox': map_obj.bbox_string,
'preview': getattr(
settings,
'GEONODE_CLIENT_LAYER_PREVIEW_LIBRARY',
Expand Down
6 changes: 4 additions & 2 deletions geonode/maps/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@
map_edit = views.map_edit
map_json = views.map_json
map_thumbnail = views.map_thumbnail
map_detail = views.map_detail

elif check_ogc_backend(qgis_server.BACKEND_PACKAGE):
from geonode.maps.qgis_server_views import MapCreateView, \
MapDetailView, MapEmbedView, MapEditView, MapUpdateView

new_map_view = MapCreateView.as_view()
existing_map_view = MapDetailView.as_view()
existing_map_view = MapEditView.as_view()
map_embed = MapEmbedView.as_view()

from geonode.maps.qgis_server_views import map_download_qlr, \
Expand All @@ -56,6 +57,7 @@
map_edit = MapEditView.as_view()
map_json = MapUpdateView.as_view()
map_thumbnail = set_thumbnail_map
map_detail = MapDetailView.as_view()

urlpatterns = [
# 'geonode.maps.views',
Expand All @@ -68,7 +70,7 @@
url(r'^new/data$', views.new_map_json, name='new_map_json'),
url(r'^checkurl/?$', views.ajax_url_lookup),
url(r'^snapshot/create/?$', views.snapshot_create),
url(r'^(?P<mapid>[^/]+)$', views.map_detail, name='map_detail'),
url(r'^(?P<mapid>[^/]+)$', map_detail, name='map_detail'),
url(r'^(?P<mapid>[^/]+)/view$', existing_map_view, name='map_view'),
url(r'^(?P<mapid>[^/]+)/edit$', map_edit, name='map_edit'),
url(r'^(?P<mapid>[^/]+)/data$', map_json, name='map_json'),
Expand Down
2 changes: 1 addition & 1 deletion geonode/qgis_server/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ def qgis_server_post_save_map(instance, sender, **kwargs):
'map_download_qlr',
kwargs={'mapid': instance.id}))
logger.debug('qlr_map_download_url: %s' % ogc_qlr_url)
link_name = 'Download QLR Layer file'
link_name = 'QGIS layer file (.qlr)'
link_mime = 'application/xml'
Link.objects.update_or_create(
resource=instance.resourcebase_ptr,
Expand Down
2 changes: 1 addition & 1 deletion geonode/qgis_server/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ def test_download_map_qlr(self):

# check that QLR is added to the links
links = map.link_set.download()
map_qlr_link = links.get(name='Download QLR Layer file')
map_qlr_link = links.get(name='QGIS layer file (.qlr)')
self.assertIn('qlr', map_qlr_link.url)

# QLR
Expand Down
7 changes: 4 additions & 3 deletions geonode/qgis_server/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ def download_map(request, mapid):
map_id=mapid).order_by('stack_order')
# Folder name in ZIP archive which contains the above files
# E.g [thearchive.zip]/somefiles/file2.txt
zip_subdir = mapid
zip_subdir = [ml.name for ml in map_layers if ml.local][0]
# Using map name for the zip file
zip_filename = "%s.zip" % zip_subdir

# Open StringIO to grab in-memory ZIP contents
Expand All @@ -161,8 +162,8 @@ def download_map(request, mapid):
zf = zipfile.ZipFile(s, "w")

for map_layer in map_layers:
if 'osm' not in map_layer.layer_title and 'OpenMap' not in map_layer.layer_title:
layer = get_object_or_404(Layer, name=map_layer.layer_title)
if map_layer.local:
layer = get_object_or_404(Layer, alternate=map_layer.name)
qgis_layer = get_object_or_404(QGISServerLayer, layer=layer)
# Files (local path) to put in the .zip
filenames = qgis_layer.files
Expand Down

0 comments on commit ce61f45

Please sign in to comment.