Skip to content

Commit

Permalink
embed widget link for qgis-server and geoserver backend
Browse files Browse the repository at this point in the history
embed widget link and add copy button

fix #152
  • Loading branch information
boney-bun committed Sep 27, 2017
1 parent c8f92c9 commit d5fdb98
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 46 deletions.
33 changes: 0 additions & 33 deletions geonode/maps/qgis_server_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
from django.utils.decorators import method_decorator
from django.core.urlresolvers import reverse
from django.http import HttpResponse
from django.shortcuts import render

from geonode.maps.views import _resolve_map, _PERMISSION_MSG_VIEW, \
snapshot_config
Expand Down Expand Up @@ -217,35 +216,3 @@ def perm_filter(layer):
% map_obj.title + '.qlr'

return response


def map_embed_widget(request, mapid,
template='leaflet_maps/map_embed_widget.html'):
"""Display code snippet for embedding widget.
:param request: The request from the frontend.
:type request: HttpRequest
:param mapid: The id of the map.
:type mapid: String
:return: formatted code.
"""

map_obj = _resolve_map(request,
mapid,
'base.view_resourcebase',
_PERMISSION_MSG_VIEW)
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 = {
'resource': map_obj,
'map_layers': layers
}
message = render(request, template, context)
return HttpResponse(message)
6 changes: 5 additions & 1 deletion geonode/maps/templates/leaflet_maps/map_embed_widget.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
$(document).ready(function () {
var wmsLayer = null;
var firstProjection = proj4('EPSG:3857');

{% if resource.srid %}
var secondProjection = proj4('{{ resource.srid }}');
{% else %}
var secondProjection = proj4('EPSG:4326');
{% endif %}

var point_wsg84 = proj4(firstProjection, secondProjection, [{{ resource.center_x }}, {{ resource.center_y }}]);
var map = L.map('map').setView([point_wsg84[1], point_wsg84[0]], 6);
Expand All @@ -16,7 +21,6 @@
});
map.addLayer(osm);

firstProjection = proj4('{{ resource.srid }}');
var corner0 = [{{ resource.bbox_x0 }}, {{ resource.bbox_y0 }}];
var corner1 = [{{ resource.bbox_x1 }}, {{ resource.bbox_y1 }}];

Expand Down
9 changes: 9 additions & 0 deletions geonode/maps/templates/maps/map_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ <h4 class="modal-title" id="myModalLabel">{% trans "Embed Widget" %}</h4>
<pre id="embed-widget-body" style="font-size: 0.5em"></pre>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-clipboard-target="#embed-widget-body">{% trans "Copy to Clipboard" %}</button>
<button type="button" class="btn btn-default" data-dismiss="modal">{% trans "Close" %}</button>
</div>
</div>
Expand All @@ -310,6 +311,7 @@ <h4 class="modal-title" id="myModalLabel">{% trans "Embed Widget" %}</h4>
{% overall_rating resource "map" as the_map_rating %}
{% endif %}
{% include 'rating.html' %}
<script type="text/javascript" src="{{ STATIC_URL}}geonode/js/utils/clipboard.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
post_url = '{% url 'map_embed_widget' resource.id %}';
Expand All @@ -323,6 +325,13 @@ <h4 class="modal-title" id="myModalLabel">{% trans "Embed Widget" %}</h4>
$('#embed-widget-body').text(formatted_data);
});
});
var clipboard = new Clipboard('.btn');
clipboard.on('success', function(e) {
alert("Code copied");
});
clipboard.on('error', function(e) {
alert("Oops.. something went wrong");
});
$(function() {

{% verbatim %}
Expand Down
8 changes: 2 additions & 6 deletions geonode/maps/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,13 @@
map_embed = 'map_embed'
# TODO qlr for geoserver
map_download_qlr = 'map_download_qlr'
# TODO no implementation for geoserver
map_embed_widget = 'map_embed_widget'

elif check_ogc_backend(qgis_server.BACKEND_PACKAGE):
new_map_view = MapCreateView.as_view()
existing_map_view = MapDetailView.as_view()
map_embed = MapEmbedView.as_view()
from geonode.maps.qgis_server_views import map_download_qlr, \
map_embed_widget
from geonode.maps.qgis_server_views import map_download_qlr
map_download_qlr = map_download_qlr
map_embed_widget = map_embed_widget

urlpatterns = patterns(
'geonode.maps.views',
Expand All @@ -75,7 +71,7 @@
url(r'^(?P<mapid>[^/]+)/metadata$', 'map_metadata', name='map_metadata'),
url(r'^(?P<mapid>[^/]+)/metadata_advanced$', 'map_metadata_advanced', name='map_metadata_advanced'),
url(r'^(?P<mapid>[^/]+)/embed$', map_embed, name='map_embed'),
url(r'^(?P<mapid>[^/]+)/embed_widget$', map_embed_widget, name='map_embed_widget'),
url(r'^(?P<mapid>[^/]+)/embed_widget$', 'map_embed_widget', name='map_embed_widget'),
url(r'^(?P<mapid>[^/]+)/history$', 'ajax_snapshot_history'),
url(r'^(?P<mapid>\d+)/thumbnail$', 'map_thumbnail', name='map_thumbnail'),
url(r'^(?P<mapid>[^/]+)/(?P<snapshot>[A-Za-z0-9_\-]+)/view$', 'map_view'),
Expand Down
36 changes: 30 additions & 6 deletions geonode/maps/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from django.core.serializers.json import DjangoJSONEncoder
from django.http import HttpResponse, HttpResponseRedirect, HttpResponseNotAllowed, HttpResponseServerError
from django.http.response import HttpResponseBadRequest
from django.shortcuts import render_to_response, get_object_or_404
from django.shortcuts import render_to_response, get_object_or_404, render
from django.conf import settings
from django.template import RequestContext
from django.utils.translation import ugettext as _
Expand Down Expand Up @@ -354,12 +354,36 @@ def map_embed(
}))


def map_embed_widget(request):
"""
This function serves as geoserver compatibility.
We might need to embed widget on geoserver in the future.
def map_embed_widget(request, mapid,
template='leaflet_maps/map_embed_widget.html'):
"""Display code snippet for embedding widget.
:param request: The request from the frontend.
:type request: HttpRequest
:param mapid: The id of the map.
:type mapid: String
:return: formatted code.
"""
return HttpResponseBadRequest('Sorry, Embed Widget has not supported yet')

map_obj = _resolve_map(request,
mapid,
'base.view_resourcebase',
_PERMISSION_MSG_VIEW)
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 = {
'resource': map_obj,
'map_layers': layers
}
message = render(request, template, context)
return HttpResponse(message)


# MAPS VIEWER #
Expand Down
7 changes: 7 additions & 0 deletions geonode/static/geonode/js/utils/clipboard.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d5fdb98

Please sign in to comment.