'Render a Map widget suitable for use in an S3Filter-based page
such as S3Summary
@param r: the S3Request
@param method: the widget method
@param widget_id: the widget ID
@param callback: None by default in case DIV is hidden
@param visible: whether the widget is initially visible
@param attr: controller attributes'

def widget(self, r, method='map', widget_id=None, visible=True, callback=None, **attr):

    if (not widget_id):
        widget_id = 'default_map'
    gis = current.gis
    tablename = self.tablename
    ftable = current.s3db.gis_layer_feature
    def lookup_layer(prefix, name):
        query = ((ftable.controller == prefix) & (ftable.function == name))
        layers = current.db(query).select(ftable.layer_id, ftable.style_default)
        if (len(layers) > 1):
            layers.exclude((lambda row: (row.style_default == False)))
        if (len(layers) == 1):
            layer_id = layers.first().layer_id
        else:
            layer_id = None
        return layer_id
    prefix = r.controller
    name = r.function
    layer_id = lookup_layer(prefix, name)
    if (not layer_id):
        (prefix, name) = tablename.split('_', 1)
        layer_id = lookup_layer(prefix, name)
    url = URL(extension='geojson', args=None)
    _id = 'search_results'
    feature_resources = [{'name': current.T('Search    Results'), 'id': _id, 'layer_id': layer_id, 'tablename': tablename, 'url': url, 'active': False}]
    settings = current.deployment_settings
    catalogue_layers = settings.get_gis_widget_catalogue_layers()
    legend = settings.get_gis_legend()
    search = settings.get_gis_search_geonames()
    toolbar = settings.get_gis_toolbar()
    wms_browser = settings.get_gis_widget_wms_browser()
    if wms_browser:
        config = gis.get_config()
        if config.wmsbrowser_url:
            wms_browser = wms_browser = {'name': config.wmsbrowser_name, 'url': config.wmsbrowser_url}
        else:
            wms_browser = None
    map = gis.show_map(id=widget_id, feature_resources=feature_resources, catalogue_layers=catalogue_layers, collapsed=True, legend=legend, toolbar=toolbar, save=False, search=search, wms_browser=wms_browser, callback=callback)
    return map
