Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] fix map interaction #538

Open
wants to merge 1 commit into
base: 2.8.x-qgis_server
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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