Skip to content

Commit

Permalink
Fixed restore of ms2 backgrounds
Browse files Browse the repository at this point in the history
  • Loading branch information
afabiani committed Sep 27, 2018
1 parent 3c028c5 commit 2b9949d
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 104 deletions.
69 changes: 46 additions & 23 deletions mapstore2_adapter/plugins/geonode.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,29 +66,33 @@ def convert(self, viewer, request):
ms2_map['maxResolution'] = viewer_obj['map']['maxResolution']

# Backgrouns
ms2_map['layers'] = MAP_BASELAYERS + [
# TODO: covnert Viewer Backgroun Layers
# Add here more backgrounds e.g.:
# {
# "type": "wms",
# "url": "https://demo.geo-solutions.it/geoserver/wms",
# "visibility": True,
# "opacity": 0.5,
# "title": "Weather data",
# "name": "nurc:Arc_Sample",
# "group": "Meteo",
# "format": "image/png",
# "bbox": {
# "bounds": {
# "minx": -25.6640625,
# "miny": 26.194876675795218,
# "maxx": 48.1640625,
# "maxy": 56.80087831233043
# },
# "crs": "EPSG:4326"
# }
# }, ...
]
backgrounds = self.getBackgrounds(viewer, MAP_BASELAYERS)
if backgrounds:
ms2_map['layers'] = backgrounds
else:
ms2_map['layers'] = MAP_BASELAYERS + [
# TODO: covnert Viewer Background Layers
# Add here more backgrounds e.g.:
# {
# "type": "wms",
# "url": "https://demo.geo-solutions.it/geoserver/wms",
# "visibility": True,
# "opacity": 0.5,
# "title": "Weather data",
# "name": "nurc:Arc_Sample",
# "group": "Meteo",
# "format": "image/png",
# "bbox": {
# "bounds": {
# "minx": -25.6640625,
# "miny": 26.194876675795218,
# "maxx": 48.1640625,
# "maxy": 56.80087831233043
# },
# "crs": "EPSG:4326"
# }
# }, ...
]

# Security Info
info = {}
Expand Down Expand Up @@ -191,6 +195,25 @@ def convert(self, viewer, request):
logger.error(tb)
return json.dumps(data, cls=DjangoJSONEncoder, sort_keys=True)

def getBackgrounds(self, viewer, defaults):
backgrounds = list(defaults)
try:
viewer_obj = json.loads(viewer)
layers = viewer_obj['map']['layers']
sources = viewer_obj['sources']
for layer in layers:
if 'group' in layer and layer['group'] == "background":
source = sources[layer['source']]
def_background = [bg for bg in defaults if bg['name'] == layer['name']]
background = def_background[0] if def_background else None
if background:
background['opacity'] = layer['opacity'] if 'opacity' in layer else 1.0
background['visibility'] = layer['visibility'] if 'visibility' in layer else False
except BaseException:
tb = traceback.format_exc()
logger.error(tb)
return backgrounds

def get_overlays(self, viewer):
overlays = []
selected = None
Expand Down
152 changes: 71 additions & 81 deletions tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,87 +360,77 @@ def get_geonode_catalogue_service():
"source": "osm",
"group": "background",
"visibility": True
},
{
"type": "google",
"title": "Google HYBRID",
"name": "HYBRID",
"source": "google",
"group": "background",
"visibility": False
},
{
"type": "mapquest",
"title": "MapQuest OSM",
"name": "osm",
"source": "mapquest",
"group": "background",
"visibility": False
},
{
"type": "bing",
"title": "Bing Aerial",
"apiKey": "AqTGBsziZHIJYYxgivLBf0hVdrAk9mWO5cQcb8Yux8sW5M8c8opEC2lZqKR1ZZXf",
"name": "Aerial",
"source": "bing",
"group": "background",
"visibility": False
},
{
"type": "tileprovider",
"title": "NASAGIBS Night 2012",
"provider": "NASAGIBS.ViirsEarthAtNight2012",
"name": "Night2012",
"source": "nasagibs",
"group": "background",
"visibility": False
},
{
"type": "wms",
"url": "http://www.realvista.it/reflector/open/service",
"visibility": False,
"title": "e-Geos Ortofoto RealVista 1.0",
"name": "rv1",
"group": "background",
"format": "image/jpeg"
},
{
"type": "wms",
"url": "https://demo.geo-solutions.it/geoserver/wms",
"visibility": False,
"title": "Natural Earth",
"name": "sde:NE2_HR_LC_SR_W_DR",
"group": "background",
"format": "image/png"
},
{
"type": "wms",
"url": "https://demo.geo-solutions.it/geoserver/wms",
"visibility": False,
"title": "Hypsometric",
"name": "sde:HYP_HR_SR_OB_DR",
"group": "background",
"format": "image/png"
},
{
"type": "wms",
"url": "https://demo.geo-solutions.it/geoserver/wms",
"visibility": False,
"title": "Gray Earth",
"name": "sde:GRAY_HR_SR_OB_DR",
"group": "background",
"format": "image/png"
},
{
"type": "tileprovider",
"title": "OpenTopoMap",
"provider": "OpenTopoMap",
"name": "OpenTopoMap",
"source": "OpenTopoMap",
"group": "background",
"visibility": False
}
]
}, {
"type": "google",
"title": "Google HYBRID",
"name": "HYBRID",
"source": "google",
"group": "background",
"visibility": False
}, {
"type": "mapquest",
"title": "MapQuest OSM",
"name": "osm",
"source": "mapquest",
"group": "background",
"visibility": False
}, {
"type": "bing",
"title": "Bing Aerial",
"apiKey": "AqTGBsziZHIJYYxgivLBf0hVdrAk9mWO5cQcb8Yux8sW5M8c8opEC2lZqKR1ZZXf",
"name": "Aerial",
"source": "bing",
"group": "background",
"visibility": False
}, {
"type": "tileprovider",
"title": "NASAGIBS Night 2012",
"provider": "NASAGIBS.ViirsEarthAtNight2012",
"name": "Night2012",
"source": "nasagibs",
"group": "background",
"visibility": False
}, {
"type": "wms",
"url": "http://www.realvista.it/reflector/open/service",
"visibility": False,
"title": "e-Geos Ortofoto RealVista 1.0",
"name": "rv1",
"group": "background",
"format": "image/jpeg"
}, {
"type": "wms",
"url": "https://demo.geo-solutions.it/geoserver/wms",
"visibility": False,
"title": "Natural Earth",
"name": "sde:NE2_HR_LC_SR_W_DR",
"group": "background",
"format": "image/png"
}, {
"type": "wms",
"url": "https://demo.geo-solutions.it/geoserver/wms",
"visibility": False,
"title": "Hypsometric",
"name": "sde:HYP_HR_SR_OB_DR",
"group": "background",
"format": "image/png"
}, {
"type": "wms",
"url": "https://demo.geo-solutions.it/geoserver/wms",
"visibility": False,
"title": "Gray Earth",
"name": "sde:GRAY_HR_SR_OB_DR",
"group": "background",
"format": "image/png"
}, {
"type": "tileprovider",
"title": "OpenTopoMap",
"provider": "OpenTopoMap",
"name": "OpenTopoMap",
"source": "OpenTopoMap",
"group": "background",
"visibility": False
}]

MAPSTORE_BASELAYERS = DEFAULT_MS2_BACKGROUNDS

Expand Down

0 comments on commit 2b9949d

Please sign in to comment.