def komoo_map(context, geojson={}, arg1='', arg2='', arg3='', arg4='',
              arg5='', arg6='', arg7='', arg8='', arg9='', arg10=''):
    """
    The syntax:
        {% komoo_map <geojson> [<project_id>] [type] [<width>] [<height>]
        [<zoom>] [panel] [ajax] [lazy] [edit_button] [maptype] %}
    """
    if isinstance(arg1, int):
        arg1 = 'project={}'.format(arg1)
    parsed_args = _parse_args(arg1, arg2, arg3, arg4, arg5, arg6, arg7,
                              arg8, arg9, arg10)
    type = parsed_args.get('type', 'main')
    width = parsed_args.get('width', '200')
    height = parsed_args.get('height', '200')
    zoom = parsed_args.get('zoom', 16)
    project = parsed_args.get('project', None)
    panel = parsed_args.get('panel', ('komoo_map/panel.html' if not type in
                                      ('preview', 'tooltip', 'view') else ''))
    ajax = parsed_args.get('ajax', 'True').lower() != 'false'
    lazy = parsed_args.get('lazy', 'False').lower() != 'false'
    edit_button = parsed_args.get('edit_button', 'False').lower() != 'false'
    maptype = parsed_args.get('maptype', 'clean')

    editable = type in ('main', 'editor')
    if geojson:
        geojson_dict = json.loads(geojson)
        for feature in geojson_dict.get('features', []):
            if 'properties' in feature and editable:
                feature['properties']['alwaysVisible'] = True
        geojson = to_json(geojson_dict)

    if not width.endswith('%') and not width.endswith('px'):
        width = width + 'px'
    if not height.endswith('%') and not height.endswith('px'):
        height = height + 'px'

    if getattr(settings, 'KOMOO_DISABLE_MAP', False):
        type = 'disabled'

    return dict(type=type, width=width, height=height, zoom=zoom, panel=panel,
                lazy=lazy, geojson=geojson, edit_button=edit_button,
                project=project, ajax=ajax, editable=editable, maptype=maptype,
                feature_types_json=get_models_json(),
                STATIC_URL=settings.STATIC_URL,
                LANGUAGE_CODE=settings.LANGUAGE_CODE)
def feature_types(request):
    return HttpResponse(get_models_json(), mimetype="application/x-javascript")
Exemple #3
0
def feature_types(request):
    return HttpResponse(get_models_json(), mimetype="application/x-javascript")