def leaflet_map(name, callback=None, fitextent=True, creatediv=True): """ :param name: :param callback: :param fitextent: :param creatediv: :return: """ if callback is None: callback = "%sInit" % name tilesurl = app_settings.get('TILES_URL') if tilesurl and isinstance(tilesurl, basestring): tilesurl = (('background', tilesurl),) extent = None if SPATIAL_EXTENT is not None: xmin, ymin, xmax, ymax = SPATIAL_EXTENT extent = (ymin, xmin, ymax, xmax) t = template.loader.get_template("leaflet/map_fragment.html") return t.render(Context(dict(name=name, creatediv=creatediv, srid=SRID, extent=list(extent), center=app_settings['DEFAULT_CENTER'], zoom=app_settings['DEFAULT_ZOOM'], fitextent=fitextent, tilesurl=[list(url) for url in tilesurl], callback=callback, scale=app_settings.get('SCALE'), minimap=app_settings.get('MINIMAP'), tilesextent=list(app_settings.get('TILES_EXTENT', [])), )))
def leaflet_map(name, callback=None, fitextent=True, creatediv=True, loadevent=app_settings.get('LOADEVENT'), settings_overrides={}): """ :param name: :param callback: :param fitextent: :param creatediv: :param loadevent: :param settings_overrides: :return: """ extent = None if SPATIAL_EXTENT is not None: # Leaflet uses [lat, lng] xmin, ymin, xmax, ymax = SPATIAL_EXTENT extent = (ymin, xmin, ymax, xmax) if settings_overrides == '': settings_overrides = {} app_settings.update(**settings_overrides) djoptions = dict( srid=SRID, extent=[extent[:2], extent[2:4]], fitextent=fitextent, center=app_settings['DEFAULT_CENTER'], zoom=app_settings['DEFAULT_ZOOM'], minzoom=app_settings['MIN_ZOOM'], maxzoom=app_settings['MAX_ZOOM'], layers=[(force_text(label), url, attrs) for (label, url, attrs) in app_settings.get('TILES')], overlays=[(force_text(label), url, attrs) for (label, url, attrs) in app_settings.get('OVERLAYS')], attributionprefix=force_text(app_settings.get('ATTRIBUTION_PREFIX'), strings_only=True), scale=app_settings.get('SCALE'), minimap=app_settings.get('MINIMAP'), resetview=app_settings.get('RESET_VIEW'), tilesextent=list(app_settings.get('TILES_EXTENT', []))) return { # templatetag options 'name': name, 'loadevents': json.dumps(loadevent.split(), cls=JSONLazyTranslationEncoder), 'creatediv': creatediv, 'callback': callback, # initialization options 'djoptions': json.dumps(djoptions, cls=JSONLazyTranslationEncoder), # settings 'NO_GLOBALS': app_settings.get('NO_GLOBALS'), }
def leaflet_js(): t = template.loader.get_template("leaflet/head_fragment.html") return t.render( Context( dict(debug=settings.TEMPLATE_DEBUG, version=app_settings.get('LEAFLET_VERSION'), srid=SRID)))
def _get_attrs(self, name, attrs=None): assert self.map_srid == 4326, 'Leaflet vectors should be decimal degrees.' # Retrieve params from Field init (if any) self.geom_type = self.attrs.get('geom_type', self.geom_type) self.settings_overrides = self.attrs.get('settings_overrides', self.settings_overrides) # Setting 'loadevent' added in the widget constructor loadevent = self.attrs.get('loadevent', app_settings.get('LOADEVENT')) attrs = attrs or {} # In BaseGeometryWidget, geom_type is set using gdal, and fails with generic. # See https://code.djangoproject.com/ticket/21021 if self.geom_type == 'GEOMETRY': attrs['geom_type'] = 'Geometry' map_id_css = slugify(attrs.get('id', name)).replace('__prefix__', '__PREFIX__') # id need to have - for the inline formset to replace the prefix map_id = map_id_css.replace('-', '_') # JS-safe attrs.update(id=map_id, id_css=map_id_css, module='geodjango_%s' % map_id, id_map=map_id_css + '-map', id_map_callback=map_id + '_map_callback', loadevent=loadevent, modifiable=self.modifiable, target_map=attrs.get('target_map', getattr(self, 'target_map', None)), settings_overrides=attrs.get('settings_overrides', getattr(self, 'settings_overrides', None)), geometry_field_class=attrs.get('geometry_field_class', getattr(self, 'geometry_field_class', 'L.GeometryField')), field_store_class=attrs.get('field_store_class', getattr(self, 'field_store_class', 'L.FieldStore'))) return attrs
def render(self, name, value, attrs=None): assert self.map_srid == 4326, 'Leaflet vectors should be decimal degrees.' value = None if value in validators.EMPTY_VALUES else value # Retrieve params from Field init (if any) self.geom_type = self.attrs.get('geom_type', self.geom_type) # Setting 'loadevent' added in the widget constructor loadevent = self.attrs.get('loadevent', app_settings.get('LOADEVENT')) attrs = attrs or {} # In BaseGeometryWidget, geom_type is set using gdal, and fails with generic. # See https://code.djangoproject.com/ticket/21021 if self.geom_type == 'GEOMETRY': attrs['geom_type'] = 'Geometry' map_id = slugify(attrs.get('id', name)).replace('-', '_') # JS-safe attrs.update(id=map_id, module='geodjango_%s' % map_id, id_map=map_id + '_map', id_map_callback=map_id + '_map_callback', loadevent=loadevent, modifiable=self.modifiable, target_map=attrs.get('target_map', getattr(self, 'target_map', None)), geometry_field_class=attrs.get('geometry_field_class', getattr(self, 'geometry_field_class', 'L.GeometryField')), field_store_class=attrs.get('field_store_class', getattr(self, 'field_store_class', 'L.FieldStore'))) return super(LeafletWidget, self).render(name, value, attrs)
def leaflet_js(plugins=None): """ :param only_plugins: :param exclude_plugins: :return: """ plugin_names = _get_plugin_names(plugins) with_forms = PLUGIN_FORMS in plugin_names or PLUGIN_ALL in plugin_names FORCE_IMAGE_PATH = app_settings.get('FORCE_IMAGE_PATH') template_options = hasattr(settings, 'TEMPLATES') \ and len(settings.TEMPLATES) \ and settings.TEMPLATES[0].get('OPTIONS', None) if template_options and 'debug' in template_options: debug = template_options['debug'] elif hasattr(settings, 'TEMPLATE_DEBUG'): debug = settings.TEMPLATE_DEBUG else: debug = False return { "DEBUG": debug, "SRID": str(SRID) if SRID else None, "PLUGINS_JS": _get_all_resources_for_plugins(plugin_names, 'js'), "with_forms": with_forms, "FORCE_IMAGE_PATH": FORCE_IMAGE_PATH }
def leaflet_js(plugins=None): """ :param only_plugins: :param exclude_plugins: :return: """ plugin_names = _get_plugin_names(plugins) with_forms = PLUGIN_FORMS in plugin_names or PLUGIN_ALL in plugin_names FORCE_IMAGE_PATH = app_settings.get('FORCE_IMAGE_PATH') if hasattr(settings, 'TEMPLATE_DEBUG'): debug = settings.TEMPLATE_DEBUG elif 'debug' in settings.TEMPLATES[0]['OPTIONS']: debug = settings.TEMPLATES[0]['OPTIONS']['debug'] else: debug = False return { "DEBUG": debug, "SRID": str(SRID) if SRID else None, "PLUGINS_JS": _get_all_resources_for_plugins(plugin_names, 'js'), "with_forms": with_forms, "FORCE_IMAGE_PATH": FORCE_IMAGE_PATH }
def leaflet_js(plugins=None): """ :param only_plugins: :param exclude_plugins: :return: """ plugin_names = _get_plugin_names(plugins) with_forms = PLUGIN_FORMS in plugin_names or PLUGIN_ALL in plugin_names FORCE_IMAGE_PATH = app_settings.get("FORCE_IMAGE_PATH") template_options = ( hasattr(settings, "TEMPLATES") and len(settings.TEMPLATES) and settings.TEMPLATES[0].get("OPTIONS", None) ) if template_options and "debug" in template_options: debug = template_options["debug"] elif hasattr(settings, "TEMPLATE_DEBUG"): debug = settings.TEMPLATE_DEBUG else: debug = False return { "DEBUG": debug, "SRID": str(SRID) if SRID else None, "PLUGINS_JS": _get_all_resources_for_plugins(plugin_names, "js"), "with_forms": with_forms, "FORCE_IMAGE_PATH": FORCE_IMAGE_PATH, }
def leaflet_map(name, callback=None, fitextent=True, creatediv=True, loadevent=app_settings.get('LOADEVENT'), settings_overrides={}): """ :param name: :param callback: :param fitextent: :param creatediv: :param loadevent: :param settings_overrides: :return: """ extent = None if SPATIAL_EXTENT is not None: # Leaflet uses [lat, lng] xmin, ymin, xmax, ymax = SPATIAL_EXTENT extent = (ymin, xmin, ymax, xmax) if settings_overrides == '': settings_overrides = {} app_settings.update(**settings_overrides) djoptions = dict( srid=SRID, extent=[extent[:2], extent[2:4]], fitextent=fitextent, center=app_settings['DEFAULT_CENTER'], zoom=app_settings['DEFAULT_ZOOM'], minzoom=app_settings['MIN_ZOOM'], maxzoom=app_settings['MAX_ZOOM'], layers=[(force_text(label), url, attrs) for (label, url, attrs) in app_settings.get('TILES')], overlays=[(force_text(label), url, attrs) for (label, url, attrs) in app_settings.get('OVERLAYS')], attributionprefix=force_text(app_settings.get('ATTRIBUTION_PREFIX'), strings_only=True), scale=app_settings.get('SCALE'), minimap=app_settings.get('MINIMAP'), resetview=app_settings.get('RESET_VIEW'), tilesextent=list(app_settings.get('TILES_EXTENT', [])) ) return { # templatetag options 'name': name, 'loadevents': json.dumps(loadevent.split(), cls=JSONLazyTranslationEncoder), 'creatediv': creatediv, 'callback': callback, # initialization options 'djoptions': json.dumps(djoptions, cls=JSONLazyTranslationEncoder), # settings 'NO_GLOBALS': app_settings.get('NO_GLOBALS'), }
def leaflet_map( name, callback=None, fitextent=True, creatediv=True, loadevent=app_settings.get("LOADEVENT"), settings_overrides={} ): """ :param name: :param callback: :param fitextent: :param creatediv: :param loadevent: :param settings_overrides: :return: """ if settings_overrides == "": settings_overrides = {} instance_app_settings = app_settings.copy() # Allow not overidding global app_settings instance_app_settings.update(**settings_overrides) extent = None if instance_app_settings["SPATIAL_EXTENT"] is not None: # Leaflet uses [lat, lng] xmin, ymin, xmax, ymax = instance_app_settings["SPATIAL_EXTENT"] bbox = (ymin, xmin, ymax, xmax) extent = [bbox[:2], bbox[2:4]] djoptions = dict( srid=SRID, extent=extent, fitextent=fitextent, center=instance_app_settings["DEFAULT_CENTER"], zoom=instance_app_settings["DEFAULT_ZOOM"], minzoom=instance_app_settings["MIN_ZOOM"], maxzoom=instance_app_settings["MAX_ZOOM"], layers=[(force_text(label), url, attrs) for (label, url, attrs) in instance_app_settings.get("TILES")], overlays=[(force_text(label), url, attrs) for (label, url, attrs) in instance_app_settings.get("OVERLAYS")], attributionprefix=force_text(instance_app_settings.get("ATTRIBUTION_PREFIX"), strings_only=True), scale=instance_app_settings.get("SCALE"), minimap=instance_app_settings.get("MINIMAP"), resetview=instance_app_settings.get("RESET_VIEW"), tilesextent=list(instance_app_settings.get("TILES_EXTENT", [])), ) return { # templatetag options "name": name, "loadevents": json.dumps(loadevent.split(), cls=JSONLazyTranslationEncoder), "creatediv": creatediv, "callback": callback, # initialization options "djoptions": json.dumps(djoptions, cls=JSONLazyTranslationEncoder), # settings "NO_GLOBALS": instance_app_settings.get("NO_GLOBALS"), }
def leaflet_map(name, callback=None, fitextent=True): if callback is None: callback = "%sInit" % name tilesurl = app_settings.get('TILES_URL') if tilesurl and isinstance(tilesurl, basestring): tilesurl = (('background', tilesurl),) extent = None if SPATIAL_EXTENT is not None: xmin, ymin, xmax, ymax = SPATIAL_EXTENT extent = (ymin, xmin, ymax, xmax) t = template.loader.get_template("leaflet/map_fragment.html") return t.render(Context(dict(name=name, srid=SRID, extent=list(extent), fitextent=fitextent, tilesurl=[list(url) for url in tilesurl], callback=callback, scale=app_settings.get('SCALE'), tilesextent=list(app_settings.get('TILES_EXTENT', [])), maxresolution=app_settings.get('MAX_RESOLUTION', 0))))
def leaflet_css(plugins=None): """ :param only_plugins: :param exclude_plugins: :return: """ plugin_names = _get_plugin_names(plugins) return { "MINIMAP": app_settings.get('MINIMAP'), "PLUGINS_CSS": _get_all_resources_for_plugins(plugin_names, 'css'), }
def leaflet_css(plugins=None): """ :param only_plugins: :param exclude_plugins: :return: """ plugin_names = _get_plugin_names(plugins) return { "MINIMAP": app_settings.get('MINIMAP'), "PLUGINS_CSS": _get_all_resources_for_plugins(plugin_names, 'css'), }
def leaflet_map(name, callback=None, fitextent=True): if callback is None: callback = "%sInit" % name tilesurl = app_settings.get('TILES_URL') if tilesurl and isinstance(tilesurl, basestring): tilesurl = (('background', tilesurl), ) extent = None if SPATIAL_EXTENT is not None: xmin, ymin, xmax, ymax = SPATIAL_EXTENT extent = (ymin, xmin, ymax, xmax) t = template.loader.get_template("leaflet/map_fragment.html") return t.render( Context( dict(name=name, srid=SRID, extent=list(extent), fitextent=fitextent, tilesurl=[list(url) for url in tilesurl], callback=callback, scale=app_settings.get('SCALE'), tilesextent=list(app_settings.get('TILES_EXTENT', [])), maxresolution=app_settings.get('MAX_RESOLUTION', 0))))
def leaflet_map(name, callback=None, fitextent=True, creatediv=True): """ :param name: :param callback: :param fitextent: :param creatediv: :return: """ if callback is None: callback = "%sInit" % name tilesurl = app_settings.get('TILES_URL') if tilesurl and isinstance(tilesurl, basestring): tilesurl = (('background', tilesurl), ) extent = None if SPATIAL_EXTENT is not None: xmin, ymin, xmax, ymax = SPATIAL_EXTENT extent = (ymin, xmin, ymax, xmax) t = template.loader.get_template("leaflet/map_fragment.html") return t.render( Context( dict( name=name, creatediv=creatediv, srid=SRID, extent=list(extent), center=app_settings['DEFAULT_CENTER'], zoom=app_settings['DEFAULT_ZOOM'], fitextent=fitextent, tilesurl=[list(url) for url in tilesurl], callback=callback, scale=app_settings.get('SCALE'), minimap=app_settings.get('MINIMAP'), tilesextent=list(app_settings.get('TILES_EXTENT', [])), )))
def leaflet_js(plugins=None): """ :param only_plugins: :param exclude_plugins: :return: """ plugin_names = _get_plugin_names(plugins) return { "DEBUG": settings.TEMPLATE_DEBUG, "SRID": SRID, "MINIMAP": app_settings.get('MINIMAP'), "PLUGINS_JS": _get_all_resources_for_plugins(plugin_names, 'js'), }
def leaflet_js(plugins=None): """ :param only_plugins: :param exclude_plugins: :return: """ plugin_names = _get_plugin_names(plugins) return { "DEBUG": settings.TEMPLATE_DEBUG, "SRID": SRID, "MINIMAP": app_settings.get('MINIMAP'), "PLUGINS_JS": _get_all_resources_for_plugins(plugin_names, 'js'), }
def leaflet_map(name, callback=None, fitextent=True, creatediv=True, loadevent="load", settings_overrides={}): """ :param name: :param callback: :param fitextent: :param creatediv: :return: """ extent = None if SPATIAL_EXTENT is not None: # Leaflet uses [lat, lng] xmin, ymin, xmax, ymax = SPATIAL_EXTENT extent = (ymin, xmin, ymax, xmax) if settings_overrides == "": settings_overrides = {} app_settings.update(**settings_overrides) djoptions = dict( srid=SRID, extent=[extent[:2], extent[2:4]], fitextent=fitextent, center=app_settings["DEFAULT_CENTER"], zoom=app_settings["DEFAULT_ZOOM"], minzoom=app_settings["MIN_ZOOM"], maxzoom=app_settings["MAX_ZOOM"], layers=[(force_text(label), url, attrs) for (label, url, attrs) in app_settings.get("TILES")], overlays=[(force_text(label), url, attrs) for (label, url, attrs) in app_settings.get("OVERLAYS")], attributionprefix=force_text(app_settings.get("ATTRIBUTION_PREFIX"), strings_only=True), scale=app_settings.get("SCALE"), minimap=app_settings.get("MINIMAP"), resetview=app_settings.get("RESET_VIEW"), tilesextent=list(app_settings.get("TILES_EXTENT", [])), ) return { # templatetag options "name": name, "loadevents": json.dumps(loadevent.split()), "creatediv": creatediv, "callback": callback, # initialization options "djoptions": json.dumps(djoptions), # settings "NO_GLOBALS": app_settings.get("NO_GLOBALS"), }
def leaflet_map(name, callback=None, fitextent=True, creatediv=True, loadevent='load'): """ :param name: :param callback: :param fitextent: :param creatediv: :return: """ extent = None if SPATIAL_EXTENT is not None: # Leaflet uses [lat, lng] xmin, ymin, xmax, ymax = SPATIAL_EXTENT extent = (ymin, xmin, ymax, xmax) djoptions = dict( srid=SRID, extent=[extent[:2], extent[2:4]], fitextent=fitextent, center=app_settings['DEFAULT_CENTER'], zoom=app_settings['DEFAULT_ZOOM'], layers=[(six.text_type(label), url, attrs) for (label, url, attrs) in app_settings.get('TILES')], overlays=[(six.text_type(label), url, attrs) for (label, url, attrs) in app_settings.get('OVERLAYS')], attributionprefix=app_settings.get('ATTRIBUTION_PREFIX'), scale=app_settings.get('SCALE'), minimap=app_settings.get('MINIMAP'), resetview=app_settings.get('RESET_VIEW'), tilesextent=list(app_settings.get('TILES_EXTENT', [])) ) if app_settings['MIN_ZOOM'] is not None: djoptions['minzoom'] = app_settings['MIN_ZOOM'] if app_settings['MAX_ZOOM'] is not None: djoptions['maxzoom'] = app_settings['MAX_ZOOM'] return { # templatetag options 'name': name, 'loadevents': json.dumps(loadevent.split()), 'creatediv': creatediv, 'callback': callback, # initialization options 'djoptions': json.dumps(djoptions), # settings 'NO_GLOBALS': app_settings.get('NO_GLOBALS'), }
def leaflet_js(plugins=None): """ :param only_plugins: :param exclude_plugins: :return: """ plugin_names = _get_plugin_names(plugins) with_forms = PLUGIN_FORMS in plugin_names or PLUGIN_ALL in plugin_names FORCE_IMAGE_PATH = app_settings.get('FORCE_IMAGE_PATH') return { "DEBUG": settings.TEMPLATE_DEBUG, "SRID": str(SRID) if SRID else None, "PLUGINS_JS": _get_all_resources_for_plugins(plugin_names, 'js'), "with_forms": with_forms, "FORCE_IMAGE_PATH": FORCE_IMAGE_PATH }
def leaflet_js(plugins=None): """ :param only_plugins: :param exclude_plugins: :return: """ plugin_names = _get_plugin_names(plugins) with_forms = PLUGIN_FORMS in plugin_names or PLUGIN_ALL in plugin_names force_image_path = app_settings.get('FORCE_IMAGE_PATH') return { "DEBUG": settings.TEMPLATE_DEBUG, "SRID": str(SRID) if SRID else None, "PLUGINS_JS": _get_all_resources_for_plugins(plugin_names, 'js'), "with_forms": with_forms, "FORCE_IMAGE_PATH": force_image_path }
def render(self, name, value, attrs=None): assert self.map_srid == 4326, 'Leaflet vectors should be decimal degrees.' value = None if value in validators.EMPTY_VALUES else value # Retrieve params from Field init (if any) self.geom_type = self.attrs.get('geom_type', self.geom_type) self.settings_overrides = self.attrs.get('settings_overrides', self.settings_overrides) # Setting 'loadevent' added in the widget constructor loadevent = self.attrs.get('loadevent', app_settings.get('LOADEVENT')) attrs = attrs or {} # In BaseGeometryWidget, geom_type is set using gdal, and fails with generic. # See https://code.djangoproject.com/ticket/21021 if self.geom_type == 'GEOMETRY': attrs['geom_type'] = 'Geometry' map_id = slugify(attrs.get('id', name)).replace('-', '_') # JS-safe attrs.update(id=map_id, module='geodjango_%s' % map_id, id_map=map_id + '_map', id_map_callback=map_id + '_map_callback', loadevent=loadevent, modifiable=self.modifiable, target_map=attrs.get('target_map', getattr(self, 'target_map', None)), settings_overrides=attrs.get( 'settings_overrides', getattr(self, 'settings_overrides', None)), geometry_field_class=attrs.get( 'geometry_field_class', getattr(self, 'geometry_field_class', 'L.GeometryField')), field_store_class=attrs.get( 'field_store_class', getattr(self, 'field_store_class', 'L.FieldStore'))) return super(LeafletWidget, self).render(name, value, attrs)
def base_url(): version = app_settings.get('LEAFLET_VERSION') paths = (settings.STATIC_URL, "leaflet") if version: paths += (version, ) return os.path.join(*paths)
def leaflet_js(): t = template.loader.get_template("leaflet/head_fragment.html") return t.render(Context(dict(debug=settings.TEMPLATE_DEBUG, version=app_settings.get('LEAFLET_VERSION'), srid=SRID)))
def base_url(): version = app_settings.get('LEAFLET_VERSION') paths = (settings.STATIC_URL, "leaflet") if version: paths += (version,) return os.path.join(*paths)
def leaflet_js(): return { "DEBUG": settings.TEMPLATE_DEBUG, "SRID": SRID, "MINIMAP": app_settings.get('MINIMAP'), }
def leaflet_css(): return { "MINIMAP": app_settings.get('MINIMAP'), }
def leaflet_map(name, callback=None, fitextent=True, creatediv=True, loadevent=app_settings.get('LOADEVENT'), settings_overrides={}): """ :param name: :param callback: :param fitextent: :param creatediv: :param loadevent: :param settings_overrides: :return: """ if settings_overrides == '': settings_overrides = {} instance_app_settings = app_settings.copy( ) # Allow not overidding global app_settings instance_app_settings.update(**settings_overrides) extent = None if instance_app_settings['SPATIAL_EXTENT'] is not None: # Leaflet uses [lat, lng] xmin, ymin, xmax, ymax = instance_app_settings['SPATIAL_EXTENT'] bbox = (ymin, xmin, ymax, xmax) extent = [bbox[:2], bbox[2:4]] djoptions = dict( srid=SRID, extent=extent, fitextent=fitextent, center=instance_app_settings['DEFAULT_CENTER'], zoom=instance_app_settings['DEFAULT_ZOOM'], precision=instance_app_settings['DEFAULT_PRECISION'], minzoom=instance_app_settings['MIN_ZOOM'], maxzoom=instance_app_settings['MAX_ZOOM'], layers=[(force_str(label), url, attrs) for (label, url, attrs) in instance_app_settings.get('TILES')], overlays=[(force_str(label), url, attrs) for (label, url, attrs) in instance_app_settings.get('OVERLAYS')], attributionprefix=force_str( instance_app_settings.get('ATTRIBUTION_PREFIX'), strings_only=True), scale=instance_app_settings.get('SCALE'), minimap=instance_app_settings.get('MINIMAP'), resetview=instance_app_settings.get('RESET_VIEW'), tilesextent=list(instance_app_settings.get('TILES_EXTENT', []))) return { # templatetag options 'name': name, 'loadevents': json.dumps(loadevent.split(), cls=DjangoJSONEncoder), 'creatediv': creatediv, 'callback': callback, # initialization options 'djoptions': json.dumps(djoptions, cls=DjangoJSONEncoder), # settings 'NO_GLOBALS': instance_app_settings.get('NO_GLOBALS'), }