'Lookup Theme Layer polygons once per layer and not per-record
Called by S3REST: S3Resource.export_tree()
@ToDo: Vary precision by Lx
- store this (& tolerance map) in the style?'

@staticmethod
def get_theme_geojson(resource):

    s3db = current.s3db
    tablename = 'gis_theme_data'
    table = s3db.gis_theme_data
    gtable = s3db.gis_location
    query = (table.id.belongs(resource._ids) & (table.location_id == gtable.id))
    geojsons = {}
    rows = current.db(query).select(table.id, gtable.level, gtable.wkt)
    simplify = GIS.simplify
    tolerance = {'L0': 0.01, 'L1': 0.005, 'L2': 0.00125, 'L3': 0.000625, 'L4': 0.0003125, 'L5': 0.00015625}
    for row in rows:
        grow = row.gis_location
        geojson = simplify(grow.wkt, tolerance=tolerance[grow.level], output='geojson')
        if geojson:
            geojsons[row['gis_theme_data.id']] = geojson
    _geojsons = {}
    _geojsons[tablename] = geojsons
    return dict(geojsons=_geojsons)
