fix: correcciones parciales - ProjectController, ProfileController, Phase features, project-map JS
This commit is contained in:
@@ -140,31 +140,50 @@
|
||||
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
|
||||
}).addTo(map);*/
|
||||
|
||||
// Add geojson layers for active phases
|
||||
// Add geojson layers for active phases - features loaded from DB via features() relationship
|
||||
@foreach($phases as $phase)
|
||||
const phase{{ $phase->id }}Data = @json($phase->currentLayer?->geojson_data);
|
||||
if (phase{{ $phase->id }}Data) {
|
||||
@php
|
||||
$phaseFeatures = $phase->features()->with('layer')->get();
|
||||
$fc = [
|
||||
'type' => 'FeatureCollection',
|
||||
'features' => $phaseFeatures->map(function($f) {
|
||||
return [
|
||||
'type' => 'Feature',
|
||||
'id' => $f->id,
|
||||
'geometry' => $f->geometry,
|
||||
'properties' => array_merge($f->properties ?? [], [
|
||||
'name' => $f->name,
|
||||
'progress' => $f->progress,
|
||||
'responsible' => $f->responsible,
|
||||
'template_id' => $f->template_id,
|
||||
'_feature_id' => $f->id,
|
||||
])
|
||||
];
|
||||
})->values()->toArray()
|
||||
];
|
||||
@endphp
|
||||
const phase{{ $phase->id }}Data = @json($fc);
|
||||
if (phase{{ $phase->id }}Data && phase{{ $phase->id }}Data.features && phase{{ $phase->id }}Data.features.length > 0) {
|
||||
layers[{{ $phase->id }}] = L.geoJSON(phase{{ $phase->id }}Data, {
|
||||
style: { color: '{{ $phase->color }}', weight: 3, opacity: 0.8, fillOpacity: 0.3 },
|
||||
onEachFeature: function (feature, layer) {
|
||||
const props = feature.properties;
|
||||
const props = feature.properties || {};
|
||||
const featId = props._feature_id || feature.id;
|
||||
let content = `<b>${props.name || 'Elemento'}</b><br>
|
||||
Progreso: ${props.progress || 'N/A'}%<br>
|
||||
Responsable: ${props.responsible || '-'}<br>
|
||||
<input type="range" min="0" max="100" value="${props.progress || 0}" id="slider-${feature.id}" class="range range-sm" />
|
||||
<button class="btn btn-xs btn-primary mt-1" onclick="updatePhaseProgress({{ $phase->id }}, document.getElementById('slider-${feature.id}').value)">Actualizar</button>
|
||||
<button class="btn btn-xs btn-secondary mt-1" onclick="addNote({{ $phase->id }})">Añadir nota</button>`;
|
||||
<input type="range" min="0" max="100" value="${props.progress || 0}" id="slider-${featId}" class="range range-sm" />
|
||||
<button class="btn btn-xs btn-primary mt-1" onclick="window.updateFeatureProgress(${featId}, document.getElementById('slider-${featId}').value)">Actualizar</button>`;
|
||||
layer.bindPopup(content);
|
||||
layer.on('click', function(e) {
|
||||
@this.selectFeature(feature.properties.id, feature.properties);
|
||||
@this.selectFeature(featId);
|
||||
});
|
||||
}
|
||||
});
|
||||
if (@json(in_array($phase->id, $activeLayers))) {
|
||||
layers[{{ $phase->id }}].addTo(map);
|
||||
}
|
||||
}
|
||||
@endforeach
|
||||
|
||||
|
||||
// 🔁 Forzar que el mapa recalcule su tamaño (por si el contenedor no está visible al 100%)
|
||||
setTimeout(() => {
|
||||
@@ -242,8 +261,8 @@
|
||||
}
|
||||
}
|
||||
|
||||
window.updatePhaseProgress = function(phaseId, progress) {
|
||||
@this.updateProgress(phaseId, progress);
|
||||
window.updateFeatureProgress = function(featureId, progress) {
|
||||
@this.updateProgress(featureId, progress, 'Actualizado desde mapa');
|
||||
}
|
||||
</script>
|
||||
@endpush
|
||||
Reference in New Issue
Block a user