Skip to content

Commit

Permalink
- Backport stable fixes from master branch
Browse files Browse the repository at this point in the history
  • Loading branch information
Alessio Fabiani committed Jun 21, 2018
1 parent 76d6d6e commit edbbd73
Show file tree
Hide file tree
Showing 22 changed files with 356 additions and 279 deletions.
2 changes: 1 addition & 1 deletion geonode/base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1480,7 +1480,7 @@ def do_logout(sender, user, request, **kwargs):
pass

# Do GeoServer Logout
if 'access_token' in request.session:
if request and 'access_token' in request.session:
access_token = request.session['access_token']
else:
access_token = None
Expand Down
2 changes: 1 addition & 1 deletion geonode/catalogue/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def csw_global_dispatch(request):
mdict = dict(settings.PYCSW['CONFIGURATION'], **CONFIGURATION)

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

absolute_uri = ('%s' % request.build_absolute_uri())
Expand Down
24 changes: 21 additions & 3 deletions geonode/client/hooksets.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#########################################################################
try:
import json
except ImportError:
from django.utils import simplejson as json


class GeoExtHookSet(object):
Expand Down Expand Up @@ -60,13 +64,27 @@ def map_update_template(self, context=None):
return 'geoext/maps/map_geoexplorer.js'

def map_embed_template(self, context=None):
return 'geoext/maps/map_geoexplorer.js'
return 'geoext/maps/map_geoexplorer_viewer.js'

def map_download_template(self, context=None):
return 'geoext/maps/map_geoexplorer.js'

# Map Persisting
def viewer_json(self, conf, context=None):
if not context:
context = {}

if isinstance(conf, basestring):
conf = json.loads(conf)
return conf

def update_from_viewer(self, conf, context=None):
conf = self.viewer_json(conf, context=context)
context['config'] = conf
return 'geoext/maps/map_geoexplorer.js'


class LeafletHookSet(object):
class LeafletHookSet(GeoExtHookSet):

# Layers
def layer_detail_template(self, context=None):
Expand Down Expand Up @@ -113,7 +131,7 @@ def map_download_template(self, context=None):
return 'leaflet/maps/map_embed.html'


class ReactHookSet(object):
class ReactHookSet(GeoExtHookSet):

# Layers
def layer_detail_template(self, context=None):
Expand Down
5 changes: 3 additions & 2 deletions geonode/client/templates/geoext/maps/map_geoexplorer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{% include 'geoext/ext_header.html' %}
{% include 'geoext/geo_header.html' %}
{% include "geoext/ext_header.html" %}
{% include "geoext/app_header.html" %}
{% include "geoext/geo_header.html" %}
<link href="{{ STATIC_URL}}geonode/css/geoexplorer/map_geoexplorer.css" rel="stylesheet"/>
<script type="text/javascript" src="{{ STATIC_URL}}geonode/js/extjs/GeoNode-mixin.js"></script>
<script type="text/javascript" src="{{ STATIC_URL}}geonode/js/extjs/Geonode-CatalogueApiSearch.js"></script>
Expand Down
194 changes: 194 additions & 0 deletions geonode/client/templates/geoext/maps/map_geoexplorer_viewer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
{% include "geoext/ext_header.html" %}
{% include "geoext/app_header.html" %}
{% include "geoext/geo_header.html" %}
<link href="{{ STATIC_URL}}geonode/css/geoexplorer/map_geoexplorer.css" rel="stylesheet"/>
<script type="text/javascript" src="{{ STATIC_URL}}geonode/js/extjs/GeoNode-mixin.js"></script>
<script type="text/javascript" src="{{ STATIC_URL}}geonode/js/extjs/Geonode-CatalogueApiSearch.js"></script>
<script type="text/javascript" src="{{ STATIC_URL}}geonode/js/extjs/GeoNode-GeoExplorer.js"></script>
<script type="text/javascript">
var app;
Ext.onReady(function() {
{% autoescape off %}
GeoExt.Lang.set("{{ LANGUAGE_CODE }}");
var config = Ext.apply({
authStatus: {% if user.is_authenticated %} 200{% else %} 401{% endif %},
{% if PROXY_URL %}
proxy: '{{ PROXY_URL }}',
{% endif %}

{% if 'access_token' in request.session %}
access_token: "{{request.session.access_token}}",
{% else %}
access_token: null,
{% endif %}

{% if MAPFISH_PRINT_ENABLED %}
printService: "{{ GEOSERVER_BASE_URL }}pdf/",
{% else %}
printService: null,
printCapabilities: null,
{% endif %}

useCapabilities: false,
useToolbar: true,

/* 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: "{% url "maps_browse" %}",
ajaxLoginUrl: "{% url "account_ajax_login" %}",
homeUrl: "{% url "home" %}",
localGeoServerBaseUrl: "{{ GEOSERVER_BASE_URL }}",
localCSWBaseUrl: "{{ CATALOGUE_BASE_URL }}",
csrfToken: "{{ csrf_token }}",
tools: [{ptype: "gxp_getfeedfeatureinfo"}],
listeners: {
"ready": function() {
app.mapPanel.map.getResolutions = function() {
return [156543.03390625, 78271.516953125, 39135.7584765625,
19567.87923828125, 9783.939619140625, 4891.9698095703125,
2445.9849047851562, 1222.9924523925781, 611.4962261962891,
305.74811309814453, 152.87405654907226, 76.43702827453613,
38.218514137268066, 19.109257068634033, 9.554628534317017,
4.777314267158508, 2.388657133579254, 1.194328566789627,
0.5971642833948135, 0.25, 0.1, 0.05];
}
app.mapPanel.map.getServerResolutions = function() {
return [156543.03390625, 78271.516953125, 39135.7584765625,
19567.87923828125, 9783.939619140625,
4891.9698095703125, 2445.9849047851562,
1222.9924523925781, 611.4962261962891,
305.74811309814453, 152.87405654907226,
76.43702827453613, 38.218514137268066,
19.109257068634033, 9.554628534317017,
4.777314267158508, 2.388657133579254,
1.194328566789627, 0.5971642833948135];
}
app.mapPanel.map.getMaxResolution = function() {
return 156543.0339 * 2;
}
app.mapPanel.map.getNumZoomLevels = function() {
return 28;
}
app.mapPanel.map.getMinZoom = function() {
return 0;
}
app.mapPanel.map.getMaxZoom = function() {
return 28;
}
app.mapPanel.map.getResolutionForZoom = function(zoom) {
zoom = Math.max(0, Math.min(zoom, this.getResolutions().length - 1));
var resolution;
var fractionalZoom = true;
if(fractionalZoom) {
var low = Math.floor(zoom);
var high = Math.ceil(zoom);
resolution = this.getResolutions()[low] -
((zoom-low) * (this.getResolutions()[low]-this.getResolutions()[high]));
} else {
resolution = this.getResolutions()[Math.round(zoom)];
}
return resolution;
}
app.mapPanel.map.adjustZoom = function(zoom) {
var maxResolution = 156543.0339 * 4;
if (this.baseLayer && this.baseLayer.wrapDateLine) {
var resolution, resolutions = this.getResolutions(),
// maxResolution = this.getMaxExtent().getWidth() / this.size.w;
maxResolution = this.getMaxResolution();
if (this.getResolutionForZoom(zoom) > maxResolution) {
var fractionalZoom = true;
if (fractionalZoom) {
zoom = this.getZoomForResolution(maxResolution);
} else {
for (var i=zoom|0, ii=resolutions.length; i<ii; ++i) {
if (resolutions[i] <= maxResolution) {
zoom = i;
break;
}
}
}
}
}
return zoom;
}

try {
l = app.selectedLayer.getLayer();
l.addOptions({wrapDateLine:true, displayOutsideMaxExtent: true});
l.addOptions({maxExtent:app.mapPanel.map.getMaxExtent()});
} catch(err) {
;
}

{% if 'access_token' in request.session %}
try {
if(l.url != undefined && (typeof l.url) == "string") {
l.url += ( !l.url.match(/\b\?/gi) || l.url.match(/\b\?/gi).length == 0 ? '?' : '&');
if((!l.url.match(/\baccess_token/gi))) {
l.url += "access_token={{request.session.access_token}}";
} else {
l.url =
l.url.replace(/(access_token)(.+?)(?=\&)/, "$1={{request.session.access_token}}");
}
}
} catch(err) {
console.log(err);
}
{% endif %}

for (var ll in app.mapPanel.map.layers) {
l = app.mapPanel.map.layers[ll];
if (l.url != undefined && (typeof l.url) == "string" && l.url.indexOf('{{GEOSERVER_BASE_URL}}') !== -1) {
l.addOptions({wrapDateLine:true, displayOutsideMaxExtent: true});
l.addOptions({maxExtent:app.mapPanel.map.getMaxExtent()});
{% if 'access_token' in request.session %}
try {
l.url += ( !l.url.match(/\b\?/gi) || l.url.match(/\b\?/gi).length == 0 ? '?' : '&');
if((!l.url.match(/\baccess_token/gi))) {
l.url += "access_token={{request.session.access_token}}";
} else {
l.url =
l.url.replace(/(access_token)(.+?)(?=\&)/, "$1={{request.session.access_token}}");
}
} catch(err) {
console.log(err);
}
{% endif %}
}
}

var map = app.mapPanel.map;
var layer = app.map.layers.slice(-1)[0];
var bbox = layer.bbox;
var crs = layer.srs;
if (bbox != undefined)
{
var extent = new OpenLayers.Bounds();

if (layer.capability.bbox &&
!Array.isArray(layer.capability.bbox) &&
map.projection in layer.capability.bbox) {
bbox = layer.capability.bbox[map.projection].bbox;
extent = OpenLayers.Bounds.fromArray(bbox);
} else {
if (crs != map.projection) {
extent = OpenLayers.Bounds.fromArray(bbox);
extent = extent.clone().transform(crs, map.projection);
} else {
extent = OpenLayers.Bounds.fromArray(bbox);
}
}
}
},
'save': function(obj_id) {
createMapThumbnail(obj_id);
}
}
}, {{ config }});

app = new GeoNode.Viewer(config);
{% endautoescape %}
});
</script>

0 comments on commit edbbd73

Please sign in to comment.