예제 #1
0
    def layerConfig(self, translate):
        config = {}
        for k in self.__dict__.keys():
            if not k.startswith("_") and \
                self.__dict__[k] is not None and \
                    k not in ('maps', 'staging'):
                if k == 'idBod':
                    config['label'] = translate(self.__dict__[k])
                elif k == 'attribution':
                    config[k] = translate(self.__dict__[k])
                elif k == 'matrixSet':
                    if self.__dict__[k] != '21781_26':
                        config['resolutions'] = self._getResolutionsFromMatrixSet(
                            self.__dict__[k]
                        )
                else:
                    config[k] = self.__dict__[k]

        staging = self.__dict__['staging']
        if config['type'] == 'wmts':
            del config['singleTile']
        if config['type'] == 'wms':
            if staging == 'test':
                config['wmsUrl'] = make_agnostic(
                    config['wmsUrl'].replace('wms.geo.admin.ch', 'wms-bgdi0t.bgdi.admin.ch'))
            if staging == 'integration':
                config['wmsUrl'] = make_agnostic(
                    config['wmsUrl'].replace('wms.geo.admin.ch', 'wms-bgdi0i.bgdi.admin.ch'))
        # sublayers don't have attributions
        if 'attribution' in config:
            config['attributionUrl'] = translate(self.__dict__['attribution'] + '.url')

        return {self.idBod: config}
예제 #2
0
파일: bod.py 프로젝트: cype/mf-chsdi3
    def layerConfig(self, params):
        config = {}
        translate = params.translate
        excludedAttrs = ('geojsonUrlde', 'geojsonUrlfr', 'geojsonUrlit',
                         'geojsonUrlrm', 'geojsonUrlen')
        wmsHost = params.request.registry.settings['wmshost']
        for k in self.__dict__.keys():
            if not k.startswith("_") and k not in excludedAttrs and \
                self.__dict__[k] is not None and \
                    k not in ('staging'):
                if k == 'maps':
                    config['topics'] = self.__dict__[k]
                elif k == 'layerBodId':
                    config['label'] = translate(self.__dict__[k])
                elif k == 'attribution':
                    config[k] = translate(self.__dict__[k])
                elif k == 'matrixSet':
                    if self.__dict__[k] != '21781_26':
                        config[
                            'resolutions'] = self._getResolutionsFromMatrixSet(
                                self.__dict__[k])
                else:
                    config[k] = self.__dict__[k]

        layerStaging = self.__dict__['staging']
        if config['type'] == 'wmts':
            del config['singleTile']
        elif config['type'] == 'wms':
            if layerStaging != 'prod':
                config['wmsUrl'] = make_agnostic(config['wmsUrl'].replace(
                    'wms.geo.admin.ch', wmsHost))
        elif config['type'] == 'geojson':
            api_url = params.request.registry.settings['api_url']
            config['styleUrl'] = make_agnostic(api_url +
                                               '/static/vectorStyles/' +
                                               self.layerBodId + '.json')
            config['geojsonUrl'] = self._getGeoJsonUrl(params.lang)
        # sublayers don't have attributions
        if 'attribution' in config:
            config['attributionUrl'] = translate(self.__dict__['attribution'] +
                                                 '.url')

        # adding __queryable_attributes__ if they have them
        models = models_from_name(self.layerBodId)
        if models is not None:
            queryable_attributes = get_models_attributes_keys(
                models, params.lang, True)
            if len(queryable_attributes) > 0:
                config['queryableAttributes'] = queryable_attributes

        return {self.layerBodId: config}
예제 #3
0
    def test_make_agnostic(self):
        url = 'http://foo.com'
        agnostic_link = make_agnostic(url)
        self.assertTrue(not agnostic_link.startswith('http://'))
        self.assertTrue(agnostic_link.startswith('//'))

        url_2 = 'https://foo.com'
        agnostic_link_2 = make_agnostic(url_2)
        self.assertTrue(not agnostic_link_2.startswith('https://'))
        self.assertTrue(agnostic_link_2.startswith('//'))

        url_3 = '//foo.com'
        agnostic_link_3 = make_agnostic(url_3)
        self.assertEqual(url_3, agnostic_link_3)
예제 #4
0
    def test_make_agnostic(self):
        url = 'http://foo.com'
        agnostic_link = make_agnostic(url)
        self.assertTrue(not agnostic_link.startswith('http://'))
        self.assertTrue(agnostic_link.startswith('//'))

        url_2 = 'https://foo.com'
        agnostic_link_2 = make_agnostic(url_2)
        self.assertTrue(not agnostic_link_2.startswith('https://'))
        self.assertTrue(agnostic_link_2.startswith('//'))

        url_3 = '//foo.com'
        agnostic_link_3 = make_agnostic(url_3)
        self.assertEqual(url_3, agnostic_link_3)
예제 #5
0
파일: bod.py 프로젝트: fredj/mf-chsdi3
    def layerConfig(self, params):
        config = {}
        translate = params.translate
        settings = params.request.registry.settings
        wmsHost = settings['wmshost']
        defaultResolution = 0.5
        for k in self.__dict__.keys():
            val = self.__dict__[k]
            if not k.startswith("_") and not k.startswith('geojsonUrl') and \
                    val is not None and k not in ('staging', 'srid'):
                if k == 'maps':
                    config['topics'] = val
                elif k == 'layerBodId':
                    config['label'] = translate(val)
                elif k == 'attribution':
                    config[k] = translate(val)
                elif k == 'tilematrix_resolution_max':
                    if val != defaultResolution and \
                            self.__dict__['srid'] != u'4326':
                        config[
                            'resolutions'] = self._getResolutionsFromMatrixSet(
                                val, params.srid)
                elif k == 'extent':  # Used for the shop, are still in lv03
                    if val and params.srid == 2056:
                        config['extent'] = shift_to(val, 2056)
                    else:
                        config['extent'] = val
                else:
                    config[k] = val

        if config['type'] in ('wmts', 'aggregate', 'geojson'):
            del config['singleTile']

        if not config['timeEnabled']:
            del config['timeBehaviour']

        if config['type'] == 'wms':
            config['wmsUrl'] = 'https://%s' % wmsHost
        elif config['type'] == 'geojson':
            api_url = params.request.registry.settings['api_url']
            config['styleUrl'] = make_agnostic(api_url +
                                               '/static/vectorStyles/' +
                                               self.layerBodId + '.json')
            config['geojsonUrl'] = self._getGeoJsonUrl(params.lang)
            if 'format' in config:
                del config['format']
        # sublayers don't have attributions
        if 'attribution' in config:
            config['attributionUrl'] = translate(self.__dict__['attribution'] +
                                                 '.url')

        # adding __queryable_attributes__ if they have them
        models = models_from_bodid(self.layerBodId)
        if models is not None:
            queryable_attributes = get_models_attributes_keys(
                models, params.lang, True)
            if len(queryable_attributes) > 0:
                config['queryableAttributes'] = queryable_attributes

        return {self.layerBodId: config}
예제 #6
0
파일: bod.py 프로젝트: ponceta/mf-chsdi3
    def layerConfig(self, params):
        config = {}
        translate = params.translate
        geodataStaging = params.geodataStaging
        wmsHost = params.request.registry.settings['wmshost']
        for k in self.__dict__.keys():
            if not k.startswith("_") and \
                self.__dict__[k] is not None and \
                    k not in ('maps', 'staging'):
                if k == 'layerBodId':
                    config['label'] = translate(self.__dict__[k])
                elif k == 'attribution':
                    config[k] = translate(self.__dict__[k])
                elif k == 'matrixSet':
                    if self.__dict__[k] != '21781_26':
                        config[
                            'resolutions'] = self._getResolutionsFromMatrixSet(
                                self.__dict__[k])
                else:
                    config[k] = self.__dict__[k]

        layerStaging = self.__dict__['staging']
        if config['type'] == 'wmts':
            del config['singleTile']
        if config['type'] == 'wms':
            if layerStaging != 'prod':
                config['wmsUrl'] = make_agnostic(config['wmsUrl'].replace(
                    'wms.geo.admin.ch', wmsHost))
        # sublayers don't have attributions
        if 'attribution' in config:
            config['attributionUrl'] = translate(self.__dict__['attribution'] +
                                                 '.url')

        return {self.layerBodId: config}
예제 #7
0
파일: bod.py 프로젝트: justb4/mf-chsdi3
    def layerConfig(self, params):
        config = {}
        translate = params.translate
        geodataStaging = params.geodataStaging
        wmsHost = params.request.registry.settings['wmshost']
        for k in self.__dict__.keys():
            if not k.startswith("_") and \
                self.__dict__[k] is not None and \
                    k not in ('maps', 'staging'):
                if k == 'layerBodId':
                    config['label'] = translate(self.__dict__[k])
                elif k == 'attribution':
                    config[k] = translate(self.__dict__[k])
                elif k == 'matrixSet':
                    if self.__dict__[k] != '21781_26':
                        config['resolutions'] = self._getResolutionsFromMatrixSet(
                            self.__dict__[k]
                        )
                else:
                    config[k] = self.__dict__[k]

        layerStaging = self.__dict__['staging']
        if config['type'] == 'wmts':
            del config['singleTile']
        if config['type'] == 'wms':
            if layerStaging != 'prod':
                config['wmsUrl'] = make_agnostic(
                    config['wmsUrl'].replace('wms.geo.admin.ch', wmsHost))
        # sublayers don't have attributions
        if 'attribution' in config:
            config['attributionUrl'] = translate(self.__dict__['attribution'] + '.url')

        return {self.layerBodId: config}
예제 #8
0
파일: bod.py 프로젝트: cclauss/mf-chsdi3
    def layerConfig(self, params):
        config = {}
        translate = params.translate
        wmsHost = params.request.registry.settings['wmshost']
        for k in self.__dict__.keys():
            val = self.__dict__[k]
            if not k.startswith("_") and not k.startswith('geojsonUrl') and \
                    val is not None and k not in ('staging', 'srid'):
                if k == 'maps':
                    config['topics'] = val
                elif k == 'layerBodId':
                    config['label'] = translate(val)
                elif k == 'attribution':
                    config[k] = translate(val)
                elif k == 'matrixSet':
                    if val != self.defaultMatrixSet21781 and \
                            self.__dict__['srid'] != '4326':
                        config['resolutions'] = self._getResolutionsFromMatrixSet(
                            val)
                else:
                    config[k] = val

        layerStaging = self.__dict__['staging']
        if config['type'] in ('wmts', 'aggregate', 'geojson'):
            del config['singleTile']

        if config['type'] == 'wms':
            if layerStaging != 'prod':
                config['wmsUrl'] = make_agnostic(
                    config['wmsUrl'].replace('wms.geo.admin.ch', wmsHost))
        elif config['type'] == 'geojson':
            api_url = params.request.registry.settings['api_url']
            config['styleUrl'] = make_agnostic(
                api_url + '/static/vectorStyles/' + self.layerBodId + '.json')
            config['geojsonUrl'] = self._getGeoJsonUrl(params.lang)
        # sublayers don't have attributions
        if 'attribution' in config:
            config['attributionUrl'] = translate(self.__dict__['attribution'] + '.url')

        # adding __queryable_attributes__ if they have them
        models = models_from_bodid(self.layerBodId)
        if models is not None:
            queryable_attributes = get_models_attributes_keys(models, params.lang, True)
            if len(queryable_attributes) > 0:
                config['queryableAttributes'] = queryable_attributes

        return {self.layerBodId: config}
예제 #9
0
파일: bod.py 프로젝트: geoadmin/mf-chsdi3
    def layerConfig(self, params):
        config = {}
        translate = params.translate
        settings = params.request.registry.settings
        wmsHost = settings['wmshost']
        defaultResolution = 0.5
        for k in self.__dict__.keys():
            val = self.__dict__[k]
            if not k.startswith("_") and not k.startswith('geojsonUrl') and \
                    val is not None and k not in ('staging', 'srid'):
                if k == 'maps':
                    config['topics'] = val
                elif k == 'layerBodId':
                    config['label'] = translate(val)
                elif k == 'attribution':
                    config[k] = translate(val)
                elif k == 'tilematrix_resolution_max':
                    if val != defaultResolution and \
                            self.__dict__['srid'] != u'4326':
                        config['resolutions'] = self._getResolutionsFromMatrixSet(
                            val, params.srid)
                elif k == 'extent':  # Used for the shop, are still in lv03
                    if val and params.srid == 2056:
                        config['extent'] = shift_to(val, 2056)
                    else:
                        config['extent'] = val
                else:
                    config[k] = val

        if config['type'] in ('wmts', 'aggregate', 'geojson'):
            del config['singleTile']

        if not config['timeEnabled']:
            del config['timeBehaviour']

        if config['type'] == 'wms':
            config['wmsUrl'] = 'https://%s' % wmsHost
        elif config['type'] == 'geojson':
            api_url = params.request.registry.settings['api_url']
            config['styleUrl'] = make_agnostic(
                api_url + '/static/vectorStyles/' + self.layerBodId + '.json')
            config['geojsonUrl'] = self._getGeoJsonUrl(params.lang)
            if 'format' in config:
                del config['format']
        # sublayers don't have attributions
        if 'attribution' in config:
            config['attributionUrl'] = translate(self.__dict__['attribution'] + '.url')

        # adding __queryable_attributes__ if they have them
        models = models_from_bodid(self.layerBodId)
        if models is not None:
            queryable_attributes = get_models_attributes_keys(models, params.lang, True)
            if len(queryable_attributes) > 0:
                config['queryableAttributes'] = queryable_attributes

        return {self.layerBodId: config}
예제 #10
0
파일: bod.py 프로젝트: qbns/mf-chsdi3
    def layerConfig(self, params):
        config = {}
        translate = params.translate
        excludedAttrs = ('geojsonUrlde', 'geojsonUrlfr', 'geojsonUrlit', 'geojsonUrlrm', 'geojsonUrlen')
        wmsHost = params.request.registry.settings['wmshost']
        for k in self.__dict__.keys():
            if not k.startswith("_") and k not in excludedAttrs and \
                self.__dict__[k] is not None and \
                    k not in ('staging'):
                if k == 'maps':
                    config['topics'] = self.__dict__[k]
                elif k == 'layerBodId':
                    config['label'] = translate(self.__dict__[k])
                elif k == 'attribution':
                    config[k] = translate(self.__dict__[k])
                elif k == 'matrixSet':
                    if self.__dict__[k] != '21781_26':
                        config['resolutions'] = self._getResolutionsFromMatrixSet(
                            self.__dict__[k]
                        )
                else:
                    config[k] = self.__dict__[k]

        layerStaging = self.__dict__['staging']
        if config['type'] == 'wmts':
            del config['singleTile']
        elif config['type'] == 'wms':
            if layerStaging != 'prod':
                config['wmsUrl'] = make_agnostic(
                    config['wmsUrl'].replace('wms.geo.admin.ch', wmsHost))
        elif config['type'] == 'geojson':
            api_url = params.request.registry.settings['api_url']
            config['styleUrl'] = make_agnostic(
                api_url + '/static/vectorStyles/' + self.layerBodId + '.json')
            config['geojsonUrl'] = self._getGeoJsonUrl(params.lang)
        # sublayers don't have attributions
        if 'attribution' in config:
            config['attributionUrl'] = translate(self.__dict__['attribution'] + '.url')

        return {self.layerBodId: config}