PHP code example of nwn-software / maplibre

1. Go to this page and download the library: Download nwn-software/maplibre library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

nwn-software / maplibre example snippets


return [
    'style' => env('MAPLIBRE_STYLE', 'https://demotiles.maplibre.org/style.json'),
];

MaplibrePlugin::make()
    ->style(config('maplibre.style'))



namespace App\Filament\App\Widgets;

use App\Models\Employee;
use App\Models\User;
use NWNSoftware\Maplibre\Data\MarkerData;
use NWNSoftware\Maplibre\Widgets\MapLibreWidget;

class MapWidget extends MapLibreWidget {

    protected array $center = [0, 0];

    protected int $zoom = 9;

    protected bool $allowFullscreen = true;

    public function getMarkers(): array {
        return [];
    }
}



namespace App\Filament\App\Widgets;

use App\Models\Employee;
use App\Models\User;
use NWNSoftware\Maplibre\Data\MarkerData;
use NWNSoftware\Maplibre\Widgets\MapLibreWidget;

class MapWidget extends MapLibreWidget {

    protected array $center = [0, 0];

    protected int $zoom = 9;

    protected bool $allowFullscreen = true;

    public function getMarkers(): array {
        return collect($devicePositions)->map(function ($devicePosition) {
            return MarkerData::make()
                ->id($employee->id)
                ->longitude($devicePosition['Position'][0])
                ->latitude($devicePosition['Position'][1])
                ->toArray();
        })->all();
    }
}

$lon = $lat = 0;
$center = [$lon, $lat];
$this->dispatch('maplibre--flyTo', $center);

return MarkerData::make()
    ->id($employee->id)
    ->longitude($devicePosition['Position'][0])
    ->latitude($devicePosition['Position'][1])
    ->avatarUrl($employee->getAvatarUrl())
    ->avatarIconSize(40)



namespace App\Filament\App\Widgets;

use App\Models\Employee;
use App\Models\User;
use NWNSoftware\Maplibre\Data\MarkerData;
use NWNSoftware\Maplibre\Widgets\MapLibreWidget;
use Filament\Infolists\Infolist;

class MapWidget extends MapLibreWidget {

    protected array $center = [0, 0];

    protected int $zoom = 9;

    public Model | string | null $model = Employee::class;

    public function getMarkers(): array {
        return collect($devicePositions)->map(function ($devicePosition) {
            return MarkerData::make()
                ->id($employee->id)
                ->longitude($devicePosition['Position'][0])
                ->latitude($devicePosition['Position'][1])
                ->toArray();
        })->all();
    }

    public function getInfolistSchema(Infolist $infolist): Infolist
    {
        return $infolist
            ->schema([
            ]);
    }
}

 MarkerData::make()
    ->id($employee->id)
    ->longitude($devicePosition['Position'][0])
    ->latitude($devicePosition['Position'][1])
    ->popupText("Here goes your HTML")
    ->toArray();

 MarkerData::make()
    ->id($employee->id)
    ->longitude($devicePosition['Position'][0])
    ->latitude($devicePosition['Position'][1])
    ->url("https://google.be")
    ->shouldOpenUrlInNewTab()
    ->toArray();
bash
php artisan vendor:publish --tag="maplibre-migrations"
php artisan migrate
bash
php artisan vendor:publish --tag="maplibre-config"
bash
php artisan vendor:publish --tag="maplibre-views"
bash
php artisan make:filament-widget MapWidget