@@ -354,6 +354,8 @@ class GeoJson(Layer):
354354 embed: bool, default True
355355 Whether to embed the data in the html file or not. Note that disabling
356356 embedding is only supported if you provide a file link or URL.
357+ zoom_on_click: bool, default False
358+ Set to True to enable zooming in on a geometry when clicking on it.
357359
358360 Examples
359361 --------
@@ -409,9 +411,13 @@ class GeoJson(Layer):
409411 e.target.setStyle({{ this.get_name() }}_highlighter(e.target.feature));
410412 },
411413 {%- endif %}
414+ {%- if this.zoom_on_click %}
412415 click: function(e) {
413- {{ this.parent_map.get_name() }}.fitBounds(e.target.getBounds());
416+ if (typeof e.target.getBounds === 'function') {
417+ {{ this.parent_map.get_name() }}.fitBounds(e.target.getBounds());
418+ }
414419 }
420+ {%- endif %}
415421 });
416422 };
417423 var {{ this.get_name() }} = L.geoJson(null, {
@@ -438,7 +444,8 @@ class GeoJson(Layer):
438444
439445 def __init__ (self , data , style_function = None , highlight_function = None , # noqa
440446 name = None , overlay = True , control = True , show = True ,
441- smooth_factor = None , tooltip = None , embed = True , popup = None ):
447+ smooth_factor = None , tooltip = None , embed = True , popup = None ,
448+ zoom_on_click = False ):
442449 super (GeoJson , self ).__init__ (name = name , overlay = overlay ,
443450 control = control , show = show )
444451 self ._name = 'GeoJson'
@@ -449,6 +456,7 @@ def __init__(self, data, style_function=None, highlight_function=None, # noqa
449456 self .smooth_factor = smooth_factor
450457 self .style = style_function is not None
451458 self .highlight = highlight_function is not None
459+ self .zoom_on_click = zoom_on_click
452460
453461 self .data = self .process_data (data )
454462
0 commit comments