Skip to content

Commit

Permalink
Fix and refactor map update interaction
Browse files Browse the repository at this point in the history
- Refactor Maps API endpoint to only list map layers on detail request
- Heavy refactor on Leaflet Map Creation Page
- Heavy refactor on Leaflet Map Update Page to extends Map Creation Page
- Refactor QGIS Server Views to support Leaflet Map page
- Refactor Leaflet Map detail page
- Refactor GeoNode map urls for QGIS Server Backend
- Allow Map thumbnail to include chosen basemap
- Fix QGIS Server Map post save signal to save active basemap and local layers
- Add urls for layer json definition for QGIS Server Backend
- Refactor default basemaps for Map Leaflet page to use https
- Refactor Leaflet map css
  • Loading branch information
lucernae committed Nov 28, 2018
1 parent 4c4f4e2 commit 35af1b8
Show file tree
Hide file tree
Showing 15 changed files with 1,224 additions and 1,016 deletions.
78 changes: 57 additions & 21 deletions geonode/api/resourcebase_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,11 @@ class Meta(CommonMetaApi):
class MapResource(CommonModelApi):

"""Maps API"""
layers = fields.ListField(
attribute='layers',
null=True,
use_in='detail',
default=[])

def format_objects(self, objects):
"""
Expand All @@ -886,6 +891,8 @@ def format_objects(self, objects):
"""
formatted_objects = []
for obj in objects:
bundle = self.build_bundle(obj=obj)

# convert the object to a dict using the standard values.
formatted_obj = model_to_dict(obj, fields=self.VALUES)
username = obj.owner.get_username()
Expand All @@ -909,34 +916,63 @@ def format_objects(self, objects):
formatted_obj['online'] = True

# get map layers
map_layers = obj.layers
formatted_layers = []
map_layer_fields = [
'id'
'stack_order',
'format',
'name',
'opacity',
'group',
'visibility',
'transparent',
'ows_url',
'layer_params',
'source_params',
'local'
]
for layer in map_layers:
formatted_map_layer = model_to_dict(
layer, fields=map_layer_fields)
formatted_layers.append(formatted_map_layer)
formatted_obj['layers'] = formatted_layers
if self.layers.use_in in ['all', 'list']:
formatted_obj['layers'] = self.dehydrate_layers(bundle)

formatted_objects.append(formatted_obj)
return formatted_objects

def dehydrate_layers(self, bundle):
"""Dehydrate layer_set field."""
dehydrated = []
obj = bundle.obj
layer_set_fields = [
'id',
'stack_order',
'format',
'name',
'opacity',
'group',
'visibility',
'transparent',
'ows_url',
'layer_params',
'layer_title',
'source_params',
'local'
]
for l in obj.layer_set.all().order_by('stack_order'):
formatted_layer_set = model_to_dict(l, fields=layer_set_fields)
formatted_layer_set['title'] = l.layer_title

try:
formatted_layer_set['layer_params'] = json.loads(
l.layer_params)
except ValueError:
formatted_layer_set['layer_params'] = l.layer_params

try:
formatted_layer_set['source_params'] = json.loads(
l.source_params)
except ValueError:
formatted_layer_set['source_params'] = l.source_params

dehydrated.append(formatted_layer_set)
return dehydrated

class Meta(CommonMetaApi):
queryset = Map.objects.distinct().order_by('-date')
resource_name = 'maps'
authentication = MultiAuthentication(SessionAuthentication(), GeonodeApiKeyAuthentication())
detail_uri_name = 'id'
include_resource_uri = True
allowed_methods = ['get']
excludes = ['csw_anytext', 'metadata_xml']
filtering = CommonMetaApi.filtering
# Allow filtering using ID
filtering.update({
'id': ALL,
})


class DocumentResource(CommonModelApi):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
.leaflet-container { /* all maps */
height: 400px;
}
.leaflet-control-zoom, .leaflet-control-zoomslider { /* all controls */

.leaflet-left .leaflet-control { /* all controls */
position: relative;
left: 0px !important;
}
Expand Down
5 changes: 5 additions & 0 deletions geonode/client/templates/leaflet/maps/map_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,11 @@
position: relative;
left: 0px !important;
}

.leaflet-left .leaflet-control { /* all controls */
position: relative;
left: 0px !important;
}
</style>

<h2 class="page-title">{{ resource.title }}</h2>
Expand Down
Loading

0 comments on commit 35af1b8

Please sign in to comment.