Skip to content

Commit

Permalink
Revert "Add return values for selected layers in LayersControl (#217)"
Browse files Browse the repository at this point in the history
This reverts commit 0b2a92f.
  • Loading branch information
randyzwitch authored Sep 28, 2024
1 parent 0b2a92f commit 5fe640c
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 146 deletions.
90 changes: 0 additions & 90 deletions examples/pages/layer_control.py

This file was deleted.

2 changes: 0 additions & 2 deletions streamlit_folium/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
# the component, and True when we're ready to package and distribute it.
_RELEASE = True


if not _RELEASE:
_component_func = components.declare_component(
"st_folium", url="http://localhost:3001"
Expand Down Expand Up @@ -330,7 +329,6 @@ def bounds_to_dict(bounds_list: list[list[float]]) -> dict[str, dict[str, float]
else {},
"last_circle_radius": None,
"last_circle_polygon": None,
"selected_layers": None,
}

# If the user passes a custom list of returned objects, we'll only return those
Expand Down
58 changes: 4 additions & 54 deletions streamlit_folium/frontend/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ type GlobalData = {
last_center: any
last_feature_group: any
last_layer_control: any
selected_layers: Record<string, { name: string; url: string }>
}

declare global {
Expand Down Expand Up @@ -58,7 +57,6 @@ function updateComponentValue(map: any) {
last_circle_radius: global_data.last_circle_radius,
last_circle_polygon: global_data.last_circle_polygon,
center: map.getCenter(),
selected_layers: Object.values(global_data.selected_layers)
}

let to_return = global_data.returned_objects
Expand Down Expand Up @@ -113,43 +111,6 @@ function onDraw(e: any) {
return onLayerClick(e)
}

function removeLayer(e: any) {
const global_data = window.__GLOBAL_DATA__
let layer = e.layer

if (layer && layer["_url"] && layer["wmsParams"] && layer["wmsParams"]["layers"]) {
const layerName = layer["wmsParams"]["layers"];
const layerUrl = layer["_url"];

const layerKey = `${layerUrl},${layerName}`;

// Remove the layer object if it exists
if (global_data.selected_layers[layerKey]) {
delete global_data.selected_layers[layerKey];
}
}

debouncedUpdateComponentValue(window.map)
}

function addLayer(e: any) {
const global_data = window.__GLOBAL_DATA__
let layer = e.layer

if (layer && layer["_url"] && layer["wmsParams"] && layer["wmsParams"]["layers"]) {
const layerName = layer["wmsParams"]["layers"];
const layerUrl = layer["_url"];

const layerKey = `${layerUrl},${layerName}`;

if (!global_data.selected_layers[layerKey]) {
global_data.selected_layers[layerKey] = { name: layerName, url: layerUrl };
}
}

debouncedUpdateComponentValue(window.map)
}

function onLayerClick(e: any) {
const global_data = window.__GLOBAL_DATA__
global_data.last_object_clicked = e.latlng
Expand Down Expand Up @@ -206,30 +167,19 @@ function getPixelatedStyles(pixelated: boolean) {
}

window.initComponent = (map: any, return_on_hover: boolean) => {
const global_data = window.__GLOBAL_DATA__
map.on("click", onMapClick)
map.on("moveend", onMapMove)
for (let key in map._layers) {
let layer = map._layers[key]
if (layer && layer["_url"] && layer["wmsParams"] && layer["wmsParams"]["layers"]) {
const layerName = layer["wmsParams"]["layers"];
const layerUrl = layer["_url"];

const layerKey = `${layerUrl},${layerName}`;

if (!global_data.selected_layers[layerKey]) {
global_data.selected_layers[layerKey] = { name: layerName, url: layerUrl };
}
layer.on("click", onLayerClick)
if (return_on_hover) {
layer.on("mouseover", onLayerClick)
}
}
map.on("draw:created", onDraw)
map.on("draw:edited", onDraw)
map.on("draw:deleted", onDraw)

// Adding functionality for tracking layer changes
map.on("overlayadd", addLayer);
map.on("overlayremove", removeLayer);

Streamlit.setFrameHeight()
updateComponentValue(map)
}
Expand Down Expand Up @@ -278,6 +228,7 @@ async function onRender(event: Event) {
linkTag.href = link
window.document.head.appendChild(linkTag)
})

const style = document.createElement("style")
style.innerHTML = getPixelatedStyles(pixelated)
window.document.head.appendChild(style)
Expand Down Expand Up @@ -388,7 +339,6 @@ async function onRender(event: Event) {
last_center: null,
last_feature_group: null,
last_layer_control: null,
selected_layers: {}
}
if (script.indexOf("map_div2") !== -1) {
parent_div?.classList.remove("single")
Expand Down

0 comments on commit 5fe640c

Please sign in to comment.