Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MapTableWidget not reacting to Table Radius Filter - Flickers and re-centers #95

Open
chrisscalzo opened this issue Apr 18, 2024 · 3 comments

Comments

@chrisscalzo
Copy link

maptablewidget-radius-bug-animated

The MapTableWidget isn't reacting to the Location Radius Filter in the table. I have been able to reproduce this issue in both the Location Resource from the test project repository < https://github.com/cheesegrits/fgm > and when I implement the MapTableWidget in my personal project.

Steps to Reproduce

  1. Implement the MapTableWidget following the documentation - or download and install the test project
  2. When using the MapTableWidget set the following properties:

class LocationMapTableWidget extends MapTableWidget
{
protected static ?string $heading = 'Location Map';

protected static ?int $sort = 1;

protected static ?string $pollingInterval = null;

protected static ?bool $clustering = true;

protected static ?bool $fitToBounds = true;

protected static ?string $mapId = 'incidents';

protected static ?bool $filtered = true;

protected static bool $collapsible = true;

public ?bool $mapIsFilter = true
  1. When the page is rendered it appears fine, the map shows locations for the records in the table.

  2. Attempt to filter the table using the address of the first record that appears in the table. The table doesn't react and stays the same. The map flickers then recenters to a default location.

  3. You can't reset the filter you need to refresh the entire web page to get back to the default state when the page first loads.

@ryanmortier
Copy link
Contributor

Same issue, you figure out the solution?

@chrisscalzo
Copy link
Author

Same issue, you figure out the solution?

Not yet, but will be trying next week as I will need mapping capabilities in the next app I'm building.

@ryanmortier
Copy link
Contributor

I ended up figuring it out partially. I had to override the filter with my own class and add the ->updateLatLng() method onto the Geocomplete field. It still flickers and makes several round trips to the server, but it works.

<?php

namespace App\Filters;

use Cheesegrits\FilamentGoogleMaps\Fields\Geocomplete;
use Filament\Forms\Components\Fieldset;
use Filament\Forms\Components\Group;
use Filament\Forms\Components\Hidden;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;

class RadiusFilter extends \Cheesegrits\FilamentGoogleMaps\Filters\RadiusFilter
{
    public function getFormSchema(): array
    {
        $form = [
            Group::make()->schema([
                Geocomplete::make('geocomplete')
                    ->label(__('filament-google-maps::fgm.radius_filter.address'))
                    ->filterName($this->getName())
                    ->updateLatLng()
                    ->lazy(),
                Group::make()->schema([
                    TextInput::make('radius')
                        ->label(__('filament-google-maps::fgm.radius_filter.distance'))
                        ->numeric()
                        ->default($this->getRadius() ?? 10)
                        ->lazy(),
                    Select::make('unit')
                        ->label(__('filament-google-maps::fgm.radius_filter.unit'))
                        ->options([
                            'mi' => __('filament-google-maps::fgm.radius_filter.miles'),
                            'km' => __('filament-google-maps::fgm.radius_filter.kilometers'),
                        ])
                        ->default(
                            $this->getKilometers() ? 'km' : 'mi'
                        )
                        ->visible(fn () => $this->getSelectUnit()),
                ])
                    ->columns($this->getSelectUnit() ? 2 : 1),
                Group::make()->schema([
                    Hidden::make('latitude'),
                    Hidden::make('longitude'),
                ]),
            ])
                ->columnSpan('full'),
        ];

        if ($this->hasSection()) {
            $form = [
                Fieldset::make($this->getSection())->schema($form),
            ];
        }

        return $form;
    }

    private function hasSection(): bool
    {
        return ! empty($this->getSection());
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants