ikoojoshi / Folium-GroupedLayerControl

A layer control for folium based on leaflet-groupedlayercontrol by ismyrnow.
5 stars 3 forks source link

Grouping Google Earth Engine (GEE) & Folium layers? #2

Open IndigoWizard opened 2 years ago

IndigoWizard commented 2 years ago

Is there a way to only have check-boxes? Multiple groups of check-boxes?

My use case:

I have multiple layers that I'd like to separate into two categories, "Vector layers" and "Raster layers". And I need them all to be activated as checkbox by default, I don't need radio.

As you can see in the screenshot bellow, layers are listed as follows:

image

Here's the project repo, the develop branch is the one ahead: https://github.com/IndigoWizard/mega-port-environment/tree/develop I need to split them to 3 categories: Basemaps | Vector layers, | Raster layers but it doesn't seem to work The google earth engine layers don't seem to be compatible with this maybe or I'm not doing it right, any chance I get some help with it? Error i get: m.add_ee_layer(image_satellite, image_params, 'Sentinel-2 True Colors').add_to(raster_layers) AttributeError: 'NoneType' object has no attribute 'add_to'

IndigoWizard commented 2 years ago

So I tried but it seems the earth engine layers can't be added for some reason so I only added the vector layers (those based as GeoJson features ) and still have the following issue:

The video shows that all layers are still active/drawn on the map even though all boxes in layer panel are unchecked except the last one

https://user-images.githubusercontent.com/43890965/194719319-990ceef5-e507-498b-91cf-b1270a5086c1.mp4

here's the code sample:

# ##### Waterways
waterways_style_function = lambda x: {
  'fillColor' : '#75cff0',
  'color' :  '#75cff0',
  'fillOpacity' : 0.50,
  'opacity' : 0.50,
  'weight' : 2,
}

waterways_highlight_function = lambda x: {
  'fillColor': '#75cff0', 
  'color': '#75cff0', 
  'fillOpacity': 0.80,
  'opacity' : 0.9,
  'weight': 4,
}

WATERWAYS_INFO = folium.features.GeoJson(
  waterways,
  name = 'Waterways',
  control = True,
  style_function = waterways_style_function, 
  highlight_function = waterways_highlight_function,
  tooltip=folium.features.GeoJsonTooltip(
    fields=['name', 'type'],
    aliases=['Name: ', 'Type: '],
    style=("background-color: white; color: #333333; font-family: arial; font-size: 12px; padding: 10px;") 
  )
)
m.add_child(WATERWAYS_INFO)

###### all following layers are structured as the previous one (WATERWAYS_INFO)
###### it's just to show what the geojson based vector layer i created look like

WILAYA_ADMIN_INFO.add_to(vector_layers)
MUNICIPALITIES_ADMIN_INFO.add_to(vector_layers)
LOGISTIC_ZONES_INFO.add_to(vector_layers)
PORT_INFRASTRUCTURE_INFO.add_to(vector_layers)
CONSTRUCTION_ZONES_INFO.add_to(vector_layers)
ROADS_INFO.add_to(vector_layers)
FORESTS_AFFECTED_INFO.add_to(vector_layers)
FORESTS_PRESERVED_INFO.add_to(vector_layers)
AGRO_FARM_LAND_INFO.add_to(vector_layers)
WATERWAYS_INFO.add_to(vector_layers)

GroupedLayerControl({}, {
  'Vector Layers': {
    'WILAYA_ADMIN_INFO': vector_layers,
    'MUNICIPALITIES_ADMIN_INFO': vector_layers,
    'LOGISTIC_ZONES_INFO': vector_layers,
    'PORT_INFRASTRUCTURE_INFO': vector_layers,
    'CONSTRUCTION_ZONES_INFO': vector_layers,
    'ROADS_INFO': vector_layers,
    'FORESTS_AFFECTED_INFO': vector_layers,
    'FORESTS_PRESERVED_INFO': vector_layers,
    'AGRO_FARM_LAND_INFO': vector_layers,
    'WATERWAYS_INFO': vector_layers
    },
  # 'Raster Layers' : { # I commented this part because Google Earth Engine  layers don't work
  #   'Sentinel-2 True Colors' : raster_layers,
  #   'Hillshade' : raster_layers,
  #   'Elevation' : raster_layers,
  #   'Slopes' : raster_layers,
  #   'EVI' : raster_layers,
  #   'NDMI - Classified' : raster_layers,
  #   'NDVI' : raster_layers,
  #   'NDVI - Classified' : raster_layers,
  #   'NDBI' : raster_layers,
  #   'NDWI' : raster_layers,
  #   'Contour lines' : raster_layers
  #   },
  },
  ['None'] # I had to change it to whatever ("none" here) to not have the layers as radio buttons
  ).add_to(m)