This commit is contained in:
HolgerHatGarKeineNode
2023-11-20 19:42:49 +01:00
parent b489f98c2a
commit 82f0df1666
5 changed files with 68 additions and 9 deletions

View File

@@ -2,16 +2,33 @@
namespace App\Livewire\Nostr; namespace App\Livewire\Nostr;
use App\Models\Meetup;
use App\Models\User; use App\Models\User;
use Livewire\Component; use Livewire\Component;
class Start extends Component class Start extends Component
{ {
public ?User $user = null; public ?User $user = null;
public array $geoJsons = [];
public function setUser($value) public function setUser($value)
{ {
$this->user = User::query()->with(['meetups'])->where('nostr', $value['npub'])->first(); $this->user = User::query()
->with([
'meetups.city',
])
->where('nostr', $value['npub'])
->first();
$this->geoJsons = Meetup::query()
->with([
'city',
])
->get()
->pluck('city.simplified_geojson')
->filter()
->values()
->toArray();
} }
public function render() public function render()

View File

@@ -14,6 +14,8 @@
{{-- Fonts --}} {{-- Fonts --}}
@googlefonts @googlefonts
{{-- Scripts --}} {{-- Scripts --}}
@mapscripts
@include('components.layouts.scripts')
<script src="https://kit.fontawesome.com/866fd3d0ab.js" crossorigin="anonymous"></script> <script src="https://kit.fontawesome.com/866fd3d0ab.js" crossorigin="anonymous"></script>
<x-embed-styles/> <x-embed-styles/>
@wireUiScripts @wireUiScripts

View File

@@ -14,6 +14,8 @@
{{-- Fonts --}} {{-- Fonts --}}
@googlefonts @googlefonts
{{-- Scripts --}} {{-- Scripts --}}
@mapscripts
@include('components.layouts.scripts')
<script src="https://kit.fontawesome.com/866fd3d0ab.js" crossorigin="anonymous"></script> <script src="https://kit.fontawesome.com/866fd3d0ab.js" crossorigin="anonymous"></script>
<x-embed-styles/> <x-embed-styles/>
@wireUiScripts @wireUiScripts

View File

@@ -0,0 +1,4 @@
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css"
integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY="
crossorigin=""/>
<script src="{{ asset('dist/leaflet-providers.js') }}"></script>

View File

@@ -1,12 +1,46 @@
<div x-data="nostrStart(@this)"> <div x-data="nostrStart(@this)">
<div class="p-16">
<div
wire:ignore
x-data="{
geoJsons: @entangle('geoJsons'),
map: null,
init() {
this.map = L.map(this.$refs.map).setView([51.1642, 10.4541194], 6);
var baseLayer = L.tileLayer(
'https://{s}.basemaps.cartocdn.com/dark_nolabels/{z}/{x}/{y}{r}.png',{
attribution: '&copy; <a href=\'https://www.openstreetmap.org/copyright\'>OpenStreetMap</a> contributors &copy; <a href=\'https://carto.com/attributions\'>CARTO</a>',
}
).addTo(this.map);
<div class="flex flex-col"> function generateSimilarColor(baseColor, variance) {
@if($user) var baseR = parseInt(baseColor.slice(1, 3), 16);
@foreach($user->meetups as $meetup) var baseG = parseInt(baseColor.slice(3, 5), 16);
<div> var baseB = parseInt(baseColor.slice(5, 7), 16);
{{ $meetup->name }} var newR = Math.floor((Math.random() - 0.5) * variance + baseR).toString(16).padStart(2, '0');
var newG = Math.floor((Math.random() - 0.5) * variance + baseG).toString(16).padStart(2, '0');
var newB = Math.floor((Math.random() - 0.5) * variance + baseB).toString(16).padStart(2, '0');
return `#${newR}${newG}${newB}`;
}
this.$watch('geoJsons', (geoJsons) => {
geoJsons.forEach((geoJson) => {
L.geoJSON(geoJson, {
style: function (feature) {
return {
color: generateSimilarColor('#0d579b', 20),
fillColor: generateSimilarColor('#f7931a', 20),
weight: 1,
opacity: 1,
};
},
}).addTo(this.map);
});
});
}
}"
>
<div class="w-full" x-ref="map" style="height: 70vh;"></div>
</div> </div>
@endforeach
@endif
</div> </div>
</div> </div>