@@ -354,6 +354,8 @@ class GeoJson(Layer):
354
354
embed: bool, default True
355
355
Whether to embed the data in the html file or not. Note that disabling
356
356
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.
357
359
358
360
Examples
359
361
--------
@@ -409,9 +411,13 @@ class GeoJson(Layer):
409
411
e.target.setStyle({{ this.get_name() }}_highlighter(e.target.feature));
410
412
},
411
413
{%- endif %}
414
+ {%- if this.zoom_on_click %}
412
415
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
+ }
414
419
}
420
+ {%- endif %}
415
421
});
416
422
};
417
423
var {{ this.get_name() }} = L.geoJson(null, {
@@ -438,7 +444,8 @@ class GeoJson(Layer):
438
444
439
445
def __init__ (self , data , style_function = None , highlight_function = None , # noqa
440
446
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 ):
442
449
super (GeoJson , self ).__init__ (name = name , overlay = overlay ,
443
450
control = control , show = show )
444
451
self ._name = 'GeoJson'
@@ -449,6 +456,7 @@ def __init__(self, data, style_function=None, highlight_function=None, # noqa
449
456
self .smooth_factor = smooth_factor
450
457
self .style = style_function is not None
451
458
self .highlight = highlight_function is not None
459
+ self .zoom_on_click = zoom_on_click
452
460
453
461
self .data = self .process_data (data )
454
462
0 commit comments