2828 parse_options ,
2929 camelize
3030)
31- from folium .vector_layers import PolyLine , path_options
31+ from folium .vector_layers import Circle , CircleMarker , PolyLine , path_options
3232
3333from jinja2 import Template
3434
@@ -346,6 +346,12 @@ class GeoJson(Layer):
346346 tooltip: GeoJsonTooltip, Tooltip or str, default None
347347 Display a text when hovering over the object. Can utilize the data,
348348 see folium.GeoJsonTooltip for info on how to do that.
349+ popup: GeoJsonPopup, optional
350+ Show a different popup for each feature by passing a GeoJsonPopup object.
351+ marker: Circle, CircleMarker or Marker, optional
352+ If your data contains Point geometry, you can format the markers by passing a Cirle,
353+ CircleMarker or Marker object with your wanted options. The `style_function` and
354+ `highlight_function` will also target the marker object you passed.
349355 embed: bool, default True
350356 Whether to embed the data in the html file or not. Note that disabling
351357 embedding is only supported if you provide a file link or URL.
@@ -396,21 +402,48 @@ class GeoJson(Layer):
396402 }
397403 }
398404 {%- endif %}
405+
406+ {%- if this.marker %}
407+ function {{ this.get_name() }}_pointToLayer(feature, latlng) {
408+ var opts = {{ this.marker.options | tojson | safe }};
409+ {% if this.marker._name == 'Marker' and this.marker.icon %}
410+ const iconOptions = {{ this.marker.icon.options | tojson | safe }}
411+ const iconRootAlias = L{%- if this.marker.icon._name == "Icon" %}.AwesomeMarkers{%- endif %}
412+ opts.icon = new iconRootAlias.{{ this.marker.icon._name }}(iconOptions)
413+ {% endif %}
414+ {%- if this.style_function %}
415+ let style = {{ this.get_name()}}_styler(feature)
416+ Object.assign({%- if this.marker.icon -%}opts.icon.options{%- else -%} opts {%- endif -%}, style)
417+ {% endif %}
418+ return new L.{{this.marker._name}}(latlng, opts)
419+ }
420+ {%- endif %}
421+
399422 function {{this.get_name()}}_onEachFeature(feature, layer) {
400423 layer.on({
401424 {%- if this.highlight %}
402425 mouseout: function(e) {
403- {{ this.get_name() }}.resetStyle(e.target);
426+ if(typeof e.target.setStyle === "function"){
427+ {{ this.get_name() }}.resetStyle(e.target);
428+ }
404429 },
405430 mouseover: function(e) {
406- e.target.setStyle({{ this.get_name() }}_highlighter(e.target.feature));
431+ if(typeof e.target.setStyle === "function"){
432+ const highlightStyle = {{ this.get_name() }}_highlighter(e.target.feature)
433+ e.target.setStyle(highlightStyle);
434+ }
407435 },
408436 {%- endif %}
409437 {%- if this.zoom_on_click %}
410438 click: function(e) {
411439 if (typeof e.target.getBounds === 'function') {
412440 {{ this.parent_map.get_name() }}.fitBounds(e.target.getBounds());
413441 }
442+ else if (typeof e.target.getLatLng === 'function'){
443+ let zoom = {{ this.parent_map.get_name() }}.getZoom()
444+ zoom = zoom > 12 ? zoom : zoom + 1
445+ {{ this.parent_map.get_name() }}.flyTo(e.target.getLatLng(), zoom)
446+ }
414447 }
415448 {%- endif %}
416449 });
@@ -423,6 +456,9 @@ class GeoJson(Layer):
423456 {% if this.style %}
424457 style: {{ this.get_name() }}_styler,
425458 {%- endif %}
459+ {%- if this.marker %}
460+ pointToLayer: {{ this.get_name() }}_pointToLayer
461+ {%- endif %}
426462 });
427463
428464 function {{ this.get_name() }}_add (data) {
@@ -443,7 +479,7 @@ class GeoJson(Layer):
443479 def __init__ (self , data , style_function = None , highlight_function = None , # noqa
444480 name = None , overlay = True , control = True , show = True ,
445481 smooth_factor = None , tooltip = None , embed = True , popup = None ,
446- zoom_on_click = False ):
482+ zoom_on_click = False , marker = None ):
447483 super (GeoJson , self ).__init__ (name = name , overlay = overlay ,
448484 control = control , show = show )
449485 self ._name = 'GeoJson'
@@ -455,6 +491,10 @@ def __init__(self, data, style_function=None, highlight_function=None, # noqa
455491 self .style = style_function is not None
456492 self .highlight = highlight_function is not None
457493 self .zoom_on_click = zoom_on_click
494+ if marker :
495+ if not isinstance (marker , (Circle , CircleMarker , Marker )):
496+ raise TypeError ("Only Marker, Circle, and CircleMarker are supported as GeoJson marker types." )
497+ self .marker = marker
458498
459499 self .data = self .process_data (data )
460500
0 commit comments