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(typename=maplayer.name) if gnLayer.srs: cfg['srs'] = gnLayer.srs 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, 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)
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, 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)