Skip to content

Commit

Permalink
- Fix remote services layout
Browse files Browse the repository at this point in the history
  • Loading branch information
afabiani committed Apr 26, 2018
1 parent ae62bfd commit c47b75a
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 18 deletions.
67 changes: 55 additions & 12 deletions geonode/layers/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ def sld_definition(style):
config["bbox"] = decimal_encode(
bbox_to_projection([float(coord) for coord in layer_bbox] + [layer.srid, ],
target_srid=int(srs.split(":")[1]))[:4])

config["capability"] = {
"abstract": layer.abstract,
"name": layer.alternate,
Expand Down Expand Up @@ -411,14 +412,54 @@ def sld_definition(style):
[float(coord) for coord in layer_bbox] + [layer.srid, ], target_srid=4326)[:4])
}

all_times = None
if check_ogc_backend(geoserver.BACKEND_PACKAGE):
from geonode.geoserver.views import get_capabilities
workspace, layername = layer.alternate.split(
":") if ":" in layer.alternate else (None, layer.alternate)
# WARNING Please make sure to have enabled DJANGO CACHE as per
# https://docs.djangoproject.com/en/2.0/topics/cache/#filesystem-caching
wms_capabilities_resp = get_capabilities(
request, layer.id, tolerant=True)
if wms_capabilities_resp.status_code >= 200 and wms_capabilities_resp.status_code < 400:
wms_capabilities = wms_capabilities_resp.getvalue()
if wms_capabilities:
import xml.etree.ElementTree as ET
e = ET.fromstring(wms_capabilities)
for atype in e.findall(
"./[Name='%s']/Extent[@name='time']" % (layername)):
dim_name = atype.get('name')
if dim_name:
dim_name = str(dim_name).lower()
if dim_name == 'time':
dim_values = atype.text
if dim_values:
all_times = dim_values.split(",")
break
if all_times:
config["capability"]["dimensions"] = {
"time": {
"name": "time",
"units": "ISO8601",
"unitsymbol": None,
"nearestVal": False,
"multipleVal": False,
"current": False,
"default": "current",
"values": all_times
}
}

if layer.storeType == "remoteStore":
service = layer.remote_service
source_params = {
"ptype": service.ptype,
"remote": True,
"url": service.service_url,
"name": service.name,
"title": "[R] %s" % service.title}
source_params = {}
if service.type in ('REST_MAP', 'REST_IMG'):
source_params = {
"ptype": service.ptype,
"remote": True,
"url": service.service_url,
"name": service.name,
"title": "[R] %s" % service.title}
maplayer = GXPLayer(
name=layer.alternate,
ows_url=layer.ows_url,
Expand Down Expand Up @@ -793,12 +834,14 @@ def layer_metadata(

if layer.storeType == "remoteStore":
service = layer.remote_service
source_params = {
"ptype": service.ptype,
"remote": True,
"url": service.service_url,
"name": service.name,
"title": "[R] %s" % service.title}
source_params = {}
if service.type in ('REST_MAP', 'REST_IMG'):
source_params = {
"ptype": service.ptype,
"remote": True,
"url": service.service_url,
"name": service.name,
"title": "[R] %s" % service.title}
maplayer = GXPLayer(
name=layer.alternate,
ows_url=layer.ows_url,
Expand Down
52 changes: 46 additions & 6 deletions geonode/maps/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -947,14 +947,54 @@ def sld_definition(style):
[float(coord) for coord in layer_bbox] + [layer.srid, ], target_srid=4326)[:4])
}

all_times = None
if check_ogc_backend(geoserver.BACKEND_PACKAGE):
from geonode.geoserver.views import get_capabilities
workspace, layername = layer.alternate.split(
":") if ":" in layer.alternate else (None, layer.alternate)
# WARNING Please make sure to have enabled DJANGO CACHE as per
# https://docs.djangoproject.com/en/2.0/topics/cache/#filesystem-caching
wms_capabilities_resp = get_capabilities(
request, layer.id, tolerant=True)
if wms_capabilities_resp.status_code >= 200 and wms_capabilities_resp.status_code < 400:
wms_capabilities = wms_capabilities_resp.getvalue()
if wms_capabilities:
import xml.etree.ElementTree as ET
e = ET.fromstring(wms_capabilities)
for atype in e.findall(
"./[Name='%s']/Extent[@name='time']" % (layername)):
dim_name = atype.get('name')
if dim_name:
dim_name = str(dim_name).lower()
if dim_name == 'time':
dim_values = atype.text
if dim_values:
all_times = dim_values.split(",")
break
if all_times:
config["capability"]["dimensions"] = {
"time": {
"name": "time",
"units": "ISO8601",
"unitsymbol": None,
"nearestVal": False,
"multipleVal": False,
"current": False,
"default": "current",
"values": all_times
}
}

if layer.storeType == "remoteStore":
service = layer.remote_service
source_params = {
"ptype": service.ptype,
"remote": True,
"url": service.service_url,
"name": service.name,
"title": "[R] %s" % service.title}
source_params = {}
if service.type in ('REST_MAP', 'REST_IMG'):
source_params = {
"ptype": service.ptype,
"remote": True,
"url": service.service_url,
"name": service.name,
"title": "[R] %s" % service.title}
maplayer = MapLayer(map=map_obj,
name=layer.alternate,
ows_url=layer.ows_url,
Expand Down

0 comments on commit c47b75a

Please sign in to comment.