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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
</html>
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
<html>
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="utf-8">
|
| 5 |
+
<title>DVF - Prix Immobiliers en France</title>
|
| 6 |
+
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
|
| 7 |
+
<link href="https://api.mapbox.com/mapbox-gl-js/v3.3.0/mapbox-gl.css" rel="stylesheet">
|
| 8 |
+
<script src="https://api.mapbox.com/mapbox-gl-js/v3.3.0/mapbox-gl.js"></script>
|
| 9 |
+
<script src="https://unpkg.com/pmtiles@3.0.3/dist/pmtiles.js"></script>
|
| 10 |
+
<style>
|
| 11 |
+
body { margin: 0; padding: 0; }
|
| 12 |
+
#map { position: absolute; top: 0; bottom: 0; width: 100%; }
|
| 13 |
+
|
| 14 |
+
.map-overlay {
|
| 15 |
+
position: absolute;
|
| 16 |
+
background: rgba(255, 255, 255, 0.95);
|
| 17 |
+
border-radius: 8px;
|
| 18 |
+
padding: 15px;
|
| 19 |
+
box-shadow: 0 2px 10px rgba(0,0,0,0.15);
|
| 20 |
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
| 21 |
+
font-size: 13px;
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
#info {
|
| 25 |
+
top: 10px;
|
| 26 |
+
left: 10px;
|
| 27 |
+
min-width: 200px;
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
#info h3 {
|
| 31 |
+
margin: 0 0 10px 0;
|
| 32 |
+
font-size: 16px;
|
| 33 |
+
color: #333;
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
#info .stat {
|
| 37 |
+
margin: 5px 0;
|
| 38 |
+
color: #666;
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
#info .stat strong {
|
| 42 |
+
color: #333;
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
#legend {
|
| 46 |
+
bottom: 30px;
|
| 47 |
+
left: 10px;
|
| 48 |
+
padding: 10px 15px;
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
#legend h4 {
|
| 52 |
+
margin: 0 0 10px 0;
|
| 53 |
+
font-size: 14px;
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
.legend-scale {
|
| 57 |
+
display: flex;
|
| 58 |
+
height: 15px;
|
| 59 |
+
border-radius: 3px;
|
| 60 |
+
overflow: hidden;
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
.legend-scale div {
|
| 64 |
+
flex: 1;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
.legend-labels {
|
| 68 |
+
display: flex;
|
| 69 |
+
justify-content: space-between;
|
| 70 |
+
margin-top: 5px;
|
| 71 |
+
font-size: 11px;
|
| 72 |
+
color: #666;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
#controls {
|
| 76 |
+
top: 10px;
|
| 77 |
+
right: 10px;
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
#controls label {
|
| 81 |
+
display: block;
|
| 82 |
+
margin: 5px 0;
|
| 83 |
+
cursor: pointer;
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
#controls select {
|
| 87 |
+
width: 100%;
|
| 88 |
+
padding: 5px;
|
| 89 |
+
margin-top: 10px;
|
| 90 |
+
border-radius: 4px;
|
| 91 |
+
border: 1px solid #ccc;
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
#zoom-level {
|
| 95 |
+
position: absolute;
|
| 96 |
+
bottom: 30px;
|
| 97 |
+
right: 10px;
|
| 98 |
+
background: rgba(255,255,255,0.9);
|
| 99 |
+
padding: 5px 10px;
|
| 100 |
+
border-radius: 4px;
|
| 101 |
+
font-family: monospace;
|
| 102 |
+
font-size: 12px;
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
#top-cities {
|
| 106 |
+
top: 80px;
|
| 107 |
+
right: 10px;
|
| 108 |
+
max-width: 220px;
|
| 109 |
+
display: none;
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
#top-cities h4 {
|
| 113 |
+
margin: 0 0 10px 0;
|
| 114 |
+
font-size: 14px;
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
#top-cities ol {
|
| 118 |
+
margin: 0;
|
| 119 |
+
padding-left: 20px;
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
#top-cities li {
|
| 123 |
+
margin: 4px 0;
|
| 124 |
+
font-size: 12px;
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
#top-cities .city-name {
|
| 128 |
+
font-weight: 500;
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
#top-cities .city-stats {
|
| 132 |
+
color: #666;
|
| 133 |
+
font-size: 11px;
|
| 134 |
+
}
|
| 135 |
+
</style>
|
| 136 |
+
</head>
|
| 137 |
+
<body>
|
| 138 |
+
<div id="map"></div>
|
| 139 |
+
|
| 140 |
+
<div class="map-overlay" id="info">
|
| 141 |
+
<h3>Prix Immobiliers</h3>
|
| 142 |
+
<div id="hover-info">
|
| 143 |
+
<p style="color: #999;">Survolez une zone pour voir les prix</p>
|
| 144 |
+
</div>
|
| 145 |
+
</div>
|
| 146 |
+
|
| 147 |
+
<div class="map-overlay" id="legend">
|
| 148 |
+
<h4>Prix médian (€/m²)</h4>
|
| 149 |
+
<div class="legend-scale" id="legend-scale"></div>
|
| 150 |
+
<div class="legend-labels" id="legend-labels">
|
| 151 |
+
<span>1 500</span>
|
| 152 |
+
<span>2 500</span>
|
| 153 |
+
<span>3 500</span>
|
| 154 |
+
<span>5 000</span>
|
| 155 |
+
<span>8 000+</span>
|
| 156 |
+
</div>
|
| 157 |
+
<div style="margin-top: 8px; display: flex; align-items: center; font-size: 11px; color: #666;">
|
| 158 |
+
<span style="display: inline-block; width: 16px; height: 12px; background: #999999; border-radius: 2px; margin-right: 6px;"></span>
|
| 159 |
+
<span>Aucune transaction</span>
|
| 160 |
+
</div>
|
| 161 |
+
<div style="margin-top: 4px; display: flex; align-items: center; font-size: 11px; color: #666;">
|
| 162 |
+
<span style="display: inline-block; width: 16px; height: 12px; background: #cccccc; border-radius: 2px; margin-right: 6px;"></span>
|
| 163 |
+
<span>< 5 transactions</span>
|
| 164 |
+
</div>
|
| 165 |
+
<div id="current-level" style="margin-top: 8px; font-size: 11px; color: #999;">Niveau: Pays</div>
|
| 166 |
+
</div>
|
| 167 |
+
|
| 168 |
+
<div class="map-overlay" id="controls">
|
| 169 |
+
<strong>Type de bien</strong>
|
| 170 |
+
<select id="property-type">
|
| 171 |
+
<option value="all">Tous types</option>
|
| 172 |
+
<option value="maison">Maisons</option>
|
| 173 |
+
<option value="appartement">Appartements</option>
|
| 174 |
+
</select>
|
| 175 |
+
</div>
|
| 176 |
+
|
| 177 |
+
<div id="zoom-level">Zoom: <span id="zoom-value">5</span></div>
|
| 178 |
+
|
| 179 |
+
<div class="map-overlay" id="top-cities">
|
| 180 |
+
<h4>🏆 Top 10 Villes</h4>
|
| 181 |
+
<div id="top-cities-list"></div>
|
| 182 |
+
</div>
|
| 183 |
+
|
| 184 |
+
<script>
|
| 185 |
+
// PMTiles protocol registration
|
| 186 |
+
const protocol = new pmtiles.Protocol();
|
| 187 |
+
mapboxgl.addProtocol("pmtiles", protocol.tile);
|
| 188 |
+
|
| 189 |
+
// Mapbox access token - replace with your own
|
| 190 |
+
mapboxgl.accessToken = 'pk.eyJ1IjoiYXJpc3RvdGVsaXNrb2VuIiwiYSI6ImNta3N4M2NteTFkYjAzaXNhNzlzbXVqMmwifQ.Lu0a9_eR2_kcqOWPEp2IRw';
|
| 191 |
+
|
| 192 |
+
// Color palette (green to yellow to red)
|
| 193 |
+
const colors = ['#1a9850', '#a6d96a', '#ffdd00', '#f46d43', '#d73027'];
|
| 194 |
+
|
| 195 |
+
// Will be populated with actual min/max from data
|
| 196 |
+
const priceScales = {
|
| 197 |
+
country: null,
|
| 198 |
+
regions: null,
|
| 199 |
+
departments: null,
|
| 200 |
+
iris: null,
|
| 201 |
+
communes: null,
|
| 202 |
+
parcels: null
|
| 203 |
+
};
|
| 204 |
+
|
| 205 |
+
// Store loaded GeoJSON data
|
| 206 |
+
const geoData = {};
|
| 207 |
+
|
| 208 |
+
// Compute price scale from GeoJSON features with 5 stops
|
| 209 |
+
function computePriceScale(features, priceField, level = 'default') {
|
| 210 |
+
// Fixed scale from 1500 to 8000 €/m² for all levels
|
| 211 |
+
return [1500, 3125, 4750, 6375, 8000];
|
| 212 |
+
}
|
| 213 |
+
|
| 214 |
+
// Build legend gradient (static colors)
|
| 215 |
+
const legendScale = document.getElementById('legend-scale');
|
| 216 |
+
colors.forEach(color => {
|
| 217 |
+
const div = document.createElement('div');
|
| 218 |
+
div.style.backgroundColor = color;
|
| 219 |
+
legendScale.appendChild(div);
|
| 220 |
+
});
|
| 221 |
+
|
| 222 |
+
// Initialize map
|
| 223 |
+
const map = new mapboxgl.Map({
|
| 224 |
+
container: 'map',
|
| 225 |
+
style: 'mapbox://styles/mapbox/light-v11',
|
| 226 |
+
center: [2.3, 46.5], // Center of France
|
| 227 |
+
zoom: 4,
|
| 228 |
+
minZoom: 3,
|
| 229 |
+
maxZoom: 18
|
| 230 |
+
});
|
| 231 |
+
|
| 232 |
+
// Current property type filter
|
| 233 |
+
let currentPropertyType = 'all';
|
| 234 |
+
let currentLevel = 'country';
|
| 235 |
+
let topCitiesData = [];
|
| 236 |
+
|
| 237 |
+
function updateTopCitiesPanel() {
|
| 238 |
+
const countField = getCountField();
|
| 239 |
+
const priceField = getPriceField();
|
| 240 |
+
|
| 241 |
+
// Aggregate arrondissements for Paris, Lyon, Marseille
|
| 242 |
+
const aggregated = {};
|
| 243 |
+
const bigCities = {
|
| 244 |
+
'Paris': { pattern: /^Paris \d+e?r? Arrondissement$/i, code: '75' },
|
| 245 |
+
'Marseille': { pattern: /^Marseille \d+e?r? Arrondissement$/i, code: '13' },
|
| 246 |
+
'Lyon': { pattern: /^Lyon \d+e?r? Arrondissement$/i, code: '69' }
|
| 247 |
+
};
|
| 248 |
+
|
| 249 |
+
topCitiesData.forEach(f => {
|
| 250 |
+
const name = f.properties.nom_commune || f.properties.nom_commune_geo || '';
|
| 251 |
+
const count = f.properties[countField] || 0;
|
| 252 |
+
const price = f.properties[priceField];
|
| 253 |
+
|
| 254 |
+
if (count === 0) return;
|
| 255 |
+
|
| 256 |
+
// Check if it's an arrondissement of a big city
|
| 257 |
+
let aggregateName = null;
|
| 258 |
+
for (const [city, info] of Object.entries(bigCities)) {
|
| 259 |
+
if (info.pattern.test(name)) {
|
| 260 |
+
aggregateName = city;
|
| 261 |
+
break;
|
| 262 |
+
}
|
| 263 |
+
}
|
| 264 |
+
|
| 265 |
+
if (aggregateName) {
|
| 266 |
+
// Aggregate into big city
|
| 267 |
+
if (!aggregated[aggregateName]) {
|
| 268 |
+
aggregated[aggregateName] = { name: aggregateName, count: 0, priceSum: 0, priceCount: 0 };
|
| 269 |
+
}
|
| 270 |
+
aggregated[aggregateName].count += count;
|
| 271 |
+
if (price) {
|
| 272 |
+
aggregated[aggregateName].priceSum += price * count;
|
| 273 |
+
aggregated[aggregateName].priceCount += count;
|
| 274 |
+
}
|
| 275 |
+
} else {
|
| 276 |
+
// Regular commune
|
| 277 |
+
aggregated[name] = { name, count, priceSum: price ? price * count : 0, priceCount: price ? count : 0 };
|
| 278 |
+
}
|
| 279 |
+
});
|
| 280 |
+
|
| 281 |
+
// Convert to array and sort
|
| 282 |
+
const sorted = Object.values(aggregated)
|
| 283 |
+
.map(c => ({
|
| 284 |
+
name: c.name,
|
| 285 |
+
count: c.count,
|
| 286 |
+
price: c.priceCount > 0 ? c.priceSum / c.priceCount : null
|
| 287 |
+
}))
|
| 288 |
+
.sort((a, b) => b.count - a.count)
|
| 289 |
+
.slice(0, 10);
|
| 290 |
+
|
| 291 |
+
const listHtml = sorted.map((c, i) => {
|
| 292 |
+
const priceStr = c.price ? Math.round(c.price).toLocaleString('fr-FR') + ' €/m²' : 'N/A';
|
| 293 |
+
return `<div style="margin: 6px 0;"><span class="city-name">${i+1}. ${c.name}</span><br><span class="city-stats">${c.count.toLocaleString('fr-FR')} transactions • ${priceStr}</span></div>`;
|
| 294 |
+
}).join('');
|
| 295 |
+
|
| 296 |
+
document.getElementById('top-cities-list').innerHTML = listHtml;
|
| 297 |
+
}
|
| 298 |
+
|
| 299 |
+
function showTopCities(show) {
|
| 300 |
+
document.getElementById('top-cities').style.display = show ? 'block' : 'none';
|
| 301 |
+
}
|
| 302 |
+
|
| 303 |
+
function getPriceField() {
|
| 304 |
+
switch(currentPropertyType) {
|
| 305 |
+
case 'maison': return 'prix_m2_maison_median';
|
| 306 |
+
case 'appartement': return 'prix_m2_appart_median';
|
| 307 |
+
default: return 'prix_m2_median';
|
| 308 |
+
}
|
| 309 |
+
}
|
| 310 |
+
|
| 311 |
+
function getCountField() {
|
| 312 |
+
switch(currentPropertyType) {
|
| 313 |
+
case 'maison': return 'nb_maisons';
|
| 314 |
+
case 'appartement': return 'nb_appartements';
|
| 315 |
+
default: return 'nb_transactions';
|
| 316 |
+
}
|
| 317 |
+
}
|
| 318 |
+
|
| 319 |
+
// Format price for display
|
| 320 |
+
function formatPrice(price) {
|
| 321 |
+
if (price === null || price === undefined) return 'N/A';
|
| 322 |
+
return Math.round(price).toLocaleString('fr-FR') + ' €/m²';
|
| 323 |
+
}
|
| 324 |
+
|
| 325 |
+
function formatCount(count) {
|
| 326 |
+
if (count === null || count === undefined) return 'N/A';
|
| 327 |
+
return count.toLocaleString('fr-FR');
|
| 328 |
+
}
|
| 329 |
+
|
| 330 |
+
// Update hover info panel
|
| 331 |
+
function updateInfo(properties, level) {
|
| 332 |
+
const priceField = getPriceField();
|
| 333 |
+
const countField = getCountField();
|
| 334 |
+
|
| 335 |
+
let name = '';
|
| 336 |
+
if (level === 'country') {
|
| 337 |
+
name = properties.name || 'France';
|
| 338 |
+
} else if (level === 'regions') {
|
| 339 |
+
name = properties.nom_region || properties.nom_region_geo || 'Région';
|
| 340 |
+
} else if (level === 'departments') {
|
| 341 |
+
name = properties.nom_departement || 'Département';
|
| 342 |
+
} else if (level === 'iris') {
|
| 343 |
+
const irisName = properties.nom_iris || '';
|
| 344 |
+
const communeName = properties.nom_commune_iris || '';
|
| 345 |
+
const irisCode = properties.code_iris || '';
|
| 346 |
+
// If IRIS name equals commune name, show code for distinction
|
| 347 |
+
if (irisName === communeName && irisCode) {
|
| 348 |
+
name = `IRIS ${irisCode} (${communeName})`;
|
| 349 |
+
} else if (irisName) {
|
| 350 |
+
name = communeName && irisName !== communeName ? `${irisName} (${communeName})` : irisName;
|
| 351 |
+
} else {
|
| 352 |
+
name = irisCode ? `IRIS ${irisCode}` : 'IRIS';
|
| 353 |
+
}
|
| 354 |
+
} else if (level === 'communes') {
|
| 355 |
+
name = properties.nom_commune || properties.nom_commune_geo || 'Commune';
|
| 356 |
+
} else if (level === 'parcels') {
|
| 357 |
+
const parcelId = properties.id_parcelle_unique || properties.id || '';
|
| 358 |
+
const commune = properties.nom_commune || '';
|
| 359 |
+
name = commune ? `Parcelle ${parcelId} (${commune})` : `Parcelle ${parcelId}`;
|
| 360 |
+
}
|
| 361 |
+
|
| 362 |
+
const price = properties[priceField];
|
| 363 |
+
const priceMean = properties[priceField.replace('median', 'mean')];
|
| 364 |
+
const count = properties[countField];
|
| 365 |
+
const priceQ25 = properties[priceField.replace('median', 'q25')];
|
| 366 |
+
const priceQ75 = properties[priceField.replace('median', 'q75')];
|
| 367 |
+
|
| 368 |
+
const noData = (count || 0) === 0;
|
| 369 |
+
const insufficientData = (count || 0) > 0 && (count || 0) < 5;
|
| 370 |
+
|
| 371 |
+
let dataNote = '';
|
| 372 |
+
if (noData) {
|
| 373 |
+
dataNote = '<div class="stat" style="color: #888; font-style: italic;">⛔ Aucune transaction</div>';
|
| 374 |
+
} else if (insufficientData) {
|
| 375 |
+
dataNote = '<div class="stat" style="color: #999; font-style: italic;">⚠️ Données insuffisantes (<5 transactions)</div>';
|
| 376 |
+
}
|
| 377 |
+
|
| 378 |
+
document.getElementById('hover-info').innerHTML = `
|
| 379 |
+
<div class="stat"><strong>${name}</strong></div>
|
| 380 |
+
${dataNote}
|
| 381 |
+
<div class="stat">Prix médian: <strong>${noData ? 'N/A' : formatPrice(price)}</strong></div>
|
| 382 |
+
<div class="stat">Prix moyen: ${noData ? 'N/A' : formatPrice(priceMean)}</div>
|
| 383 |
+
<div class="stat">Fourchette: ${noData ? 'N/A' : formatPrice(priceQ25) + ' - ' + formatPrice(priceQ75)}</div>
|
| 384 |
+
<div class="stat">Transactions: <strong>${formatCount(count)}</strong></div>
|
| 385 |
+
`;
|
| 386 |
+
}
|
| 387 |
+
|
| 388 |
+
function resetInfo() {
|
| 389 |
+
document.getElementById('hover-info').innerHTML =
|
| 390 |
+
'<p style="color: #999;">Survolez une zone pour voir les prix</p>';
|
| 391 |
+
}
|
| 392 |
+
|
| 393 |
+
// Build fill-color expression for a layer with specific scale
|
| 394 |
+
// Shows darker gray for no data, lighter gray for <10 transactions
|
| 395 |
+
function buildFillColor(level) {
|
| 396 |
+
const priceField = getPriceField();
|
| 397 |
+
const countField = getCountField();
|
| 398 |
+
const scale = priceScales[level] || [1000, 2000, 3000, 4000, 5000, 7000, 10000];
|
| 399 |
+
|
| 400 |
+
// Build interpolation stops: [price1, color1, price2, color2, ...]
|
| 401 |
+
const stops = [];
|
| 402 |
+
for (let i = 0; i < scale.length; i++) {
|
| 403 |
+
stops.push(scale[i], colors[i]);
|
| 404 |
+
}
|
| 405 |
+
|
| 406 |
+
// Use case expressions: 0 transactions -> dark gray, <10 -> light gray, else color
|
| 407 |
+
return [
|
| 408 |
+
'case',
|
| 409 |
+
['==', ['coalesce', ['get', countField], 0], 0],
|
| 410 |
+
'#999999', // Dark gray for no transactions
|
| 411 |
+
['<', ['coalesce', ['get', countField], 0], 5],
|
| 412 |
+
'#cccccc', // Light gray for insufficient data
|
| 413 |
+
[
|
| 414 |
+
'interpolate',
|
| 415 |
+
['linear'],
|
| 416 |
+
['coalesce', ['get', priceField], 0],
|
| 417 |
+
...stops
|
| 418 |
+
]
|
| 419 |
+
];
|
| 420 |
+
}
|
| 421 |
+
|
| 422 |
+
// Update legend labels based on current level
|
| 423 |
+
function updateLegend(level) {
|
| 424 |
+
const scale = priceScales[level] || [1500, 3125, 4750, 6375, 8000];
|
| 425 |
+
const labels = document.getElementById('legend-labels');
|
| 426 |
+
const levelNames = {
|
| 427 |
+
country: 'Pays',
|
| 428 |
+
regions: 'Régions',
|
| 429 |
+
departments: 'Départements',
|
| 430 |
+
communes: 'Communes',
|
| 431 |
+
iris: 'IRIS (Quartiers)',
|
| 432 |
+
parcels: 'Parcelles'
|
| 433 |
+
};
|
| 434 |
+
|
| 435 |
+
// Format number for legend (k for thousands)
|
| 436 |
+
const fmt = (n) => n >= 1000 ? `${(n/1000).toFixed(1)}k` : n.toString();
|
| 437 |
+
|
| 438 |
+
// Update labels (show all 5 values)
|
| 439 |
+
labels.innerHTML = `
|
| 440 |
+
<span>${fmt(scale[0])}</span>
|
| 441 |
+
<span>${fmt(scale[1])}</span>
|
| 442 |
+
<span>${fmt(scale[2])}</span>
|
| 443 |
+
<span>${fmt(scale[3])}</span>
|
| 444 |
+
<span>${fmt(scale[4])}</span>
|
| 445 |
+
`;
|
| 446 |
+
|
| 447 |
+
document.getElementById('current-level').textContent = `Niveau: ${levelNames[level]}`;
|
| 448 |
+
}
|
| 449 |
+
|
| 450 |
+
// Update scales and colors when property type changes
|
| 451 |
+
function updateScalesAndColors() {
|
| 452 |
+
const priceField = getPriceField();
|
| 453 |
+
|
| 454 |
+
// Recompute scales for each level based on current property type
|
| 455 |
+
['country', 'regions', 'departments', 'iris', 'communes'].forEach(level => {
|
| 456 |
+
if (geoData[level]) {
|
| 457 |
+
priceScales[level] = computePriceScale(geoData[level].features, priceField, level);
|
| 458 |
+
}
|
| 459 |
+
});
|
| 460 |
+
// Parcels use the same fixed scale
|
| 461 |
+
priceScales['parcels'] = [1500, 3125, 4750, 6375, 8000];
|
| 462 |
+
|
| 463 |
+
// Update layer colors
|
| 464 |
+
['country', 'regions', 'departments', 'iris', 'communes'].forEach(level => {
|
| 465 |
+
const layerId = `${level}-fill`;
|
| 466 |
+
if (map.getLayer(layerId)) {
|
| 467 |
+
map.setPaintProperty(layerId, 'fill-color', buildFillColor(level));
|
| 468 |
+
}
|
| 469 |
+
});
|
| 470 |
+
|
| 471 |
+
// Update parcels layer color (vector tiles)
|
| 472 |
+
if (map.getLayer('parcels-fill')) {
|
| 473 |
+
map.setPaintProperty('parcels-fill', 'fill-color', buildFillColor('parcels'));
|
| 474 |
+
}
|
| 475 |
+
|
| 476 |
+
// Update legend
|
| 477 |
+
updateLegend(currentLevel);
|
| 478 |
+
}
|
| 479 |
+
|
| 480 |
+
// Update all layer colors when property type changes
|
| 481 |
+
function updateLayerColors() {
|
| 482 |
+
updateScalesAndColors();
|
| 483 |
+
}
|
| 484 |
+
|
| 485 |
+
// Determine current level based on zoom
|
| 486 |
+
function getLevelFromZoom(zoom) {
|
| 487 |
+
if (zoom < 5) return 'country';
|
| 488 |
+
if (zoom < 7) return 'regions';
|
| 489 |
+
if (zoom < 9) return 'departments';
|
| 490 |
+
if (zoom < 11) return 'communes';
|
| 491 |
+
if (zoom < 13) return 'iris';
|
| 492 |
+
return 'parcels';
|
| 493 |
+
}
|
| 494 |
+
|
| 495 |
+
map.on('load', async () => {
|
| 496 |
+
// Load all GeoJSON data and compute scales
|
| 497 |
+
const levels = ['country', 'regions', 'departments', 'iris', 'communes'];
|
| 498 |
+
const priceField = getPriceField();
|
| 499 |
+
|
| 500 |
+
for (const level of levels) {
|
| 501 |
+
const response = await fetch(`data/${level}.geojson`);
|
| 502 |
+
geoData[level] = await response.json();
|
| 503 |
+
priceScales[level] = computePriceScale(geoData[level].features, priceField, level);
|
| 504 |
+
console.log(`${level} scale:`, priceScales[level]);
|
| 505 |
+
}
|
| 506 |
+
|
| 507 |
+
// Store communes data for top cities panel
|
| 508 |
+
topCitiesData = geoData.communes.features;
|
| 509 |
+
updateTopCitiesPanel();
|
| 510 |
+
showTopCities(true); // Show at initial country level
|
| 511 |
+
|
| 512 |
+
// Add country source and layers
|
| 513 |
+
map.addSource('country', {
|
| 514 |
+
type: 'geojson',
|
| 515 |
+
data: geoData.country
|
| 516 |
+
});
|
| 517 |
+
|
| 518 |
+
map.addLayer({
|
| 519 |
+
id: 'country-fill',
|
| 520 |
+
type: 'fill',
|
| 521 |
+
source: 'country',
|
| 522 |
+
paint: {
|
| 523 |
+
'fill-color': buildFillColor('country'),
|
| 524 |
+
'fill-opacity': 0.7
|
| 525 |
+
},
|
| 526 |
+
maxzoom: 5
|
| 527 |
+
});
|
| 528 |
+
|
| 529 |
+
map.addLayer({
|
| 530 |
+
id: 'country-line',
|
| 531 |
+
type: 'line',
|
| 532 |
+
source: 'country',
|
| 533 |
+
paint: {
|
| 534 |
+
'line-color': '#333',
|
| 535 |
+
'line-width': 2
|
| 536 |
+
},
|
| 537 |
+
maxzoom: 5
|
| 538 |
+
});
|
| 539 |
+
|
| 540 |
+
// Add regions source and layers
|
| 541 |
+
map.addSource('regions', {
|
| 542 |
+
type: 'geojson',
|
| 543 |
+
data: geoData.regions
|
| 544 |
+
});
|
| 545 |
+
|
| 546 |
+
map.addLayer({
|
| 547 |
+
id: 'regions-fill',
|
| 548 |
+
type: 'fill',
|
| 549 |
+
source: 'regions',
|
| 550 |
+
paint: {
|
| 551 |
+
'fill-color': buildFillColor('regions'),
|
| 552 |
+
'fill-opacity': 0.7
|
| 553 |
+
},
|
| 554 |
+
minzoom: 5,
|
| 555 |
+
maxzoom: 7
|
| 556 |
+
});
|
| 557 |
+
|
| 558 |
+
map.addLayer({
|
| 559 |
+
id: 'regions-line',
|
| 560 |
+
type: 'line',
|
| 561 |
+
source: 'regions',
|
| 562 |
+
paint: {
|
| 563 |
+
'line-color': '#333',
|
| 564 |
+
'line-width': 1.5
|
| 565 |
+
},
|
| 566 |
+
minzoom: 5,
|
| 567 |
+
maxzoom: 7
|
| 568 |
+
});
|
| 569 |
+
|
| 570 |
+
// Add departments source and layers
|
| 571 |
+
map.addSource('departments', {
|
| 572 |
+
type: 'geojson',
|
| 573 |
+
data: geoData.departments
|
| 574 |
+
});
|
| 575 |
+
|
| 576 |
+
map.addLayer({
|
| 577 |
+
id: 'departments-fill',
|
| 578 |
+
type: 'fill',
|
| 579 |
+
source: 'departments',
|
| 580 |
+
paint: {
|
| 581 |
+
'fill-color': buildFillColor('departments'),
|
| 582 |
+
'fill-opacity': 0.7
|
| 583 |
+
},
|
| 584 |
+
minzoom: 7,
|
| 585 |
+
maxzoom: 9
|
| 586 |
+
});
|
| 587 |
+
|
| 588 |
+
map.addLayer({
|
| 589 |
+
id: 'departments-line',
|
| 590 |
+
type: 'line',
|
| 591 |
+
source: 'departments',
|
| 592 |
+
paint: {
|
| 593 |
+
'line-color': '#333',
|
| 594 |
+
'line-width': 1
|
| 595 |
+
},
|
| 596 |
+
minzoom: 7,
|
| 597 |
+
maxzoom: 9
|
| 598 |
+
});
|
| 599 |
+
|
| 600 |
+
// Add IRIS (neighborhoods) source and layers
|
| 601 |
+
map.addSource('iris', {
|
| 602 |
+
type: 'geojson',
|
| 603 |
+
data: geoData.iris
|
| 604 |
+
});
|
| 605 |
+
|
| 606 |
+
map.addLayer({
|
| 607 |
+
id: 'iris-fill',
|
| 608 |
+
type: 'fill',
|
| 609 |
+
source: 'iris',
|
| 610 |
+
paint: {
|
| 611 |
+
'fill-color': buildFillColor('iris'),
|
| 612 |
+
'fill-opacity': 0.7
|
| 613 |
+
},
|
| 614 |
+
minzoom: 11,
|
| 615 |
+
maxzoom: 13
|
| 616 |
+
});
|
| 617 |
+
|
| 618 |
+
map.addLayer({
|
| 619 |
+
id: 'iris-line',
|
| 620 |
+
type: 'line',
|
| 621 |
+
source: 'iris',
|
| 622 |
+
paint: {
|
| 623 |
+
'line-color': '#555',
|
| 624 |
+
'line-width': 0.5
|
| 625 |
+
},
|
| 626 |
+
minzoom: 11,
|
| 627 |
+
maxzoom: 13
|
| 628 |
+
});
|
| 629 |
+
|
| 630 |
+
// Add parcels source (PMTiles) and layers
|
| 631 |
+
// Only add if PMTiles file exists
|
| 632 |
+
try {
|
| 633 |
+
map.addSource('parcels', {
|
| 634 |
+
type: 'vector',
|
| 635 |
+
url: 'pmtiles://data/parcels.pmtiles'
|
| 636 |
+
});
|
| 637 |
+
|
| 638 |
+
map.addLayer({
|
| 639 |
+
id: 'parcels-fill',
|
| 640 |
+
type: 'fill',
|
| 641 |
+
source: 'parcels',
|
| 642 |
+
'source-layer': 'parcels',
|
| 643 |
+
paint: {
|
| 644 |
+
'fill-color': buildFillColor('parcels'),
|
| 645 |
+
'fill-opacity': 0.8
|
| 646 |
+
},
|
| 647 |
+
minzoom: 13
|
| 648 |
+
});
|
| 649 |
+
|
| 650 |
+
map.addLayer({
|
| 651 |
+
id: 'parcels-line',
|
| 652 |
+
type: 'line',
|
| 653 |
+
source: 'parcels',
|
| 654 |
+
'source-layer': 'parcels',
|
| 655 |
+
paint: {
|
| 656 |
+
'line-color': '#333',
|
| 657 |
+
'line-width': 0.3
|
| 658 |
+
},
|
| 659 |
+
minzoom: 13
|
| 660 |
+
});
|
| 661 |
+
|
| 662 |
+
console.log('Parcels PMTiles layer added');
|
| 663 |
+
} catch (e) {
|
| 664 |
+
console.log('Parcels PMTiles not available:', e.message);
|
| 665 |
+
}
|
| 666 |
+
|
| 667 |
+
// Add communes source and layers
|
| 668 |
+
map.addSource('communes', {
|
| 669 |
+
type: 'geojson',
|
| 670 |
+
data: geoData.communes
|
| 671 |
+
});
|
| 672 |
+
|
| 673 |
+
map.addLayer({
|
| 674 |
+
id: 'communes-fill',
|
| 675 |
+
type: 'fill',
|
| 676 |
+
source: 'communes',
|
| 677 |
+
paint: {
|
| 678 |
+
'fill-color': buildFillColor('communes'),
|
| 679 |
+
'fill-opacity': 0.7
|
| 680 |
+
},
|
| 681 |
+
minzoom: 9,
|
| 682 |
+
maxzoom: 11
|
| 683 |
+
});
|
| 684 |
+
|
| 685 |
+
map.addLayer({
|
| 686 |
+
id: 'communes-line',
|
| 687 |
+
type: 'line',
|
| 688 |
+
source: 'communes',
|
| 689 |
+
paint: {
|
| 690 |
+
'line-color': '#666',
|
| 691 |
+
'line-width': 0.5
|
| 692 |
+
},
|
| 693 |
+
minzoom: 9,
|
| 694 |
+
maxzoom: 11
|
| 695 |
+
});
|
| 696 |
+
|
| 697 |
+
// Hover interactions for each layer
|
| 698 |
+
['country', 'regions', 'departments', 'iris', 'communes'].forEach(layer => {
|
| 699 |
+
map.on('mousemove', `${layer}-fill`, (e) => {
|
| 700 |
+
map.getCanvas().style.cursor = 'pointer';
|
| 701 |
+
if (e.features.length > 0) {
|
| 702 |
+
updateInfo(e.features[0].properties, layer);
|
| 703 |
+
}
|
| 704 |
+
});
|
| 705 |
+
|
| 706 |
+
map.on('mouseleave', `${layer}-fill`, () => {
|
| 707 |
+
map.getCanvas().style.cursor = '';
|
| 708 |
+
resetInfo();
|
| 709 |
+
});
|
| 710 |
+
});
|
| 711 |
+
|
| 712 |
+
// Separate hover handler for parcels (vector tiles)
|
| 713 |
+
if (map.getSource('parcels')) {
|
| 714 |
+
map.on('mousemove', 'parcels-fill', (e) => {
|
| 715 |
+
map.getCanvas().style.cursor = 'pointer';
|
| 716 |
+
if (e.features.length > 0) {
|
| 717 |
+
updateInfo(e.features[0].properties, 'parcels');
|
| 718 |
+
}
|
| 719 |
+
});
|
| 720 |
+
|
| 721 |
+
map.on('mouseleave', 'parcels-fill', () => {
|
| 722 |
+
map.getCanvas().style.cursor = '';
|
| 723 |
+
resetInfo();
|
| 724 |
+
});
|
| 725 |
+
}
|
| 726 |
+
|
| 727 |
+
// Initial legend update
|
| 728 |
+
updateLegend(getLevelFromZoom(map.getZoom()));
|
| 729 |
+
});
|
| 730 |
+
|
| 731 |
+
// Update zoom display and legend
|
| 732 |
+
map.on('zoom', () => {
|
| 733 |
+
const zoom = map.getZoom();
|
| 734 |
+
document.getElementById('zoom-value').textContent = zoom.toFixed(1);
|
| 735 |
+
|
| 736 |
+
const newLevel = getLevelFromZoom(zoom);
|
| 737 |
+
if (newLevel !== currentLevel) {
|
| 738 |
+
currentLevel = newLevel;
|
| 739 |
+
updateLegend(currentLevel);
|
| 740 |
+
}
|
| 741 |
+
});
|
| 742 |
+
|
| 743 |
+
// Property type selector
|
| 744 |
+
document.getElementById('property-type').addEventListener('change', (e) => {
|
| 745 |
+
currentPropertyType = e.target.value;
|
| 746 |
+
updateLayerColors();
|
| 747 |
+
updateTopCitiesPanel();
|
| 748 |
+
});
|
| 749 |
+
|
| 750 |
+
// Add navigation controls
|
| 751 |
+
map.addControl(new mapboxgl.NavigationControl());
|
| 752 |
+
</script>
|
| 753 |
+
</body>
|
| 754 |
</html>
|