def snapshot_config(snapshot, map_obj, request): """ Get the snapshot map configuration - look up WMS parameters (bunding box) for local GeoNode layers """ # Match up the layer with it's source def snapsource_lookup(source, sources): for k, v in sources.iteritems(): if v.get("id") == source.get("id"): return k return None # Set up the proper layer configuration def snaplayer_config(layer, sources, request): cfg = layer.layer_config() src_cfg = layer.source_config() source = snapsource_lookup(src_cfg, sources) if source: cfg["source"] = source if src_cfg.get( "ptype", "gxp_wmscsource") == "gxp_wmscsource" or src_cfg.get( "ptype", "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
def snapshot_config(snapshot, map_obj, user, access_token): """ Get the snapshot map configuration - look up WMS parameters (bunding box) for local GeoNode layers """ # Match up the layer with it's source def snapsource_lookup(source, sources): for k, v in sources.iteritems(): if v.get("id") == source.get("id"): return k return None # Set up the proper layer configuration def snaplayer_config(layer, sources, user, access_token): cfg = layer.layer_config() src_cfg = layer.source_config() source = snapsource_lookup(src_cfg, sources) if source: cfg["source"] = source if src_cfg.get( "ptype", "gxp_wmscsource") == "gxp_wmscsource" or src_cfg.get( "ptype", "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, user, access_token) for l in maplayers] else: config = map_obj.viewer_json(user, access_token) return config
def snaplayer_config(layer, sources, request): user = request.user if request else None cfg = layer_config(layer, user) src_cfg = source_config(layer) source = snapsource_lookup(src_cfg, sources) if source: cfg["source"] = source if src_cfg.get("ptype", "gxp_wmscsource") == "gxp_wmscsource" or src_cfg.get( "ptype", "gxp_gnsource") == "gxp_gnsource": 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))
def snapshot_config(snapshot, map_obj, request): """ Get the snapshot map configuration - look up WMS parameters (bunding box) for local GeoNode layers """ def source_config(maplayer): """ Generate a dict that can be serialized to a GXP layer source configuration suitable for loading this layer. """ try: cfg = json.loads(maplayer.source_params) except Exception: cfg = dict(ptype="gxp_gnsource", restUrl="/gs/rest") if maplayer.ows_url: cfg["url"] = ows_sub.sub('', maplayer.ows_url) if "ptype" not in cfg: cfg["ptype"] = "gxp_wmscsource" if "ptype" in cfg and cfg["ptype"] == "gxp_gnsource": cfg["restUrl"] = "/gs/rest" return cfg def layer_config(maplayer, user): """ Generate a dict that can be serialized to a GXP layer configuration suitable for loading this layer. The "source" property will be left unset; the layer is not aware of the name assigned to its source plugin. See :method:`geonode.maps.models.Map.viewer_json` for an example of generating a full map configuration. """ try: cfg = json.loads(maplayer.layer_params) except Exception: cfg = dict() if maplayer.format: cfg['format'] = maplayer.format if maplayer.name: cfg["name"] = maplayer.name if maplayer.opacity: cfg['opacity'] = maplayer.opacity if maplayer.styles: cfg['styles'] = maplayer.styles if maplayer.transparent: cfg['transparent'] = True cfg["fixed"] = maplayer.fixed if 'url' not in cfg: cfg['url'] = maplayer.ows_url if cfg['url']: cfg['url'] = ows_sub.sub('', cfg['url']) if maplayer.group: cfg["group"] = maplayer.group cfg["visibility"] = maplayer.visibility if maplayer.name is not None and maplayer.source_params.find( "gxp_gnsource") > -1: # Get parameters from GeoNode instead of WMS GetCapabilities try: gnLayer = Layer.objects.get(alternate=maplayer.name) if gnLayer.srid: cfg['srs'] = gnLayer.srid if gnLayer.bbox: cfg['bbox'] = json.loads(gnLayer.bbox) if gnLayer.llbbox: cfg['llbbox'] = json.loads(gnLayer.llbbox) cfg['attributes'] = (get_layer_attributes(gnLayer)) attribute_cfg = gnLayer.attribute_config() if "getFeatureInfo" in attribute_cfg: cfg["getFeatureInfo"] = attribute_cfg["getFeatureInfo"] cfg['queryable'] = (gnLayer.storeType == 'dataStore'), cfg['disabled'] = user is not None and not user.has_perm( 'maps.view_layer', obj=gnLayer) # cfg["displayOutsideMaxExtent"] = user is not None and user.has_perm('maps.change_layer', obj=gnLayer) cfg['visibility'] = cfg['visibility'] and not cfg['disabled'] cfg['abstract'] = gnLayer.abstract cfg['styles'] = maplayer.styles cfg['local'] = True except Exception as e: # Give it some default values so it will still show up on the map, but disable it in the layer tree cfg['srs'] = 'EPSG:900913' cfg['llbbox'] = [-180, -90, 180, 90] cfg['attributes'] = [] cfg['queryable'] = False, cfg['disabled'] = False cfg['visibility'] = cfg['visibility'] and not cfg['disabled'] cfg['abstract'] = '' cfg['styles'] = '' print "Could not retrieve Layer with typename of %s : %s" % ( maplayer.name, str(e)) elif maplayer.source_params.find("gxp_hglsource") > -1: # call HGL ServiceStarter asynchronously to load the layer into HGL geoserver from geonode.queue.tasks import loadHGL loadHGL.delay(maplayer.name) return cfg # Match up the layer with it's source def snapsource_lookup(source, sources): for k, v in sources.iteritems(): if v.get("id") == source.get("id"): return k return None # Set up the proper layer configuration # def snaplayer_config(layer, sources, user): def snaplayer_config(layer, sources, request): user = request.user if request else None cfg = layer_config(layer, user) src_cfg = source_config(layer) source = snapsource_lookup(src_cfg, sources) if source: cfg["source"] = source if src_cfg.get("ptype", "gxp_wmscsource") == "gxp_wmscsource" or src_cfg.get( "ptype", "gxp_gnsource") == "gxp_gnsource": 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(map_obj.id, MapLayer, layer, config["sources"][layer["source"]], ordering, False)) # 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
cfg = layer_config(layer, user) src_cfg = source_config(layer) source = snapsource_lookup(src_cfg, sources) if source: cfg["source"] = source if src_cfg.get( "ptype", "gxp_wmscsource") == "gxp_wmscsource" or src_cfg.get( "ptype", "gxp_gnsource") == "gxp_gnsource": 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( map_obj.id, MapLayer, layer, config["sources"][ layer["source"]], ordering,
def snapshot_config(snapshot, map_obj, request): """ Get the snapshot map configuration - look up WMS parameters (bunding box) for local GeoNode layers """ def source_config(maplayer): """ Generate a dict that can be serialized to a GXP layer source configuration suitable for loading this layer. """ try: cfg = json.loads(maplayer.source_params) except Exception: cfg = dict(ptype="gxp_gnsource", restUrl="/gs/rest") if maplayer.ows_url: cfg["url"] = ows_sub.sub('', maplayer.ows_url) if "ptype" not in cfg: cfg["ptype"] = "gxp_wmscsource" if "ptype" in cfg and cfg["ptype"] == "gxp_gnsource": cfg["restUrl"] = "/gs/rest" return cfg def layer_config(maplayer, user): """ Generate a dict that can be serialized to a GXP layer configuration suitable for loading this layer. The "source" property will be left unset; the layer is not aware of the name assigned to its source plugin. See :method:`geonode.maps.models.Map.viewer_json` for an example of generating a full map configuration. """ try: cfg = json.loads(maplayer.layer_params) except Exception: cfg = dict() if maplayer.format: cfg['format'] = maplayer.format if maplayer.name: cfg["name"] = maplayer.name if maplayer.opacity: cfg['opacity'] = maplayer.opacity if maplayer.styles: cfg['styles'] = maplayer.styles if maplayer.transparent: cfg['transparent'] = True cfg["fixed"] = maplayer.fixed if 'url' not in cfg: cfg['url'] = maplayer.ows_url if cfg['url']: cfg['url'] = ows_sub.sub('', cfg['url']) if maplayer.group: cfg["group"] = maplayer.group cfg["visibility"] = maplayer.visibility if maplayer.name is not None and maplayer.source_params.find("gxp_gnsource") > -1: # Get parameters from GeoNode instead of WMS GetCapabilities try: gnLayer = Layer.objects.get(alternate=maplayer.name) if gnLayer.srid: cfg['srs'] = gnLayer.srid if gnLayer.bbox: cfg['bbox'] = json.loads(gnLayer.bbox) if gnLayer.llbbox: cfg['llbbox'] = json.loads(gnLayer.llbbox) cfg['attributes'] = (get_layer_attributes(gnLayer)) attribute_cfg = gnLayer.attribute_config() if "getFeatureInfo" in attribute_cfg: cfg["getFeatureInfo"] = attribute_cfg["getFeatureInfo"] cfg['queryable'] = (gnLayer.storeType == 'dataStore'), cfg['disabled'] = user is not None and not user.has_perm('maps.view_layer', obj=gnLayer) # cfg["displayOutsideMaxExtent"] = user is not None and user.has_perm('maps.change_layer', obj=gnLayer) cfg['visibility'] = cfg['visibility'] and not cfg['disabled'] cfg['abstract'] = gnLayer.abstract cfg['styles'] = maplayer.styles cfg['local'] = True except Exception as e: # Give it some default values so it will still show up on the map, but disable it in the layer tree cfg['srs'] = 'EPSG:900913' cfg['llbbox'] = [-180, -90, 180, 90] cfg['attributes'] = [] cfg['queryable'] = False, cfg['disabled'] = False cfg['visibility'] = cfg['visibility'] and not cfg['disabled'] cfg['abstract'] = '' cfg['styles'] = '' print "Could not retrieve Layer with typename of %s : %s" % (maplayer.name, str(e)) elif maplayer.source_params.find("gxp_hglsource") > -1: # call HGL ServiceStarter asynchronously to load the layer into HGL geoserver from geonode.queue.tasks import loadHGL loadHGL.delay(maplayer.name) return cfg # Match up the layer with it's source def snapsource_lookup(source, sources): for k, v in sources.iteritems(): if v.get("id") == source.get("id"): return k return None # Set up the proper layer configuration # def snaplayer_config(layer, sources, user): def snaplayer_config(layer, sources, request): user = request.user if request else None cfg = layer_config(layer, user) src_cfg = source_config(layer) source = snapsource_lookup(src_cfg, sources) if source: cfg["source"] = source if src_cfg.get( "ptype", "gxp_wmscsource") == "gxp_wmscsource" or src_cfg.get( "ptype", "gxp_gnsource") == "gxp_gnsource": 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( map_obj.id, MapLayer, layer, config["sources"][ layer["source"]], ordering, False)) # 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