Skip to content

Commit

Permalink
embed iframe when viewing a map
Browse files Browse the repository at this point in the history
  • Loading branch information
boney-bun committed Aug 21, 2017
1 parent 6ad1905 commit c56fcff
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 2 deletions.
46 changes: 46 additions & 0 deletions geonode/maps/qgis_server_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,49 @@ def get_context_data(self, **kwargs):

def get_object(self):
return Map.objects.get(id=self.kwargs.get("mapid"))


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

def get_context_data(self, **kwargs):
"""Prepare context data."""

mapid = self.kwargs.get('mapid')
snapshot = self.kwargs.get('snapshot')
request = self.request

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

if 'access_token' in request.session:
access_token = request.session['access_token']
else:
access_token = None

if snapshot is None:
config = map_obj.viewer_json(request.user, access_token)
else:
config = snapshot_config(snapshot, map_obj, request.user,
access_token)
# list all required layers
layers = Layer.objects.all()
map_layers = MapLayer.objects.filter(
map_id=mapid).order_by('stack_order')
context = {
'config': json.dumps(config),
'create': False,
'layers': layers,
'resource': map_obj,
'map_layers': map_layers,
'preview': getattr(
settings,
'LAYER_PREVIEW_LIBRARY',
'')
}
return context

def get_object(self):
return Map.objects.get(id=self.kwargs.get("mapid"))
23 changes: 23 additions & 0 deletions geonode/maps/templates/leaflet_maps/map_detail.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{% if TWITTER_CARD %}
{% include "base/_resourcebase_twittercard.html" %}
{% endif %}
{% if OPENGRAPH_ENABLED %}
{% include "base/_resourcebase_opengraph.html" %}
{% endif %}
{% if preview == 'OL3' %}
{% include "maps/map_ol3.html" %}
{% elif preview == 'leaflet' %}
{% include "maps/map_leaflet.html" %}
{% elif preview == 'react' %}
{% include 'geonode-client/map_detail.html' %}
{% else %}
{% include "maps/map_include.html" %}
{% endif %}
{{ block.super }}



<div id="embedded_map">
<div id="the_map"></div>
</div>

43 changes: 43 additions & 0 deletions geonode/maps/templates/maps/map_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,25 @@ <h4>{% trans "Copy this map" %}</h4>
<p>{% trans "Duplicate this map and modify it for your own purposes" %}</p>
<a href="{% url "new_map" %}?copy={{ resource.id }}" class="btn btn-default btn-md btn-block">{% trans "Create a New Map" %}</a>
</li>
{% if 'geonode.qgis_server' in INSTALLED_APPS %}
<li class="list-group-item">
<h4>{% trans "Embed this map" %}</h4>
<p>{% trans "Embed this map to your own sites" %}</p>
<div class="btn-group btn-block">
<button type="button" class="btn btn-default btn-block dropdown-toggle"
data-toggle="dropdown"
aria-haspopup="true" aria-expanded="false">
Embed Map <span class="caret"></span></button>
<ul class="dropdown-menu btn-block">
<li>
<a href="javascript:$('#embed-iframe').modal()">Embed Iframe Link</a></li>
<li>
<a href="#">Embed Widget Link</a></li>
</ul>
</div>
</li>
{% endif %}


{% if resource.is_public and "change_resourcebase" in perms_list or resource.layer_group %}
<li class="list-group-item">
Expand All @@ -233,6 +252,30 @@ <h4>{% trans "Map WMS" %}</h4>

</div>

<div class="modal fade" id="embed-iframe" tabindex="-1" role="dialog" aria-labelledby="Embed Iframe"
aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 class="modal-title" id="myModalLabel">{% trans "Embed Iframe" %}</h4>
</div>
<div class="modal-body">
<p>To embed this map, add the following code snippet and customize its properties (scrolling, width,
height) based on your needs to your site:</p>
<p style="font-weight: bold">
&lt;iframe scrolling="yes" src="{{ SITEURL }}{% url "map_embed" resource.id %}"
width="480px" height="360px"&gt;&lt;/iframe&gt;
</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">{% trans "Close" %}</button>
</div>
</div>
</div>
</div>


{% endblock %}

{% block extra_script %}
Expand Down
6 changes: 4 additions & 2 deletions geonode/maps/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from django.conf import settings
from django.views.generic import TemplateView

from geonode.maps.qgis_server_views import MapCreateView, MapDetailView
from geonode.maps.qgis_server_views import MapCreateView, MapDetailView, MapEmbedView

js_info_dict = {
'packages': ('geonode.maps',),
Expand All @@ -34,10 +34,12 @@
if 'geonode.geoserver' in settings.INSTALLED_APPS:
new_map_view = 'new_map'
existing_map_view = 'map_view'
map_embed = 'map_embed'

elif 'geonode.qgis_server' in settings.INSTALLED_APPS:
new_map_view = MapCreateView.as_view()
existing_map_view = MapDetailView.as_view()
map_embed = MapEmbedView.as_view()

urlpatterns = patterns(
'geonode.maps.views',
Expand All @@ -59,7 +61,7 @@
url(r'^(?P<mapid>[^/]+)/remove$', 'map_remove', name='map_remove'),
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$', map_embed, name='map_embed'),
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

0 comments on commit c56fcff

Please sign in to comment.