'GIS / GIS Controllers'

@staticmethod
def gis():

    MAP_ADMIN = current.session.s3.system_roles.MAP_ADMIN
    settings = current.deployment_settings
    gis_menu = settings.get_gis_menu()
    def pois(i):
        poi_resources = settings.get_gis_poi_create_resources()
        if (not poi_resources):
            return False
        for res in poi_resources:
            if (res['table'] == 'gis_poi'):
                return True
        return False
    def config_menu(i):
        auth = current.auth
        if (not auth.is_logged_in()):
            return False
        s3db = current.s3db
        if auth.s3_has_permission('create', s3db.gis_config):
            return True
        table = s3db.gis_config
        query = (table.pe_id == auth.user.pe_id)
        config = current.db(query).select(table.id, limitby=(0, 1), cache=s3db.cache).first()
        if config:
            return True
    def config_args():
        auth = current.auth
        if (not auth.user):
            return []
        if auth.s3_has_role(MAP_ADMIN):
            return []
        s3db = current.s3db
        table = s3db.gis_config
        query = (table.pe_id == auth.user.pe_id)
        config = current.db(query).select(table.id, limitby=(0, 1), cache=s3db.cache).first()
        if config:
            return [config.id, 'layer_entity']
        return ['create']
    return M(c='gis')(M('Fullscreen    Map', c='gis', f='map_viewing_client'), M('Locations', c='gis', f='location')(M('Create', m='create'), M('Import    from    CSV', m='import', restrict=[MAP_ADMIN]), M('Import    from    OpenStreetMap', m='import_poi', restrict=[MAP_ADMIN])), M('PoIs', c='gis', f='poi', check=pois)(), M('Configuration', c='gis', f='config', args=config_args(), _id='gis_menu_config', check=config_menu), M('Admin', c='gis', restrict=[MAP_ADMIN])(M('Hierarchy', f='hierarchy'), M('Layers', f='catalog'), M('Markers', f='marker'), M('Menu', f='menu', check=[gis_menu]), M('PoI    Types', f='poi_type', check=[pois]), M('Projections', f='projection'), M('Styles', f='style')))
