How to use the geonode.maps.models.MapLayer function in GeoNode

To help you get started, we’ve selected a few GeoNode examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cholmes / mapstory / tests.py View on Github external
# lets publish it and ensure things work
        self.bobby.useractivity.other_actor_actions.clear()
        admin_map.publish.status = 'Public'
        admin_map.publish.save()
        # there should be a single 'public' action (the other exists so it can hang on bobby)
        actions = self.admin.actor_actions.public()
        self.assertEqual(1, len(actions))
        self.assertEqual('admin published map1 by admin 0 minutes ago', str(actions[0]))
        # and a single action for bobby
        actions = self.bobby.useractivity.other_actor_actions.all()
        self.assertEqual(1, len(actions))
        self.assertEqual('admin published layer1 Layer on map1 by admin 0 minutes ago', str(actions[0]))
        
        # already published, add another layer and make sure it shows up in bobby
        self.bobby.useractivity.other_actor_actions.clear()
        MapLayer.objects.create(name = 'layer2', ows_url='layer2', map=dummy, stack_order=2)
        admin_map.update_from_viewer(dummy.viewer_json())
        actions = self.bobby.useractivity.other_actor_actions.all()
        self.assertEqual(1, len(actions))
        self.assertEqual('admin added layer2 Layer on map1 by admin 0 minutes ago', str(actions[0]))
github GeoNode / geonode / geonode / maps / views.py View on Github external
ows_url=layer.ows_url,
                                layer_params=json.dumps(config),
                                visibility=True,
                                source_params=json.dumps(source_params)
            )
        else:
            ogc_server_url = urlparse.urlsplit(
                ogc_server_settings.PUBLIC_LOCATION).netloc
            layer_url = urlparse.urlsplit(layer.ows_url).netloc

            access_token = request.session['access_token'] if request and 'access_token' in request.session else None
            if access_token and ogc_server_url == layer_url and 'access_token' not in layer.ows_url:
                url = layer.ows_url + '?access_token=' + access_token
            else:
                url = layer.ows_url
            maplayer = MapLayer(
                map=map_obj,
                name=layer.alternate,
                ows_url=url,
                # use DjangoJSONEncoder to handle Decimal values
                layer_params=json.dumps(config, cls=DjangoJSONEncoder),
                visibility=True
            )

        layers.append(maplayer)

    if bbox and len(bbox) >= 4:
        minx, maxx, miny, maxy = [float(coord) for coord in bbox]
        x = (minx + maxx) / 2
        y = (miny + maxy) / 2

        if getattr(
github cga-harvard / worldmap / wm_extra / views.py View on Github external
visibility=True,
                                source_params=json.dumps({
                                    "ptype": service.ptype,
                                    "remote": True,
                                    "url": url,
                                    "name": service.name}))
        else:
            ogc_server_url = urlparse.urlsplit(
                ogc_server_settings.PUBLIC_LOCATION).netloc
            layer_url = urlparse.urlsplit(layer.ows_url).netloc

            if access_token and ogc_server_url == layer_url and 'access_token' not in layer.ows_url:
                url = layer.ows_url+'?access_token='+access_token
            else:
                url = layer.ows_url
            maplayer = MapLayer(
                map=map_obj,
                name=layer.alternate,
                ows_url=url,
                # use DjangoJSONEncoder to handle Decimal values
                layer_params=json.dumps(config, cls=DjangoJSONEncoder),
                visibility=True
            )
        layers.append(maplayer)

    if bbox is not None:
        minx, miny, maxx, maxy = [float(coord) for coord in bbox]
        x = (minx + maxx) / 2
        y = (miny + maxy) / 2

        if getattr(
            settings,
github GeoNode / geonode / geonode / maps / qgis_server_views.py View on Github external
"remote": True,
                                                  "url": url,
                                                  "name": service.name,
                                                  "title": "[R] %s" % service.title}))
                    else:
                        ogc_server_url = urlsplit(
                            ogc_server_settings.PUBLIC_LOCATION).netloc
                        layer_url = urlsplit(layer.ows_url).netloc

                        if access_token and ogc_server_url == layer_url and \
                                'access_token' not in layer.ows_url:
                            url = layer.ows_url + '?access_token=' + \
                                access_token
                        else:
                            url = layer.ows_url
                        map_layers = MapLayer(
                            map=map_obj,
                            name=layer.typename,
                            ows_url=url,
                            # use DjangoJSONEncoder to handle Decimal values
                            layer_params=json.dumps(
                                config,
                                cls=DjangoJSONEncoder),
                            visibility=True
                        )

                if bbox and len(bbox) >= 4:
                    minx, miny, maxx, maxy = [float(coord) for coord in bbox]
                    x = (minx + maxx) / 2
                    y = (miny + maxy) / 2

                    if getattr(settings,
github GeoNode / geonode / geonode / contrib / worldmap / wm_extra / views.py View on Github external
visibility=True,
                                source_params=json.dumps({
                                    "ptype": service.ptype,
                                    "remote": True,
                                    "url": url,
                                    "name": service.name}))
        else:
            ogc_server_url = urlparse.urlsplit(
                ogc_server_settings.PUBLIC_LOCATION).netloc
            layer_url = urlparse.urlsplit(layer.ows_url).netloc

            if access_token and ogc_server_url == layer_url and 'access_token' not in layer.ows_url:
                url = layer.ows_url+'?access_token='+access_token
            else:
                url = layer.ows_url
            maplayer = MapLayer(
                map=map_obj,
                name=layer.alternate,
                ows_url=url,
                # use DjangoJSONEncoder to handle Decimal values
                layer_params=json.dumps(config, cls=DjangoJSONEncoder),
                visibility=True
            )
        layers.append(maplayer)

    if bbox is not None:
        minx, maxx, miny, maxy = [float(coord) for coord in bbox]
        x = (minx + maxx) / 2
        y = (miny + maxy) / 2

        if getattr(
            settings,
github cga-harvard / worldmap / wm_extra / views.py View on Github external
else llbbox_to_mercator([float(coord) for coord in bbox])

        if layer.storeType == "remoteStore":
            service = layer.service
            # Probably not a good idea to send the access token to every remote service.
            # This should never match, so no access token should be
            # sent to remote services.
            ogc_server_url = urlparse.urlsplit(
                ogc_server_settings.PUBLIC_LOCATION).netloc
            service_url = urlparse.urlsplit(service.base_url).netloc

            if access_token and ogc_server_url == service_url and 'access_token' not in service.base_url:
                url = service.base_url+'?access_token='+access_token
            else:
                url = service.base_url
            maplayer = MapLayer(map=map_obj,
                                name=layer.alternate,
                                ows_url=layer.ows_url,
                                layer_params=json.dumps(config),
                                visibility=True,
                                source_params=json.dumps({
                                    "ptype": service.ptype,
                                    "remote": True,
                                    "url": url,
                                    "name": service.name}))
        else:
            ogc_server_url = urlparse.urlsplit(
                ogc_server_settings.PUBLIC_LOCATION).netloc
            layer_url = urlparse.urlsplit(layer.ows_url).netloc

            if access_token and ogc_server_url == layer_url and 'access_token' not in layer.ows_url:
                url = layer.ows_url+'?access_token='+access_token
github GeoNode / geonode / geonode / maps / views.py View on Github external
"gxp_gnsource") == "gxp_gnsource":
            cfg["buffer"] = 0
        return cfg

    decodedid = num_decode(snapshot)
    snapshot = get_object_or_404(MapSnapshot, pk=decodedid)
    if snapshot.map == map_obj.map:
        config = json.loads(clean_config(snapshot.config))
        layers = [_l for _l in config["map"]["layers"]]
        sources = config["sources"]
        maplayers = []
        for ordering, layer in enumerate(layers):
            maplayers.append(
                layer_from_viewer_config(
                    map_obj.id,
                    MapLayer,
                    layer,
                    config["sources"][
                        layer["source"]],
                    ordering))
        # map_obj.map.layer_set.from_viewer_config(
        # map_obj, layer, config["sources"][layer["source"]], ordering))
        config['map']['layers'] = [
            snaplayer_config(
                _l,
                sources,
                request) for _l in maplayers]
    else:
        config = map_obj.viewer_json(request)
    return config
github GeoNode / geonode / geonode / base / management / commands / migrate_baseurl.py View on Github external
if force_exec or helpers.confirm(prompt=message, resp=False):
            try:
                # Deactivate GeoNode Signals
                print("Deactivating GeoNode Signals...")
                designals()
                print("...done!")

                _cnt = Map.objects.filter(thumbnail_url__icontains=source_address).update(
                    thumbnail_url=Func(
                        F('thumbnail_url'),Value(source_address),Value(target_address),function='replace'))
                print("Updated %s Maps" % _cnt)

                _cnt = MapLayer.objects.filter(ows_url__icontains=source_address).update(
                    ows_url=Func(
                        F('ows_url'),Value(source_address),Value(target_address),function='replace'))
                MapLayer.objects.filter(layer_params__icontains=source_address).update(
                    layer_params=Func(
                        F('layer_params'),Value(source_address),Value(target_address),function='replace'))
                print("Updated %s MapLayers" % _cnt)

                _cnt = Layer.objects.filter(thumbnail_url__icontains=source_address).update(
                    thumbnail_url=Func(
                        F('thumbnail_url'),Value(source_address),Value(target_address),function='replace'))
                print("Updated %s Layers" % _cnt)

                _cnt = Style.objects.filter(sld_url__icontains=source_address).update(
                    sld_url=Func(
                        F('sld_url'),Value(source_address),Value(target_address),function='replace'))
                print("Updated %s Styles" % _cnt)

                _cnt = Link.objects.filter(url__icontains=source_address).update(
                    url=Func(
github GeoNode / geonode / geonode / contrib / worldmap / wm_extra / views.py View on Github external
cfg["buffer"] = 0
        return cfg

    from geonode.utils import num_decode
    from geonode.utils import layer_from_viewer_config
    decodedid = num_decode(snapshot)
    snapshot = get_object_or_404(MapSnapshot, pk=decodedid)
    if snapshot.map == map_obj.map:
        config = json.loads(clean_config(snapshot.config))
        layers = [l for l in config["map"]["layers"]]
        sources = config["sources"]
        maplayers = []
        for ordering, layer in enumerate(layers):
            maplayers.append(
                layer_from_viewer_config(
                    MapLayer,
                    layer,
                    config["sources"][
                        layer["source"]],
                    ordering))
#             map_obj.map.layer_set.from_viewer_config(
# map_obj, layer, config["sources"][layer["source"]], ordering))
        config['map']['layers'] = [
            snaplayer_config(
                l,
                sources,
                request) for l in maplayers]
    else:
        config = map_obj.viewer_json(request)

    return config