Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
:type mapid: String
:return: formatted code.
"""
map_obj = _resolve_map(request,
mapid,
'base.view_resourcebase',
_PERMISSION_MSG_VIEW)
map_bbox = map_obj.bbox_string.split(',')
# Sanity Checks
for coord in map_bbox:
if not coord:
return
map_layers = MapLayer.objects.filter(
map_id=mapid).order_by('stack_order')
layers = []
for layer in map_layers:
if layer.group != 'background':
layers.append(layer)
if map_obj.srid != 'EPSG:3857':
map_bbox = [float(coord) for coord in map_bbox]
else:
map_bbox = llbbox_to_mercator([float(coord) for coord in map_bbox])
if map_bbox and len(map_bbox) >= 4:
minx, miny, maxx, maxy = [float(coord) for coord in map_bbox]
x = (minx + maxx) / 2
y = (miny + maxy) / 2
def handle(self, *args, **options):
from geonode.maps.models import MapLayer
if len(args) == 3:
map_id, name, title = args
else:
raise CommandError("You must specify three arguments: map_id name title")
maplayer = MapLayer.objects.filter(map_id=map_id, name=name)[0]
layer_params = json.loads(maplayer.layer_params)
layer_params['title'] = title
layer_params['capability']['title'] = title
maplayer.layer_params = json.dumps(layer_params)
maplayer.save()
def local_layers(self):
layer_names = MapLayer.objects.filter(map__id=self.id).values('name')
return Layer.objects.filter(alternate__in=layer_names) | \
Layer.objects.filter(name__in=layer_names)
def apply_filters(self, request, applicable_filters):
layer_type = applicable_filters.pop('type', None)
filtered = super(MapLayerResource, self).apply_filters(
request, applicable_filters)
if layer_type:
filtered = [lyr.id for lyr in filtered
if self.get_layer(lyr.name) and # noqa
Attribute.objects.filter(
attribute_type__contains="gml:",
attribute_type__icontains=layer_type.lower(),
layer=self.get_layer(lyr.name)).count() > 0]
filtered = MapLayer.objects.filter(
id__in=filtered)
return filtered
"""
Publishes local map layers as WMS layer group on local OWS.
"""
if check_ogc_backend(geoserver.BACKEND_PACKAGE):
from geonode.geoserver.helpers import gs_catalog
from geoserver.layergroup import UnsavedLayerGroup as GsUnsavedLayerGroup
else:
raise Exception(
'Cannot publish layer group if geonode.geoserver is not in INSTALLED_APPS')
# temporary permission workaround:
# only allow public maps to be published
if not self.is_public:
return 'Only public maps can be saved as layer group.'
map_layers = MapLayer.objects.filter(map=self.id)
# Local Group Layer layers and corresponding styles
layers = []
lg_styles = []
for ml in map_layers:
if ml.local:
layer = Layer.objects.get(alternate=ml.name)
style = ml.styles or getattr(layer.default_style, 'name', '')
layers.append(layer)
lg_styles.append(style)
lg_layers = [l.name for l in layers]
# Group layer bounds and name
lg_bounds = [str(coord) for coord in self.bbox]
lg_name = '%s_%d' % (slugify(self.title), self.id)
def handle(self, *args, **options):
from geonode.maps.models import MapLayer
from django.conf import settings
site_url = settings.SITEURL.rstrip('/') if settings.SITEURL.startswith('http') else settings.SITEURL
map_layers = MapLayer.objects.filter(local=True)
for maplayer in map_layers:
maplayer.ows_url = site_url + "/geoserver/wms"
maplayer.save()
"""Download leaflet map as static HTML.
:param request: The request from the frontend.
:type request: HttpRequest
:param mapid: The id of the map.
:type mapid: String
:return: HTML file.
"""
map_obj = _resolve_map(request,
mapid,
'base.view_resourcebase',
_PERMISSION_MSG_VIEW)
map_layers = MapLayer.objects.filter(
map_id=mapid).order_by('stack_order')
layers = []
for layer in map_layers:
if layer.group != 'background':
layers.append(layer)
context = {
'resource': map_obj,
'map_layers': layers,
'for_download': True
}
the_page = render(request, template, context=context)
response = HttpResponse(
the_page.content, content_type="html",
poc_form.hidden = True
if metadata_author is None:
author_form = ProfileForm(request.POST, prefix="author")
else:
if metadata_author is None:
author_form = ProfileForm(
instance=metadata_author,
prefix="author")
else:
map_form.fields['metadata_author'].initial = metadata_author.id
author_form = ProfileForm(prefix="author")
author_form.hidden = True
config = map_obj.viewer_json(request)
layers = MapLayer.objects.filter(map=map_obj.id)
metadata_author_groups = []
if request.user.is_superuser or request.user.is_staff:
metadata_author_groups = GroupProfile.objects.all()
else:
try:
all_metadata_author_groups = chain(
request.user.group_list_all(),
GroupProfile.objects.exclude(
access="private").exclude(access="public-invite"))
except BaseException:
all_metadata_author_groups = GroupProfile.objects.exclude(
access="private").exclude(access="public-invite")
[metadata_author_groups.append(item) for item in all_metadata_author_groups
if item not in metadata_author_groups]
poc_form.hidden = True
if metadata_author is None:
author_form = ProfileForm(request.POST, prefix="author")
else:
if metadata_author is None:
author_form = ProfileForm(
instance=metadata_author,
prefix="author")
else:
map_form.fields['metadata_author'].initial = metadata_author.id
author_form = ProfileForm(prefix="author")
author_form.hidden = True
config = map_obj.viewer_json(request)
layers = MapLayer.objects.filter(map=map_obj.id)
metadata_author_groups = []
if request.user.is_superuser or request.user.is_staff:
metadata_author_groups = GroupProfile.objects.all()
else:
try:
all_metadata_author_groups = chain(
request.user.group_list_all(),
GroupProfile.objects.exclude(
access="private").exclude(access="public-invite"))
except BaseException:
all_metadata_author_groups = GroupProfile.objects.exclude(
access="private").exclude(access="public-invite")
[metadata_author_groups.append(item) for item in all_metadata_author_groups
if item not in metadata_author_groups]
snapshot = self.kwargs.get('snapshot')
request = self.request
map_obj = _resolve_map(request,
mapid,
'base.view_resourcebase',
_PERMISSION_MSG_VIEW)
if snapshot is None:
config = map_obj.viewer_json(request)
else:
config = snapshot_config(snapshot,
map_obj,
request)
layers = Layer.objects.all()
map_layers = MapLayer.objects.filter(
map_id=mapid).order_by('stack_order')
context = {
'create': False,
'config': json.dumps(config),
'layers': layers,
'map_layers': map_layers,
'map': map_obj,
'preview': getattr(
settings,
'GEONODE_CLIENT_LAYER_PREVIEW_LIBRARY',
'')
}
return context