Skip to content

Commit

Permalink
Ported the mobile client as per #404
Browse files Browse the repository at this point in the history
  • Loading branch information
capooti committed Jul 27, 2018
1 parent 89649f6 commit f9fae7d
Show file tree
Hide file tree
Showing 7 changed files with 334 additions and 3 deletions.
1 change: 1 addition & 0 deletions geonode/contrib/worldmap/wm_extra/__init__.py
@@ -0,0 +1 @@
from geonode.contrib.worldmap.wm_extra import signals # NOQA
@@ -0,0 +1,27 @@
<link rel="stylesheet" type="text/css" href="{{ GEONODE_CLIENT_LOCATION }}externals/openlayers/theme/default/style.css" />
<script src="{{ GEONODE_CLIENT_LOCATION }}script/OpenLayers.js"></script>
<link rel="stylesheet" type="text/css" href="{{ GEONODE_CLIENT_LOCATION }}externals/geoext/resources/css/geoext-all.css" />
<script src="{{ GEONODE_CLIENT_LOCATION }}script/GeoExt.js"></script>
<link rel="stylesheet" href="{{ GEONODE_CLIENT_LOCATION }}externals/gxp/theme/all.css" />
<script src="{{ GEONODE_CLIENT_LOCATION }}script/gxp.js"></script>
<link rel="stylesheet" type="text/css" href="{{ GEONODE_CLIENT_LOCATION }}theme/app/geoexplorer.css" />
<link rel="stylesheet" type="text/css" href="{{ GEONODE_CLIENT_LOCATION }}theme/app/geoexplorer_mobile.css" />
<!--[if IE]><link rel="stylesheet" type="text/css" href="{{ GEONODE_CLIENT_LOCATION }}theme/app/ie.css"/><![endif]-->
<script src="{{ GEONODE_CLIENT_LOCATION }}script/GeoExplorer.js"></script>
<script type="text/javascript">

//Reset SLD defaults for symbolizer, because for some reason
// it otherwise wreaks havoc with touch dragging

OpenLayers.Renderer.defaultSymbolizer = {
fillColor: "#000000",
strokeColor: "#000000",
strokeWidth: 2,
fillOpacity: 1,
strokeOpacity: 1,
pointRadius: 0,
labelAlign: 'cm'
};


</script>
@@ -0,0 +1,53 @@
{% load i18n %}
<html>
<head>

<title>{% block title %}WorldMap{% endblock %}</title>
<link rel="shortcut icon" href="{{ STATIC_URL }}theme/img/favicon.ico"/>
{% block head %}

<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}theme/site.css" />
<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}theme/site_mobile.css" />

{% comment %}
<script type="text/javascript" src="{% url django.views.i18n.javascript_catalog %}"></script>
<script type="text/javascript" src="{% url lang %}"></script>
{% endcomment %}

{% autoescape off %}
{{ GOOGLE_ANALYTICS_CODE }}
{% endautoescape %}

<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=2.0, user-scalable=no" />

{% endblock %}
</head>
<body style="min-height:100px;min-width:100px;">
{% block body %}
{% block header-wrapper %}
<div id="header">
<div id="wmpower">{% trans "Powered by" %} <a href="/">{% trans "WorldMap" %}</a></div>

<div class="wrapmap selfclear">

{% block logos %}

{% endblock logos %}


{% comment %}
<div id="login-area">
{% if user.is_authenticated %}
<a href="{% if user.get_profile %}{{ user.get_profile.get_absolute_url }}{% else %}{% url profiles_create_profile %}{% endif %}"><span style="font-weight:bold">{{user.username}}</span></a>
{% else %}
<!-- this should be updated to a url var --><a href="/accounts/login?next={{request.path}}">{% trans "Sign in" %}</a>
{% endif %}
</div>
{% endcomment %}

</div><!-- /.wrap -->
</div><!-- /#header -->
{% endblock header-wrapper %}
{% endblock body %}
</body>
</html>
@@ -0,0 +1,200 @@
{% extends "wm_extra/maps/mobile.html" %}
{% load i18n %}
{% block title %} {% trans "Map Viewer" %} - {{ block.super }} {% endblock %}

{% block head %}
{% include "wm_extra/maps/ext_header.html" %}
{% include "wm_extra/maps/app_header.html" %}
{% include "wm_extra/maps/geo_mobile_header.html" %}
{{ block.super }}
{% if "gme-" in GOOGLE_API_KEY %}
<script src="https://www.google.com/jsapi?client={{GOOGLE_API_KEY}}"></script>
{% else %}
<script src="https://www.google.com/jsapi?key={{GOOGLE_API_KEY}}"></script>
{% endif %}


<script type="text/javascript">
var originalConfigureLayerNode = GeoExt.WMSLegend.prototype.getLegendUrl;
GeoExt.WMSLegend.prototype.getLegendUrl = function(layerName,layerNames) {
var rec = this.layerRecord;
var layer = rec.getLayer();
if (OpenLayers.Layer.WMS && layer instanceof OpenLayers.Layer.WMS && layer.getVisibility() === false) {
return "";
} else {
return originalConfigureLayerNode.apply(this, arguments);
}
};

var touchNav = new OpenLayers.Control.TouchNavigation({
id: "touchNavControl",
dragPanOptions: {
enableKinetic: false
}
});

/*
* Deactivate navigation control when FeatureEditor's draw and select controls
are active - conflicts with touch actions.
*/
gxp.plugins.TouchFeatureEditor = Ext.extend(gxp.plugins.FeatureEditor, {
addActions: function() {
actions = gxp.plugins.FeatureEditor.prototype.addActions.apply(this, arguments);

this.drawControl.events.register("activate", this.drawControl, function(evt){
touchNav.deactivate();
});

this.drawControl.events.register("deactivate", this.drawControl, function(evt){
touchNav.activate();
});



this.selectControl.events.register("activate", this.selectControl, function() {
touchNav.deactivate();
});
this.selectControl.events.register("deactivate", this.selectControl, function() {
touchNav.activate();
});

return actions;
}
});

/*
* Deactivate navigation control when feature editing is occurring.
*/
var featureEditStartEditing = gxp.FeatureEditPopup.prototype.startEditing;
gxp.FeatureEditPopup.prototype.startEditing = function() {
touchNav.deactivate();
featureEditStartEditing.apply(this, arguments);
}

var featureEditStopEditing = gxp.FeatureEditPopup.prototype.stopEditing;
gxp.FeatureEditPopup.prototype.stopEditing = function() {
featureEditStopEditing.apply(this, arguments);
touchNav.activate();
}


var app;
Ext.onReady(function() {
{% autoescape off %}

/*
* Don't use default symbolizer; causes difficulty in draggoing vertices
*/
var featureManager = new gxp.plugins.FeatureManager({
ptype: "gxp_featuremanager",
id: "feature_manager",
paging: false,
autoSetLayer: true,
autoLoadFeatures: true,
listeners: {
'layerchange': function (mgr, layer, schema) {
app.checkLayerPermissions(layer);
}
},
actionTarget: "main.tbar",
toggleGroup: 'featureGroup',
symbolizer: {
"Point": {
fillColor: "#EF9E0F",
strokeColor: "#EF9E0F",
strokeWidth: 2,
fillOpacity: 1,
strokeOpacity: 1,
pointRadius: 5,
labelAlign: 'cm'
},
"Line": {
strokeWidth: 4,
strokeOpacity: 1,
strokeColor: "#ff9933"
},
"Polygon": {
strokeWidth: 2,
strokeOpacity: 1,
strokeColor: "#ff6633",
fillColor: "white",
fillOpacity: 0.3
}
}
});


var featureEditor = new gxp.plugins.TouchFeatureEditor({
id: "gn_layer_editor",
featureManager: "feature_manager",
autoLoadFeature: true,
actionTarget: "main.tbar",
toggleGroup: 'featureGroup'
});




var config = {
useCapabilities: false,
tools: [{
ptype: "gxp_geonodequerytool",
id: "worldmap_query_tool",
actionTarget: {target: "main.tbar"},
outputConfig: {autoHeight:true, autoWidth: true,panIn: false},
featurePanel: 'queryPanel',
attributePanel: 'gridWinPanel',
toggleGroup: 'featureGroup'
},{
ptype: "gxp_geolocator",
maxZoom: 15,
actionTarget: "main.tbar"
}{% if user.is_authenticated %},
featureManager,
featureEditor{% endif %}],
proxy: "/proxy/?url=",
localGeoServerBaseUrl: "{{ GEOSERVER_BASE_URL }}",

/* The URL to a REST map configuration service. This service
* provides listing and, with an authenticated user, saving of
* maps on the server for sharing and editing.
*/
rest: "/maps/",
createTools: function() {
}
};
Ext.apply(config, {{ config }});



config.map.controls = [
touchNav,
new OpenLayers.Control.Zoom(),
new OpenLayers.Control.Attribution()];

app = new GeoExplorer.ViewerMobile(config);
{% endautoescape %}
});
</script>
<div style="display:none" id="mobile_intro">
{% blocktrans %}
<h1>Mobile Map Tips</h1>
<ul>
<li>Click the <strong>Layers</strong> sidebar on the left to see a list of all the map's layers and legends</li>
<li>Use the <strong>Identify</strong> <img style="vertical-align:middle" src="{{ GEONODE_CLIENT_LOCATION }}theme/app/img/silk/information.png" /> tool to retrieve information on active layers at any point where you click on the map</li>
<li>Use the <strong>Geolocate</strong> <img style="vertical-align:middle" src="{{ GEONODE_CLIENT_LOCATION }}externals/gxp/theme/img/geolocate.png" /> tool to zoom to and display your location on the map</li>
</ul>
{% endblocktrans %}
{% if user.is_authenticated %}
{% blocktrans %}
<h1>Feature Creation/Editing</h1>
<ul>
<li>Click on a layer in the layer panel to select it for feature creation/editing. You must have edit permission for the layer.</li>
<li>The highlighted layer in the list is the target of edits when using the Edit feature <img style="vertical-align:middle" src="{{ GEONODE_CLIENT_LOCATION }}theme/app/img/silk/map_edit.png" /> tool or the New Feature <img style="vertical-align:middle" src="{{ GEONODE_CLIENT_LOCATION }}externals/gxp/theme/img/silk/pencil_add.png" /> tool.</li>
<li>Map panning will be disabled when the 'Edit feature' <img style="vertical-align:middle" src="{{ GEONODE_CLIENT_LOCATION }}theme/app/img/silk/map_edit.png" /> tool is enabled or when drawing a new feature <img style="vertical-align:middle" src="{{ GEONODE_CLIENT_LOCATION }}externals/gxp/theme/img/silk/pencil_add.png" /> . Deactivate the tool to re-enable panning.
</ul>
{% endblocktrans %}
{% endif %}
</div>

{% endblock %}
Expand Up @@ -276,7 +276,8 @@ <h3>{%trans "Create a new Layer" %}</h3>

<div style="position:relative;float:left;">
<h3>{%trans "Rectify Images" %}</h3>
<p style="font-size: 14px">{% trans "Use <a target='_blank' href='https://mapwarper.net/'>Map Warper</a> to upload and rectify scanned maps for use in WorldMap." %} <br/><br/> {% trans "Maps rectified using this tool can be brought into WorldMap by following the instructions under Section 4.5 in <a href='{% static "docs/WorldMap_Help.pdf" %}'>WorldMap Help</a>." %}</p>
<p style="font-size: 14px"><a target='_blank' href='https://mapwarper.net/'>{% trans "Use Map Warper to upload and rectify scanned maps for use in WorldMap." %}</a> <br/>
<br/><a href='{% static "docs/WorldMap_Help.pdf"'>{% trans "Maps rectified using this tool can be brought into WorldMap by following the instructions under Section 4.5 in >WorldMap Help." %}</a></p>
<br/><br/>
<div align="center"><a target="_blank" href="http://warp.worldmap.harvard.edu"><img src="{% static "worldmap/theme/img/warper-sample.jpg" %}" border="0" /></a></div>
</div>
Expand Down
3 changes: 2 additions & 1 deletion geonode/contrib/worldmap/wm_extra/urls.py
Expand Up @@ -8,7 +8,7 @@
ajax_layer_edit_style_check, upload_layer,
ajax_increment_layer_stats, add_layer_wm,
new_map_wm, new_map_json_wm, map_view_wm, map_json_wm,
map_detail_wm, add_endpoint, printmap, )
map_detail_wm, map_view_wm_mobile, add_endpoint, printmap, )

from tastypie.api import Api
from .api.resources import (LayerResource, TagResource, TopicCategoryResource,
Expand Down Expand Up @@ -40,6 +40,7 @@
url(r'^maps/(?P<mapid>[^/]+)$', map_detail_wm, name='map_detail_wm'),
url(r'^maps/(?P<mapid>[^/]+)/view$', map_view_wm, name='map_view_wm'),
url(r'^maps/(?P<mapid>[^/]+)/edit$', map_view_wm, name='map_view_wm'),
url(r'^maps/(?P<mapid>[^/]+)/mobile$', map_view_wm_mobile, name='map_view_wm_mobile'),
url(r'^maps/add_endpoint?$', add_endpoint, name='add_endpoint'),
url(r'^snapshot/create/?$', snapshot_create, name='snapshot_create'),
url(r'^maps/(?P<mapid>[^/]+)/(?P<snapshot>[A-Za-z0-9_\-]+)/$', map_view_wm, name='map_view_wm'),
Expand Down
50 changes: 49 additions & 1 deletion geonode/contrib/worldmap/wm_extra/views.py
Expand Up @@ -238,6 +238,54 @@ def map_view_wm(request, mapid, snapshot=None, layer_name=None, template='wm_ext
})


def map_view_wm_mobile(request, mapid=None, snapshot=None):
"""
The view that returns the map composer opened to
the mobile version for the map with the given map ID.
"""
map_obj = _resolve_map(
request,
mapid,
'base.view_resourcebase',
_PERMISSION_MSG_VIEW)

# TODO check if it is a new map
# if mapid is None:
# return newmap(request);

# TODO check if it is a mapid or suffix
# if mapid.isdigit():
# map_obj = Map.objects.get(pk=mapid)
# else:
# map_obj = Map.objects.get(urlsuffix=mapid)

if snapshot is None:
config = map_obj.viewer_json(request)
else:
config = snapshot_config(snapshot, map_obj, request)

config = gxp2wm(config, map_obj)

first_visit_mobile = True
if request.session.get('visit_mobile' + str(map_obj.id), False):
first_visit_mobile = False
else:
request.session['visit_mobile' + str(map_obj.id)] = True
config['first_visit_mobile'] = first_visit_mobile

template = 'wm_extra/maps/mobilemap.html'

return render(request, template, {
'config': json.dumps(config),
# 'GOOGLE_API_KEY' : settings.GOOGLE_API_KEY,
# 'GEONETWORK_BASE_URL' : settings.GEONETWORK_BASE_URL,
# 'GEOSERVER_BASE_URL' : settings.GEOSERVER_BASE_URL,
# 'DB_DATASTORE' : settings.DB_DATASTORE,
'maptitle': map_obj.title,
# 'urlsuffix': get_suffix_if_custom(map_obj),
})


def map_view_js(request, mapid):
map_obj = _resolve_map(
request,
Expand Down Expand Up @@ -461,6 +509,7 @@ def add_layers_to_map_config(request, map_obj, layer_names, add_base_layers=True
config["bbox"] = bbox if config["srs"] != 'EPSG:900913' \
else llbbox_to_mercator([float(coord) for coord in bbox])

access_token = request.session['access_token'] if request and 'access_token' in request.session else None
if layer.storeType == "remoteStore":
service = layer.service
# Probably not a good idea to send the access token to every remote service.
Expand All @@ -470,7 +519,6 @@ def add_layers_to_map_config(request, map_obj, layer_names, add_base_layers=True
ogc_server_settings.PUBLIC_LOCATION).netloc
service_url = urlparse.urlsplit(service.base_url).netloc

access_token = request.session['access_token'] if request and 'access_token' in request.session else None
if access_token and ogc_server_url == service_url and 'access_token' not in service.base_url:
url = service.base_url + '?access_token=' + access_token
else:
Expand Down

0 comments on commit f9fae7d

Please sign in to comment.