From 3c3c1100050f6ae2f170d9ab92003c1edc5e2da2 Mon Sep 17 00:00:00 2001 From: guillaume91 Date: Thu, 20 Jun 2024 13:37:37 +0200 Subject: [PATCH] [fix] Map init with the current geosjon files. Added menu for the layers. --- .../app/Livewire/Projects/Tabs/Settings.php | 5 +- .../livewire/projects/tabs/settings.blade.php | 75 ++++++++----------- .../livewire/dropzone.blade.php | 17 ++++- 3 files changed, 49 insertions(+), 48 deletions(-) diff --git a/laravel_app/app/Livewire/Projects/Tabs/Settings.php b/laravel_app/app/Livewire/Projects/Tabs/Settings.php index 0ce4856..1b70e9a 100644 --- a/laravel_app/app/Livewire/Projects/Tabs/Settings.php +++ b/laravel_app/app/Livewire/Projects/Tabs/Settings.php @@ -5,6 +5,7 @@ use App\Models\Project; use App\Models\ProjectEmailRecipient; use App\Rules\HarvestFile; +use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Validator; use Illuminate\Validation\Rule; use Livewire\Component; @@ -49,8 +50,8 @@ private function loadFormData(Project $project) 'email' => '', ] ]; - $this->formData['pivot_file'] = null; - $this->formData['span_file'] = null; + $this->formData['pivot_file'] = Storage::disk('local')->get($project->name.'/Data/pivot.geojson'); + $this->formData['span_file'] = Storage::disk('local')->get($project->name.'/Data/span.geojson'); $this->formData['harvest_file'] = null; } public function saveProject() diff --git a/laravel_app/resources/views/livewire/projects/tabs/settings.blade.php b/laravel_app/resources/views/livewire/projects/tabs/settings.blade.php index 5f44089..bd4fa24 100644 --- a/laravel_app/resources/views/livewire/projects/tabs/settings.blade.php +++ b/laravel_app/resources/views/livewire/projects/tabs/settings.blade.php @@ -28,9 +28,12 @@ } }, initMapLayer(){ - if(window.geoJsonMap && window.geoJsonLayer) return; - window.geoJsonLayer = L.geoJSON(); - window.geoJsonLayer.addTo(window.geoJsonMap); + if(window.geoJsonMap && window.groupLayer) return; + window.pivotLayer = L.geoJson(); + window.spanLayer = L.geoJson(); + window.groupLayer = L.featureGroup([window.pivotLayer,window.spanLayer]); + window.groupLayer.addTo(window.geoJsonMap); + L.control.layers(null,{'Pivot':window.pivotLayer,'Span':window.spanLayer}).addTo(window.geoJsonMap); window.mapLayers=[]; }, showMap(data,type){ @@ -39,54 +42,35 @@ this.addLayer(data,type); console.log('GeoJson loaded on the map.'); }, + addLayerData(data,layer){ + console.log('here'); + var basicColors = ['orange', 'purple']; + if(data && layer){ + layer.clearLayers(); + layer.addData(data); + layer.setStyle(function(feature) { + return { + color: (layer === window.pivotLayer) ? 'purple' : 'orange', + weight: 2, + opacity: 0.5, + fillOpacity: 0.5 + }; + }); + } + window.geoJsonMap.fitBounds(window.groupLayer.getBounds()); + window.map.focus(); + }, addLayer(layerData,type){ switch(type){ case 'pivot_file': - window.mapLayers.unshift(layerData); + this.addLayerData(layerData,window.pivotLayer); break; case 'span_file': - window.mapLayers.push(layerData); + this.addLayerData(layerData,window.spanLayer); break; default: break; } - this.updateLayer(layerData); - window.map.focus(); - }, - updateLayer(layerData){ - var basicColors = ['red', 'blue', 'orange', 'purple']; - var randomIndex = Math.floor(Math.random() * basicColors.length); - window.geoJsonLayer.addData(layerData); - window.geoJsonLayer.setStyle(function(feature) { - return { - color: basicColors[randomIndex], - weight: 2, - opacity: 0.5, - fillOpacity: 0.5 - }; - }); - window.geoJsonMap.fitBounds(geoJsonLayer.getBounds()); - - }, - removeLayer(type){ - try{ - window.geoJsonLayer.clearLayers(); - switch(type){ - case 'pivot_file': - window.mapLayers.shift(); - break; - case 'span_file': - window.mapLayers.pop(); - break; - default: - break; - } - if(window.mapLayers.length == 0) window.map.style.height='0px'; - window.mapLayers.forEach((data) => this.updateLayer(data)); - window.map.focus(); - }catch(e){ - console.debug('Not a geojson file, keep going.'); - } } }" x-on:livewire-upload-finish.document="processFile($event.target.files[0],$event.target.closest('[id]').id);" @@ -101,7 +85,12 @@
-
+
diff --git a/laravel_app/resources/views/vendor/livewire-dropzone/livewire/dropzone.blade.php b/laravel_app/resources/views/vendor/livewire-dropzone/livewire/dropzone.blade.php index 1a5db32..4fb3d6b 100644 --- a/laravel_app/resources/views/vendor/livewire-dropzone/livewire/dropzone.blade.php +++ b/laravel_app/resources/views/vendor/livewire-dropzone/livewire/dropzone.blade.php @@ -123,7 +123,7 @@ class="hidden"
-