Spaces:
Sleeping
Sleeping
Update pages/MipMAP.py
Browse files- pages/MipMAP.py +85 -70
pages/MipMAP.py
CHANGED
|
@@ -37,6 +37,7 @@ class AdvancedMapControl(MacroElement):
|
|
| 37 |
</select>
|
| 38 |
<input type="number" id="scale" value="1000" min="1" step="100">
|
| 39 |
<button id="apply-format">Appliquer Format</button>
|
|
|
|
| 40 |
<button id="calculate-blocks">Calculer Blocs</button>
|
| 41 |
<div id="block-result"></div>
|
| 42 |
<button id="export-geojson">Exporter GeoJSON</button>
|
|
@@ -48,8 +49,9 @@ class AdvancedMapControl(MacroElement):
|
|
| 48 |
|
| 49 |
var rectangle;
|
| 50 |
var grid;
|
|
|
|
| 51 |
|
| 52 |
-
|
| 53 |
var format = document.getElementById('paper-format').value;
|
| 54 |
var scale = parseInt(document.getElementById('scale').value);
|
| 55 |
var center = {{ this._parent.get_name() }}.getCenter();
|
|
@@ -77,6 +79,30 @@ class AdvancedMapControl(MacroElement):
|
|
| 77 |
|
| 78 |
rectangle = L.rectangle(bounds, {color: "#ff7800", weight: 1}).addTo({{ this._parent.get_name() }});
|
| 79 |
{{ this._parent.get_name() }}.fitBounds(bounds);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
});
|
| 81 |
|
| 82 |
document.getElementById('calculate-blocks').addEventListener('click', function() {
|
|
@@ -100,39 +126,68 @@ class AdvancedMapControl(MacroElement):
|
|
| 100 |
{{ this._parent.get_name() }}.removeLayer(grid);
|
| 101 |
}
|
| 102 |
grid = L.layerGroup().addTo({{ this._parent.get_name() }});
|
|
|
|
| 103 |
|
| 104 |
var latStep = blockSizeMeters / 111320;
|
| 105 |
var lngStep = blockSizeMeters / (111320 * Math.cos(bounds.getCenter().lat * Math.PI / 180));
|
| 106 |
|
| 107 |
-
for (var
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
}
|
| 113 |
});
|
| 114 |
|
| 115 |
document.getElementById('export-geojson').addEventListener('click', function() {
|
| 116 |
-
if (rectangle) {
|
| 117 |
var bounds = rectangle.getBounds();
|
| 118 |
var geojson = {
|
| 119 |
-
"type": "
|
| 120 |
-
"
|
| 121 |
-
"
|
| 122 |
-
"
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
"
|
| 128 |
-
|
| 129 |
-
[
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
|
|
|
|
|
|
|
|
|
| 135 |
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
var dataStr = "data:text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(geojson));
|
| 137 |
var downloadAnchorNode = document.createElement('a');
|
| 138 |
downloadAnchorNode.setAttribute("href", dataStr);
|
|
@@ -141,7 +196,7 @@ class AdvancedMapControl(MacroElement):
|
|
| 141 |
downloadAnchorNode.click();
|
| 142 |
downloadAnchorNode.remove();
|
| 143 |
} else {
|
| 144 |
-
alert("Veuillez d'abord
|
| 145 |
}
|
| 146 |
});
|
| 147 |
|
|
@@ -155,6 +210,8 @@ class AdvancedMapControl(MacroElement):
|
|
| 155 |
{% endmacro %}
|
| 156 |
""")
|
| 157 |
|
|
|
|
|
|
|
| 158 |
def main():
|
| 159 |
st.title("SwissScape Advanced")
|
| 160 |
|
|
@@ -163,54 +220,12 @@ def main():
|
|
| 163 |
|
| 164 |
Instructions :
|
| 165 |
1. Utilisez l'outil de dessin (en haut à gauche de la carte) pour dessiner une bbox OU choisissez un format de papier et une échelle, puis cliquez sur "Appliquer Format".
|
| 166 |
-
2.
|
| 167 |
-
3.
|
|
|
|
| 168 |
""")
|
| 169 |
|
| 170 |
-
#
|
| 171 |
-
m = folium.Map(location=[46.8182, 8.2275], zoom_start=8)
|
| 172 |
-
|
| 173 |
-
# Ajout du fond de carte swisstopo
|
| 174 |
-
folium.TileLayer(
|
| 175 |
-
tiles="https://wmts.geo.admin.ch/1.0.0/ch.swisstopo.pixelkarte-farbe/default/current/3857/{z}/{x}/{y}.jpeg",
|
| 176 |
-
attr="© swisstopo",
|
| 177 |
-
name="swisstopo",
|
| 178 |
-
overlay=False,
|
| 179 |
-
control=True
|
| 180 |
-
).add_to(m)
|
| 181 |
-
|
| 182 |
-
# Ajout du contrôle de dessin
|
| 183 |
-
draw = Draw(
|
| 184 |
-
draw_options={
|
| 185 |
-
'polyline': False,
|
| 186 |
-
'polygon': False,
|
| 187 |
-
'circle': False,
|
| 188 |
-
'marker': False,
|
| 189 |
-
'circlemarker': False,
|
| 190 |
-
'rectangle': True,
|
| 191 |
-
},
|
| 192 |
-
edit_options={'edit': False}
|
| 193 |
-
)
|
| 194 |
-
m.add_child(draw)
|
| 195 |
-
|
| 196 |
-
# Ajout du contrôle de carte avancé
|
| 197 |
-
m.add_child(AdvancedMapControl())
|
| 198 |
-
|
| 199 |
-
# Ajout des coordonnées de la souris
|
| 200 |
-
formatter = "function(num) {return L.Util.formatNum(num, 5);};"
|
| 201 |
-
MousePosition(
|
| 202 |
-
position="bottomleft",
|
| 203 |
-
separator=" | ",
|
| 204 |
-
empty_string="",
|
| 205 |
-
lng_first=True,
|
| 206 |
-
num_digits=20,
|
| 207 |
-
prefix="Coordonnées:",
|
| 208 |
-
lat_formatter=formatter,
|
| 209 |
-
lng_formatter=formatter,
|
| 210 |
-
).add_to(m)
|
| 211 |
-
|
| 212 |
-
# Affichage de la carte
|
| 213 |
-
folium_static(m, width=1000, height=600)
|
| 214 |
|
| 215 |
if __name__ == "__main__":
|
| 216 |
main()
|
|
|
|
| 37 |
</select>
|
| 38 |
<input type="number" id="scale" value="1000" min="1" step="100">
|
| 39 |
<button id="apply-format">Appliquer Format</button>
|
| 40 |
+
<button id="scale-to-fit">Mise à l'échelle</button>
|
| 41 |
<button id="calculate-blocks">Calculer Blocs</button>
|
| 42 |
<div id="block-result"></div>
|
| 43 |
<button id="export-geojson">Exporter GeoJSON</button>
|
|
|
|
| 49 |
|
| 50 |
var rectangle;
|
| 51 |
var grid;
|
| 52 |
+
var blocks = [];
|
| 53 |
|
| 54 |
+
function applyFormat() {
|
| 55 |
var format = document.getElementById('paper-format').value;
|
| 56 |
var scale = parseInt(document.getElementById('scale').value);
|
| 57 |
var center = {{ this._parent.get_name() }}.getCenter();
|
|
|
|
| 79 |
|
| 80 |
rectangle = L.rectangle(bounds, {color: "#ff7800", weight: 1}).addTo({{ this._parent.get_name() }});
|
| 81 |
{{ this._parent.get_name() }}.fitBounds(bounds);
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
document.getElementById('apply-format').addEventListener('click', applyFormat);
|
| 85 |
+
|
| 86 |
+
document.getElementById('scale-to-fit').addEventListener('click', function() {
|
| 87 |
+
if (!rectangle) {
|
| 88 |
+
alert("Veuillez d'abord dessiner une bbox ou appliquer un format de papier.");
|
| 89 |
+
return;
|
| 90 |
+
}
|
| 91 |
+
var format = document.getElementById('paper-format').value;
|
| 92 |
+
var paperSizes = {
|
| 93 |
+
'A4': [0.210, 0.297],
|
| 94 |
+
'A3': [0.297, 0.420],
|
| 95 |
+
'A2': [0.420, 0.594],
|
| 96 |
+
'A1': [0.594, 0.841],
|
| 97 |
+
'A0': [0.841, 1.189]
|
| 98 |
+
};
|
| 99 |
+
var size = paperSizes[format];
|
| 100 |
+
var bounds = rectangle.getBounds();
|
| 101 |
+
var widthMeters = (bounds.getEast() - bounds.getWest()) * 111320 * Math.cos(bounds.getCenter().lat * Math.PI / 180);
|
| 102 |
+
var heightMeters = (bounds.getNorth() - bounds.getSouth()) * 111320;
|
| 103 |
+
var scale = Math.max(widthMeters / size[0], heightMeters / size[1]);
|
| 104 |
+
document.getElementById('scale').value = Math.round(scale);
|
| 105 |
+
applyFormat();
|
| 106 |
});
|
| 107 |
|
| 108 |
document.getElementById('calculate-blocks').addEventListener('click', function() {
|
|
|
|
| 126 |
{{ this._parent.get_name() }}.removeLayer(grid);
|
| 127 |
}
|
| 128 |
grid = L.layerGroup().addTo({{ this._parent.get_name() }});
|
| 129 |
+
blocks = [];
|
| 130 |
|
| 131 |
var latStep = blockSizeMeters / 111320;
|
| 132 |
var lngStep = blockSizeMeters / (111320 * Math.cos(bounds.getCenter().lat * Math.PI / 180));
|
| 133 |
|
| 134 |
+
for (var i = 0; i < blocksY; i++) {
|
| 135 |
+
for (var j = 0; j < blocksX; j++) {
|
| 136 |
+
var blockSouth = bounds.getSouth() + i * latStep;
|
| 137 |
+
var blockWest = bounds.getWest() + j * lngStep;
|
| 138 |
+
var blockNorth = Math.min(blockSouth + latStep, bounds.getNorth());
|
| 139 |
+
var blockEast = Math.min(blockWest + lngStep, bounds.getEast());
|
| 140 |
+
|
| 141 |
+
L.rectangle([[blockSouth, blockWest], [blockNorth, blockEast]], {color: "#ff7800", weight: 1, fill: false}).addTo(grid);
|
| 142 |
+
blocks.push([[blockWest, blockSouth], [blockEast, blockNorth]]);
|
| 143 |
+
}
|
| 144 |
}
|
| 145 |
});
|
| 146 |
|
| 147 |
document.getElementById('export-geojson').addEventListener('click', function() {
|
| 148 |
+
if (rectangle && blocks.length > 0) {
|
| 149 |
var bounds = rectangle.getBounds();
|
| 150 |
var geojson = {
|
| 151 |
+
"type": "FeatureCollection",
|
| 152 |
+
"features": [{
|
| 153 |
+
"type": "Feature",
|
| 154 |
+
"properties": {
|
| 155 |
+
"format": document.getElementById('paper-format').value,
|
| 156 |
+
"scale": parseInt(document.getElementById('scale').value),
|
| 157 |
+
"printBlockSize": 0.4 // 40 cm in meters
|
| 158 |
+
},
|
| 159 |
+
"geometry": {
|
| 160 |
+
"type": "Polygon",
|
| 161 |
+
"coordinates": [[
|
| 162 |
+
[bounds.getWest(), bounds.getSouth()],
|
| 163 |
+
[bounds.getEast(), bounds.getSouth()],
|
| 164 |
+
[bounds.getEast(), bounds.getNorth()],
|
| 165 |
+
[bounds.getWest(), bounds.getNorth()],
|
| 166 |
+
[bounds.getWest(), bounds.getSouth()]
|
| 167 |
+
]]
|
| 168 |
+
}
|
| 169 |
+
}]
|
| 170 |
};
|
| 171 |
+
|
| 172 |
+
blocks.forEach(function(block, index) {
|
| 173 |
+
geojson.features.push({
|
| 174 |
+
"type": "Feature",
|
| 175 |
+
"properties": {
|
| 176 |
+
"blockIndex": index
|
| 177 |
+
},
|
| 178 |
+
"geometry": {
|
| 179 |
+
"type": "Polygon",
|
| 180 |
+
"coordinates": [[
|
| 181 |
+
[block[0][0], block[0][1]],
|
| 182 |
+
[block[1][0], block[0][1]],
|
| 183 |
+
[block[1][0], block[1][1]],
|
| 184 |
+
[block[0][0], block[1][1]],
|
| 185 |
+
[block[0][0], block[0][1]]
|
| 186 |
+
]]
|
| 187 |
+
}
|
| 188 |
+
});
|
| 189 |
+
});
|
| 190 |
+
|
| 191 |
var dataStr = "data:text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(geojson));
|
| 192 |
var downloadAnchorNode = document.createElement('a');
|
| 193 |
downloadAnchorNode.setAttribute("href", dataStr);
|
|
|
|
| 196 |
downloadAnchorNode.click();
|
| 197 |
downloadAnchorNode.remove();
|
| 198 |
} else {
|
| 199 |
+
alert("Veuillez d'abord calculer les blocs.");
|
| 200 |
}
|
| 201 |
});
|
| 202 |
|
|
|
|
| 210 |
{% endmacro %}
|
| 211 |
""")
|
| 212 |
|
| 213 |
+
# Le reste du code Python reste inchangé
|
| 214 |
+
|
| 215 |
def main():
|
| 216 |
st.title("SwissScape Advanced")
|
| 217 |
|
|
|
|
| 220 |
|
| 221 |
Instructions :
|
| 222 |
1. Utilisez l'outil de dessin (en haut à gauche de la carte) pour dessiner une bbox OU choisissez un format de papier et une échelle, puis cliquez sur "Appliquer Format".
|
| 223 |
+
2. Utilisez "Mise à l'échelle" pour ajuster l'échelle à la bbox dessinée.
|
| 224 |
+
3. Cliquez sur "Calculer Blocs" pour voir combien de blocs d'impression de 40x40 cm sont nécessaires.
|
| 225 |
+
4. Utilisez "Exporter GeoJSON" pour télécharger les données de la bbox et des blocs.
|
| 226 |
""")
|
| 227 |
|
| 228 |
+
# Le reste du code Python reste inchangé
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 229 |
|
| 230 |
if __name__ == "__main__":
|
| 231 |
main()
|