### Complete Table Filter Setup with Radius Filter Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/_autodocs/06-radius-filter.md This example demonstrates a comprehensive table filter setup, including standard select filters and a fully configured radius filter within a 'Geographic Search' section. ```php protected function getTableFilters(): array { return [ Tables\Filters\SelectFilter::make('state') ->relationship('state', 'state_name'), Tables\Filters\SelectFilter::make('status') ->options([ 'active' => 'Active', 'inactive' => 'Inactive', ]), RadiusFilter::make('radius') ->latitude('latitude') ->longitude('longitude') ->selectUnit() ->section('Geographic Search'), ]; } ``` -------------------------------- ### Install Filament Google Maps Package Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/_autodocs/00-index.md Use Composer to install the package. Ensure you are using version ^3.0. ```bash composer require cheesegrits/filament-google-maps "^3.0" ``` -------------------------------- ### Install Filament Google Maps Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/_autodocs/16-quick-reference.md Use Composer to install the package and run Artisan commands to generate model code and publish configuration files. ```bash composer require cheesegrits/filament-google-maps "^3.0" php artisan filament-google-maps:model-code # Generate model code php artisan vendor:publish --tag="filament-google-maps-config" ``` -------------------------------- ### Basic StaticMapAction Setup Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/_autodocs/08-actions-static-map.md Add the StaticMapAction to your Filament table's bulk actions. ```php protected function getTableBulkActions(): array { return [ StaticMapAction::make(), ]; } ``` -------------------------------- ### Full MapTableWidget Example Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/_autodocs/05-map-table-widget.md This example demonstrates a comprehensive MapTableWidget, integrating custom data retrieval, table columns, filters (including MapIsFilter), and actions (including GoToAction). It shows how to configure clustering and set a widget heading. ```php getTableRecords() as $location) { if ($location->latitude && $location->longitude) { $data[] = [ 'location' => [ 'lat' => $location->latitude, 'lng' => $location->longitude, ], 'label' => $location->name, 'id' => $location->getKey(), ]; } } return $data; } // Implement MapTableWidget abstract methods protected function getTableQuery(): Builder { return Location::query(); } protected function getTableColumns(): array { return [ Tables\Columns\TextColumn::make('name') ->searchable(), Tables\Columns\TextColumn::make('city') ->searchable(), Tables\Columns\TextColumn::make('state'), Tables\Columns\TextColumn::make('phone') ->searchable(), Tables\Columns\TextColumn::make('email') ->searchable(), ]; } protected function getTableFilters(): array { return [ Tables\Filters\SelectFilter::make('state') ->relationship('state', 'state_name'), MapIsFilter::make('map'), ]; } protected function getTableActions(): array { return [ GoToAction::make() ->zoom(14), ]; } protected function getTableBulkActions(): array { return [ // Define any bulk actions here ]; } } ``` -------------------------------- ### Complete Marker Example with Custom SVG Icon Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/_autodocs/15-types-and-data-structures.md A complete example demonstrating how to structure marker data within the `getData()` method, including a custom SVG icon with specified dimensions. Ensure the icon URL is accessible. ```php protected function getData(): array { return [ [ 'location' => [ 'lat' => 40.7128, 'lng' => -74.0060, ], 'label' => 'New York', 'id' => 1, 'icon' => [ 'url' => url('images/ny-icon.svg'), 'type' => 'svg', 'scale' => [40, 40], ], ], ]; } ``` -------------------------------- ### Cache Configuration Example Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/_autodocs/03-map-column.md Configure the cache store and duration for static map images in your .env file. ```dotenv FILAMENT_GOOGLE_MAPS_CACHE_STORE=redis // Use dedicated Redis for heavy usage FILAMENT_GOOGLE_MAPS_CACHE_DURATION_SECONDS=2592000 // 30 days (max permitted by Google) ``` -------------------------------- ### API Reference Structure Example Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/_autodocs/README.md This markdown structure is used for each API reference, detailing component name, description, import statements, configuration methods, usage examples, and source reference. ```markdown # Component Name Description and purpose. ## Import ```php use Namespace\Class; ``` ## Configuration Methods | Method | Parameters | Default | Return | Description | |--------|-----------|---------|--------|-------------| ## Usage Examples Real-world code showing: - Basic usage - Intermediate patterns - Advanced configurations ## Source Reference File path and line numbers for verification. ``` -------------------------------- ### Basic Map Field Setup Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/_autodocs/01-map-field.md Initializes a basic map field. This is the starting point for configuring map fields in Filament. ```php use Cheesegrits\FilamentGoogleMaps\Fields\Map; Map::make('location') ``` -------------------------------- ### API Language Code Localization Example Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/_autodocs/12-configuration.md Apply localization to all API calls by setting the API language code. This example sets the language to Spanish. ```bash FILAMENT_GOOGLE_MAPS_API_LANGUAGE_CODE=es ``` -------------------------------- ### Install Filament Google Maps Package Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/README.md Install the package using composer. Ensure you have Laravel 9 and Filament V2 prerequisites met. ```sh composer install cheesegrits/filament-google-maps ``` -------------------------------- ### Complete Filament Google Maps Configuration File Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/_autodocs/12-configuration.md Example of the main configuration file (config/filament-google-maps.php) showing how to load settings from environment variables. It includes default values for many options. ```php env('GOOGLE_MAPS_API_KEY'), 'keys' => [ 'web_key' => env('FILAMENT_GOOGLE_MAPS_WEB_API_KEY', env('GOOGLE_MAPS_API_KEY')), 'server_key' => env('FILAMENT_GOOGLE_MAPS_SERVER_API_KEY', env('GOOGLE_MAPS_API_KEY')), 'signing_key' => env('FILAMENT_GOOGLE_MAPS_SIGNING_KEY', null), ], 'libraries' => env('FILAMENT_GOOGLE_MAPS_ADDITIONAL_LIBRARIES', ''), 'locale' => [ 'region' => env('FILAMENT_GOOGLE_MAPS_REGION_CODE', null), 'language' => env('FILAMENT_GOOGLE_MAPS_LANGUAGE_CODE', null), 'api' => env('FILAMENT_GOOGLE_MAPS_API_LANGUAGE_CODE', null), ], 'rate-limit' => env('FILAMENT_GOOGLE_MAPS_RATE_LIMIT', 150), 'log' => [ 'channel' => env('FILAMENT_GOOGLE_MAPS_LOG_CHANNEL', 'null'), ], 'cache' => [ 'duration' => env('FILAMENT_GOOGLE_MAPS_CACHE_DURATION_SECONDS', 60 * 60 * 24 * 30), 'store' => env('FILAMENT_GOOGLE_MAPS_CACHE_STORE', null), ], 'force-https' => env('FILAMENT_GOOGLE_MAPS_FORCE_HTTPS', false), ]; ``` -------------------------------- ### Environment Variables for Filament Google Maps Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/_autodocs/12-configuration.md Example .env file showing all available configuration variables for the Filament Google Maps package. These variables control API keys, localization, performance, and features. ```bash # API Keys GOOGLE_MAPS_API_KEY=AIzaSyD... FILAMENT_GOOGLE_MAPS_WEB_API_KEY=AIzaSyD... FILAMENT_GOOGLE_MAPS_SERVER_API_KEY=AIzaSyD... FILAMENT_GOOGLE_MAPS_SIGNING_KEY=secret_key_string # Localization FILAMENT_GOOGLE_MAPS_REGION_CODE=US FILAMENT_GOOGLE_MAPS_LANGUAGE_CODE=en FILAMENT_GOOGLE_MAPS_API_LANGUAGE_CODE=en # Performance FILAMENT_GOOGLE_MAPS_RATE_LIMIT=150 FILAMENT_GOOGLE_MAPS_CACHE_DURATION_SECONDS=2592000 FILAMENT_GOOGLE_MAPS_CACHE_STORE=redis # Features FILAMENT_GOOGLE_MAPS_ADDITIONAL_LIBRARIES=drawing,geometry FILAMENT_GOOGLE_MAPS_LOG_CHANNEL=maps FILAMENT_GOOGLE_MAPS_FORCE_HTTPS=false ``` -------------------------------- ### Language Code Localization Example Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/_autodocs/12-configuration.md Control result text localization using IETF BCP 47 language tags. This example sets the language code for server-side calls. ```text en, es, fr, de, ja, zh-CN, etc. ``` ```bash FILAMENT_GOOGLE_MAPS_LANGUAGE_CODE=es ``` -------------------------------- ### Marker Data Structure Example Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/_autodocs/10-widget-map-field.md Defines the required and optional fields for each marker object when using the markers() closure. ```php [ 'location' => [ 'lat' => 40.7128, 'lng' => -74.0060, ], 'label' => 'Marker Name', 'icon' => [ 'url' => 'https://example.com/marker.svg', 'type' => 'svg', 'scale' => [35, 35], ], ] ``` -------------------------------- ### Display Map Entry in Infolist Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/_autodocs/07-map-entry-infolist.md Configure the infolist schema to include a MapEntry component. This example demonstrates setting a 'name' and 'address' text entry, followed by a full-width MapEntry for 'location' with a specified height. ```php public function infolist(Infolist $infolist): { return $infolist ->schema([ TextEntry::make('name') ->columnSpan('full'), TextEntry::make('address') ->columnSpan(1), TextEntry::make('city') ->columnSpan(1), MapEntry::make('location') ->columnSpan('full') ->height('400px'), ]) ->columns(2); } ``` -------------------------------- ### Reverse Geocode Command Summary Output Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/_autodocs/13-artisan-commands.md An example of the command summary output after running the reverse geocode command, useful for saving and reference. ```text Results API Lookups: 2 Records Updated: 2 Command summary - you may wish to copy and save this somewhere! php artisan filament-google-maps:reverse-geocode Location --fields="street=%n %S" --fields="city=%L" ... ``` -------------------------------- ### WidgetMap with Custom Marker Icons Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/_autodocs/10-widget-map-field.md Applies custom icons to markers, including SVG support and scaling. This example fetches dealership data and assigns specific icons based on data. ```php WidgetMap::make('dealerships') ->markers(function () { $markers = []; Dealership::all()->each(function (Dealership $dealership) use (&$markers) { if ($dealership->latitude && $dealership->longitude) { $markers[] = [ 'location' => [ 'lat' => $dealership->latitude, 'lng' => $dealership->longitude, ], 'label' => $dealership->name, 'icon' => [ 'url' => url('images/dealership-marker.svg'), 'type' => 'svg', 'scale' => [40, 40], ], ]; } }); return $markers; }) ->columnSpan(2) ``` -------------------------------- ### Map Widget Code Example Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/README.md Example of a Filament Google Maps widget that displays dealership locations. It fetches data, formats it with location, label, and ID, and optionally includes custom icons. ```php latitude && $dealership->longitude) { /** * Each element in the returned data must be an array * containing a 'location' array of 'lat' and 'lng', * and a 'label' string. * * You should also aan 'id' attribute for internal use by this plugin. */ $data[] = [ 'location' => [ 'lat' => $dealership->latitude, 'lng' => $dealership->longitude, ], 'label' => $dealership->name, 'id' => $dealership->getKey(), /** * Optionally you can provide custom icons for the map markers, * either as scalable SVG's, or PNG, which doesn't support scaling. * If you don't provide icons, the map will use the standard Google marker pin. */ 'icon' => [ 'url' => url('images/dealership.svg'), 'type' => 'svg', 'scale' => [35,35], ], ]; } } return $data; } } ``` -------------------------------- ### Basic Geocomplete Field Setup Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/_autodocs/02-geocomplete-field.md Use this to create a basic Geocomplete field for address entry. It requires a name and can be customized with a label and placeholder text. ```php use Cheesegrits\FilamentGoogleMaps\Fields\Geocomplete; Geocomplete::make('full_address') ->label('Search Address') ->placeholder('Start typing an address...') ``` -------------------------------- ### Example Mapping for Reverse Geocoding Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/_autodocs/13-artisan-commands.md Define mappings between address components and format symbols for reverse geocoding. ```text street=%n %S city=%L state=%A1 zip=%z formatted_address=%n %S, %L, %z %a1 ``` -------------------------------- ### Region Code Localization Example Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/_autodocs/12-configuration.md Bias search results to a specific region using ISO-3166-1 alpha-2 codes. ```text US, GB, CA, AU, FR, DE, JP, CN, etc. ``` ```bash FILAMENT_GOOGLE_MAPS_REGION_CODE=US ``` -------------------------------- ### Basic Radius Filter Setup Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/_autodocs/06-radius-filter.md This snippet shows the basic configuration for a radius filter. It specifies the names of the latitude and longitude fields to be used for geocoding. ```php use Cheesegrits\FilamentGoogleMaps\Filters\RadiusFilter; protected function getTableFilters(): array { return [ RadiusFilter::make('radius') ->latitude('lat') ->longitude('lng'), ]; } ``` -------------------------------- ### Server Key Restrictions Example Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/_autodocs/12-configuration.md Restrict your server API key by IP address to allow access only from your server's IP. ```text 203.0.113.45 (Your server IP) ``` -------------------------------- ### Batch Reverse Geocoding Terminal Session Example Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/README.md This snippet demonstrates an interactive terminal session for configuring and executing the batch reverse geocoding command. It shows the prompts for table elements, address component mapping, and rate limiting, along with the final command summary. ```sh fgm> php artisan filament-google-maps:reverse-geocode Location Name of latitude element on table (e.g. `latitude`): > lat Name of longitude element on table (e.g. `longitude`): > lng Optional name of field to set to 1 when record is processed (e.g. `processed`) > processed +------------------------------+-------------------------+ | Component | Format | +------------------------------+-------------------------+ | Street Number | %n | | Street Name | %S | | City (Locality) | %L | | City District (Sub-Locality) | %D | | Zipcode (Postal Code) | %z | | Admin Level Name | %A1, %A2, %A3, %A4, %A5 | | Admin Level Code | %a1, %a2, %a3, %a4, %a5 | | Country | %C | | Country Code | %c | | Timezone | %T | +------------------------------+-------------------------+ Use the table above to enter your address component mapping. Google returns a complex set of address components. You need to tell us how you want those components mapped on to your database fields. We use a standard symbolic format as summarixed in the table above to extract the address components. Each mapping should be of the form =, for example to map (say) a street address to your `street_name` field, you would need ... street_name=%n %S ... and you might also add ... city=%L state=%A2 zip=%z ... or just ... formatted_address=%s %S, %L, %A2, %z You may enter as many mappings as you need, enter a blank line to continue. Test your field mapping. Yes. This is complicated. If you would like us to look up an example record from your table and show you what all those formats translate to, enter an ID here. If not, just press enter. ID (primary key on table): > 1 +--------+-------------------+ | Symbol | Result | +--------+-------------------+ | %n | 19225 | | %S | North 44th Avenue | | %L | Glendale | | %D | | | %z | 85308 | | %A1 | Arizona | | %A2 | Maricopa County | | %A3 | | | %A4 | | | %A5 | | | %a1 | AZ | | %a2 | Maricopa County | | %a3 | | | %a4 | | | %a5 | | | %C | United States | | %c | US | | %T | | +--------+-------------------+ Field mapping (e.g. city=%L), blank line to continue: > street=%n %S Field mapping (e.g. city=%L), blank line to continue: > city=%L Field mapping (e.g. city=%L), blank line to continue: > state=%A1 Field mapping (e.g. city=%L), blank line to continue: > zip=%z Field mapping (e.g. city=%L), blank line to continue: > formatted_address=%n %S, %L, %z %a1 Field mapping (e.g. city=%L), blank line to continue: > Rate limit as API calls per minute (max 300): > 100 Results API Lookups: 2 Records Updated: 2 Command summary - you may wish to copy and save this somewhere! php artisan filament-google-maps:reverse-geocode Location --fields="street=%n %S" --fields="city=%L" --fields="state=%A1" --fields="zip=%z" --fields="formatted_address=%n %S, %L, %z %a1" --lat=lat --lng=lng --processed=processed --rate-limit=100 ``` -------------------------------- ### Configure Map Options to Hide POI Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/README.md Overrides the getConfig method to add custom map configurations. This example demonstrates how to hide Points of Interest (POI) markers by modifying the map styles. ```php public function getConfig(): array { $config = parent::getConfig(); // Disable points of interest $config['mapConfig']['styles'] = [ [ 'featureType' => 'poi', 'elementType' => 'labels', 'stylers' => [ ['visibility' => 'off'], ], ], ]; return $config; } ``` -------------------------------- ### GeoJSON File Paths Configuration Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/_autodocs/07-map-entry-infolist.md When using the geoJson() method, file paths are relative to the specified storage disk. This example shows how to reference a file on the 'public' disk and another on a custom 'maps-data' disk. ```php // public/boundaries/city-zones.geojson ->geoJson('boundaries/city-zones.geojson', 'public') ``` ```php // storage/maps/service-areas.geojson (custom disk) ->geoJson('service-areas.geojson', 'maps-data') ``` -------------------------------- ### Basic WidgetMap with Dynamic Markers Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/_autodocs/10-widget-map-field.md Displays a map with markers fetched from a database. Ensure the Location model has latitude and longitude fields. ```php use Cheesegrits\FilamentGoogleMaps\Fields\WidgetMap; use App\Models\Location; WidgetMap::make('nearby_locations') ->markers(function () { $markers = []; Location::all()->each(function (Location $location) use (&$markers) { if ($location->latitude && $location->longitude) { $markers[] = [ 'location' => [ 'lat' => round(floatval($location->latitude), 8), 'lng' => round(floatval($location->longitude), 8), ], 'label' => $location->name, ]; } }); return $markers; }) ->columnSpan(2) ``` -------------------------------- ### Import MapsHelper Class Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/_autodocs/11-helpers.md Import the MapsHelper class to use its static methods. ```php use Cheesegrits\FilamentGoogleMaps\Helpers\MapsHelper; ``` -------------------------------- ### Publish Configuration File Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/_autodocs/12-configuration.md Publish the configuration file to customize default settings. This creates a config file in your project's config directory. ```bash php artisan vendor:publish --tag="filament-google-maps-config" ``` -------------------------------- ### Import GoToAction Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/_autodocs/09-actions-goto-and-radius.md Import the GoToAction class for use in Filament table actions. ```php use Cheesegrits\FilamentGoogleMaps\Actions\GoToAction; ``` -------------------------------- ### MapEntry with KML Layers Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/_autodocs/07-map-entry-infolist.md Demonstrates adding KML layers to a MapEntry by providing an array of KML file URLs. ```php MapEntry::make('location') ->layers([ 'https://googlearchive.github.io/js-v2-samples/ggeoxml/cta.kml', 'https://example.com/transit-routes.kml', ]) ->columnSpan(2) ``` -------------------------------- ### Import StaticMapAction Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/_autodocs/08-actions-static-map.md Import the StaticMapAction class for use in Filament table actions. ```php use Cheesegrits\FilamentGoogleMaps\Actions\StaticMapAction; ``` -------------------------------- ### Web Key Restrictions Example Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/_autodocs/12-configuration.md Restrict your web API key by HTTP Referrer pattern to allow access only from specified domains. ```text *.yourdomain.com/* ``` -------------------------------- ### Import MapEntry Component Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/_autodocs/07-map-entry-infolist.md Import the MapEntry class for use in Filament infolists. ```php use Cheesegrits\FilamentGoogleMaps\Infolists\MapEntry; ``` -------------------------------- ### Get Google Maps API URLs Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/_autodocs/11-helpers.md Retrieve Google Maps API URLs for browser-side or server-side use, with options to include specific libraries. ```php use Cheesegrits\FilamentGoogleMaps\Helpers\MapsHelper; // Get map API URLs $webUrl = MapsHelper::mapsUrl(); // For browser-side API $serverUrl = MapsHelper::mapsUrl(true); // For server-side API $withDrawing = MapsHelper::mapsUrl(false, ['drawing']); // With drawing library ``` -------------------------------- ### Set Google Maps API Key Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/_autodocs/00-index.md Add your Google Maps API key to the .env file for the package to use. ```bash # .env file GOOGLE_MAPS_API_KEY=AIzaSyD... ``` -------------------------------- ### Basic Geocoding and Reverse Geocoding Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/_autodocs/11-helpers.md Demonstrates how to perform simple geocoding of an address to coordinates and reverse geocoding of coordinates to a formatted address string. ```php use Cheesegrits\FilamentGoogleMaps\Helpers\Geocoder; $geocoder = new Geocoder(); // Simple geocoding $result = $geocoder->geocode('1600 Pennsylvania Avenue, Washington DC'); // Returns: ['lat' => 38.8976633, 'lng' => -77.0365739] // Reverse geocoding $address = $geocoder->reverse(['lat' => 40.7128, 'lng' => -74.0060]); // Returns: '279 Bedford Avenue, Brooklyn, NY 11211, USA' ``` -------------------------------- ### Custom Reverse Geocoding with Map Field Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/_autodocs/14-concerns-and-traits.md Example of using the `reverseGeocodeUsing` closure within a Map field to customize how reverse geocoding results are processed and set form values. ```php schema([ TextInput::make('name') ->required(), Map::make('location') ->reverseGeocodeUsing(function (callable $set, array $results) { // Custom reverse geocoding // Access $results['address_components'] array $set('street', $results['address_components'][0]['long_name']); }), TextInput::make('street'), TextInput::make('city'), ]); } } ``` -------------------------------- ### Import MapColumn Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/_autodocs/03-map-column.md Import the MapColumn class to use it in your Filament tables. ```php use Cheesegrits\FilamentGoogleMaps\Columns\MapColumn; ``` -------------------------------- ### Radius Filter within a Fieldset Section Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/_autodocs/06-radius-filter.md Organize the radius filter within a fieldset section for better UI organization. This example places the filter under a 'Location Search' section. ```php RadiusFilter::make('radius') ->latitude('lat') ->longitude('lng') ->section('Location Search') ->kilometers() ``` -------------------------------- ### Basic Map Widget with Clustering Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/_autodocs/04-map-widget.md Displays dealership locations on a map with marker clustering enabled. Requires a Dealership model with latitude and longitude fields. ```php each(function (Dealership $dealership) use (&$data) { if ($dealership->latitude && $dealership->longitude) { $data[] = [ 'location' => [ 'lat' => $dealership->latitude, 'lng' => $dealership->longitude, ], 'label' => $dealership->name, 'id' => $dealership->getKey(), 'icon' => [ 'url' => url('images/dealership.svg'), 'type' => 'svg', 'scale' => [35, 35], ], ]; } }); return $data; } } ``` -------------------------------- ### Map Field with Geolocate Button Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/_autodocs/01-map-field.md Adds a button to the map field that allows users to get their current location. The button label can be customized, and geolocating on initial form load can be disabled. ```php Map::make('location') ->geolocate() ->geolocateLabel('Get My Location') ->geolocateOnLoad(false) // Only on new forms ``` -------------------------------- ### Import MapWidget Class Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/_autodocs/04-map-widget.md Import the MapWidget class into your PHP file to use it. ```php use Cheesegrits\FilamentGoogleMaps\Widgets\MapWidget; ``` -------------------------------- ### Reverse Geocode a Single Coordinate Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/_autodocs/13-artisan-commands.md Use this command to get address components for a given latitude and longitude. The output table provides symbols to configure format strings for the `reverseGeocode()` configuration. ```bash php artisan filament-google-maps:reverse-geocode \ --lat=38.8976633 \ --lng=-77.0365739 ``` -------------------------------- ### Default Drawing Options Configuration Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/_autodocs/15-types-and-data-structures.md Sets the styling for drawing tools like polygons and rectangles. Includes color, opacity, and interactivity settings. ```php [ 'fillColor' => '#f06eaa', // Fill color (hex) 'strokeColor' => '#00ff00', // Border color (hex) 'strokeOpacity' => '0.5', // Border opacity (0-1) 'strokeWeight' => 3, // Border width (pixels) 'fillOpacity' => 0.45, // Fill opacity (0-1) 'draggable' => true, // Allow dragging 'editable' => false, // Allow editing 'clickable' => true, // Allow clicking ] ``` -------------------------------- ### WidgetMap with Custom Center and Zoom Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/_autodocs/10-widget-map-field.md Sets the initial center point and zoom level for the map. Requires a 'markers' callback to be defined. ```php WidgetMap::make('locations') ->center([40.7128, -74.0060]) // New York City ->zoom(12) ->markers(function () { // Return marker array... }) ``` -------------------------------- ### Get Field ID for Current Form Field Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/_autodocs/11-helpers.md Use getFieldId to retrieve the state path for a form field within the current form context. This method handles nested relationships automatically. ```php use Cheesegrits\FilamentGoogleMaps\Helpers\FieldHelper; // Get state path for field in current form $fieldId = FieldHelper::getFieldId('city', $this); // Returns: 'city' or 'parent.city' depending on nesting ``` -------------------------------- ### Import MapTableWidget Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/_autodocs/05-map-table-widget.md Import the MapTableWidget class into your PHP file to use it. ```php use Cheesegrits\FilamentGoogleMaps\Widgets\MapTableWidget; ``` -------------------------------- ### Import RadiusAction Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/_autodocs/09-actions-goto-and-radius.md Import the RadiusAction class for use in Filament table actions. ```php use Cheesegrits\FilamentGoogleMaps\Actions\RadiusAction; ``` -------------------------------- ### MapsHelper Configuration Methods Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/_autodocs/11-helpers.md Methods for retrieving Google Maps API keys, language, region, and constructing the API URL. ```APIDOC ## MapsHelper::mapsKey() ### Description Get web or server API key from config. ### Parameters - **server** (bool) - Optional - Whether to get the server API key. ### Return string - The Google Maps API key. ## MapsHelper::mapsSigningKey() ### Description Get static maps signing key if configured. ### Return string|null - The signing key or null if not configured. ## MapsHelper::hasSigningKey() ### Description Check if signing key is configured. ### Return bool - True if a signing key is configured, false otherwise. ## MapsHelper::mapsLanguage() ### Description Get language code for API calls. ### Parameters - **server** (bool) - Optional - Whether to get the server-side language code. ### Return string|null - The language code or null if not set. ## MapsHelper::mapsRegion() ### Description Get region code for search bias. ### Parameters - **server** (bool) - Optional - Whether to get the server-side region code. ### Return string|null - The region code or null if not set. ## MapsHelper::mapsUrl() ### Description Get complete Google Maps API URL with key and libraries. ### Parameters - **server** (bool) - Optional - Whether to get the server-side URL. - **libraries** (array) - Optional - An array of libraries to include (e.g., ['drawing']). ### Return string - The complete Google Maps API URL. ``` -------------------------------- ### Model Code for Location Attributes Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/_autodocs/13-artisan-commands.md This PHP code snippet can be added to your Eloquent model. It defines a `location` attribute to get and set latitude and longitude values, and a static method to retrieve attribute names. ```php use Illuminate\Database\Eloquent\Casts\Attribute; public function location(): Attribute { return Attribute::make( get: function () { return [ 'lat' => is_null($this->latitude) ? 0 : floatval($this->latitude), 'lng' => is_null($this->longitude) ? 0 : floatval($this->longitude), ]; }, set: function ($value) { $this->latitude = $value['lat'] ?? $value[0] ?? null; $this->longitude = $value['lng'] ?? $value[1] ?? null; } ); } public static function getLatLngAttributes(): array { return [ 'lat' => 'latitude', 'lng' => 'longitude', ]; } ``` -------------------------------- ### Performance Configuration Environment Variables Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/_autodocs/00-index.md Configure API call rate limits, caching behavior, and cache duration using these environment variables. Defaults are provided for convenience. ```bash FILAMENT_GOOGLE_MAPS_RATE_LIMIT # API calls/minute (default: 150) FILAMENT_GOOGLE_MAPS_CACHE_STORE # Cache driver (default: null) FILAMENT_GOOGLE_MAPS_CACHE_DURATION_SECONDS # Cache TTL (default: 2592000 = 30 days) ``` -------------------------------- ### Map Widget with Marker Action and Infolist Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/_autodocs/04-map-widget.md Configures a map widget to trigger a Filament Action when a marker is clicked, displaying detailed information in an infolist. Requires a Location model with latitude and longitude. ```php each(function (Location $location) use (&$data) { if ($location->latitude && $location->longitude) { $data[] = [ 'location' => [ 'lat' => $location->latitude, 'lng' => $location->longitude, ], 'label' => $location->name, 'id' => $location->getKey(), ]; } }); return $data; } public function markerAction(): Action { return Action::make('markerAction') ->label('View Details') ->infolist([ Card::make([ TextEntry::make('name'), TextEntry::make('address'), TextEntry::make('city'), TextEntry::make('state'), TextEntry::make('zip'), ])->columns(3), ]) ->record(function (array $arguments) { return array_key_exists('model_id', $arguments) ? Location::find($arguments['model_id']) : null; }) ->modalSubmitAction(false); } } ``` -------------------------------- ### Import FieldHelper Class Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/_autodocs/11-helpers.md Import the FieldHelper class to use its static methods. This is typically done at the beginning of your PHP file. ```php use Cheesegrits\FilamentGoogleMaps\Helpers\FieldHelper; ``` -------------------------------- ### Import WidgetMap Field Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/_autodocs/10-widget-map-field.md Import the WidgetMap class to use it in your Filament forms. ```php use Cheesegrits\FilamentGoogleMaps\Fields\WidgetMap; ``` -------------------------------- ### Feature Configuration Environment Variables Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/_autodocs/00-index.md Enable additional Google Maps JavaScript API libraries and configure logging or HTTPS enforcement through these environment variables. Defaults are provided. ```bash FILAMENT_GOOGLE_MAPS_ADDITIONAL_LIBRARIES # drawing, geometry, etc. FILAMENT_GOOGLE_MAPS_LOG_CHANNEL # Logging channel (default: 'null') FILAMENT_GOOGLE_MAPS_FORCE_HTTPS # Force HTTPS (default: false) ``` -------------------------------- ### Basic MapEntry in Filament Infolist Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/_autodocs/07-map-entry-infolist.md Demonstrates the basic integration of MapEntry within an Infolist schema to display location data. Ensure necessary components like TextEntry are also included. ```php use Cheesegrits\FilamentGoogleMaps\Infolists\MapEntry; use Filament\Infolists\Components\TextEntry; public function infolist(Infolist $infolist): Infolist { return $infolist->schema([ TextEntry::make('name'), TextEntry::make('street'), TextEntry::make('city'), TextEntry::make('state'), TextEntry::make('zip'), MapEntry::make('location') ->columnSpan(2), ]); } ``` -------------------------------- ### MapEntry with GeoJSON Layers Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/_autodocs/07-map-entry-infolist.md Illustrates how to add GeoJSON layers to a MapEntry. Specify the GeoJSON file path and its associated key for loading. ```php MapEntry::make('location') ->height('450px') ->defaultZoom(12) ->geoJson('boundaries/city-zones.geojson', 'maps-data') ->geoJsonVisible(true) ->columnSpan(2) ``` -------------------------------- ### Core Configuration Environment Variables Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/_autodocs/00-index.md Set these environment variables to configure the primary API key and optional browser/server keys for Google Maps integration. The signing key is used for static maps. ```bash GOOGLE_MAPS_API_KEY # Primary API key FILAMENT_GOOGLE_MAPS_WEB_API_KEY # Browser key (optional) FILAMENT_GOOGLE_MAPS_SERVER_API_KEY # Server key (optional) FILAMENT_GOOGLE_MAPS_SIGNING_KEY # Static maps signing (optional) ``` -------------------------------- ### Import RadiusFilter Class Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/_autodocs/06-radius-filter.md Import the RadiusFilter class to use it in your Filament table filters. ```php use Cheesegrits\FilamentGoogleMaps\Filters\RadiusFilter; ``` -------------------------------- ### Custom StaticMapAction Configuration Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/_autodocs/08-actions-static-map.md Customize the label, color, icon, confirmation, and modal details for the StaticMapAction. ```php StaticMapAction::make() ->label('Generate Map') ->color('success') ->icon('heroicon-o-map') ->requiresConfirmation() ->modalHeading('Create Static Map') ->modalButton('Download') ``` -------------------------------- ### Generate Model Code Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/_autodocs/00-index.md Run this artisan command to generate necessary code for your models. Follow the interactive prompts. ```bash php artisan filament-google-maps:model-code ``` -------------------------------- ### Using Address Components in reverseGeocodeUsing Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/_autodocs/15-types-and-data-structures.md Demonstrates how to extract specific address components like street number and name within the `reverseGeocodeUsing` callback. ```php ->reverseGeocodeUsing(function (callable $set, array $results) { foreach ($results['address_components'] as $component) { if (in_array('street_number', $component['types'])) { $set('street_number', $component['long_name']); } if (in_array('route', $component['types'])) { $set('street_name', $component['long_name']); } } }) ``` -------------------------------- ### Default Cache Configuration Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/_autodocs/12-configuration.md Configure the default cache duration to 30 days (2592000 seconds) and use the default cache driver. ```php FILAMENT_GOOGLE_MAPS_CACHE_DURATION_SECONDS=2592000 FILAMENT_GOOGLE_MAPS_CACHE_STORE=null // Uses default cache driver ``` -------------------------------- ### MapIsFilter Import Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/_autodocs/16-quick-reference.md Import the MapIsFilter class for filtering based on map properties. ```php use Cheesegrits\FilamentGoogleMaps\Filters\MapIsFilter; ``` -------------------------------- ### Configure Map Field Options Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/_autodocs/16-quick-reference.md Chain methods to configure display, interaction, geocoding, geolocating, layers, drawing, and debugging for the Map field. ```php Map::make('location') ->height('400px') // Display ->defaultZoom(10) ->defaultLocation([40.7128, -74.0060]) ->type('hybrid') ->mapControls([...]) ->draggable() // Interaction ->clickable() ->autocomplete('address') // Geocoding ->autocompleteReverse() ->reverseGeocode(['city' => '%L']) ->reverseGeocodeUsing(fn() => {}) ->placeUpdatedUsing(fn() => {}) ->geolocate() // Geolocating ->geolocateLabel('My Location') ->geolocateOnLoad(true, false) ->layers(['https://...']) ->geoJson('file.geojson') ->geoJsonContainsField('zone') ->geoJsonVisible(false) ->drawingControl() ->drawingModes([...]) ->drawingField('shapes') ->polyOptions([...]) ->debug() // Debugging ``` -------------------------------- ### Geocode Address with Multiple Output Formats Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/_autodocs/13-artisan-commands.md Demonstrates using the `fgm:geocode` command with flags to output geocoded address data as a PHP array, Closure, and GeoJSON. This is useful for testing different output requirements. ```bash $ php artisan fgm:geocode --address="1600 Pennsylvania Avenue NW, Washington, DC" -A -C -G lat: 38.8976633 lng: -77.0365739 [ 'lat' => 38.8976633 'lng' => -77.0365739 ] --lat=38.8976633 --lng=-77.0365739 { "type": "Point", "coordinates": [-77.0365739, 38.8976633] } ``` -------------------------------- ### Configure Radius Action with Relationship and Icon Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/README.md Customize the RadiusAction by specifying a relationship for locations and overriding the default color and icon. ```php use Cheesegrits\FilamentGoogleMaps\Actions\RadiusAction; // protected function getTableActions(): array { return [ // RadiusAction::make() ->relationship('location') ->color('primary') ->icon('heroicon-m-map'), ]; } ``` -------------------------------- ### Configure Geocomplete Field Options Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/_autodocs/16-quick-reference.md Chain methods to set the mode, constraints, user location, component handling, performance, and text field properties for the Geocomplete field. ```php Geocomplete::make('address') ->isLocation() // Mode ->geocodeOnLoad() ->updateLatLng() ->types(['address']) // Constraints ->countries(['us', 'ca']) ->placeField('name') ->geolocate() ->geolocateIcon('heroicon-o-map-pin') ->reverseGeocode([...]) // Components ->reverseGeocodeUsing(fn() => {}) ->minChars(3) // Performance ->debug() ->placeholder('Search...') // Text Field Methods ->maxLength(255) ``` -------------------------------- ### Alias Commands for Filament Google Maps Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/_autodocs/13-artisan-commands.md Provides a list of all available Artisan commands with their short aliases, prefixed by 'fgm:'. These aliases offer a convenient way to access the package's functionalities. ```bash php artisan fgm:model-code ``` ```bash php artisan fgm:geocode ``` ```bash php artisan fgm:reverse-geocode ``` ```bash php artisan fgm:geocode-table ``` ```bash php artisan fgm:reverse-geocode-table ``` ```bash php artisan fgm:make-widget ``` -------------------------------- ### Configure MapColumn Display Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/_autodocs/16-quick-reference.md Set display and rendering properties for the MapColumn, including height, width, zoom level, map type, and attributes. ```php MapColumn::make('location') ->height(150) ->width(250) ->size(200) // Sets both ->zoom(13) ->type('satellite') ->icon('https://...') ->ttl(2592000) ->extraAttributes(['class' => '...']) ->extraImgAttributes([...]) ``` -------------------------------- ### Geocode Single Address with Options Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/_autodocs/13-artisan-commands.md This command is a helper for testing geocoding of a single address. It accepts an address and can output the results in various formats like PHP array, Closure, or GeoJSON. ```bash php artisan filament-google-maps:geocode \ --address="1600 Pennsylvania Avenue NW, Washington, DC 20500" ``` -------------------------------- ### Map Field Constructor Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/_autodocs/01-map-field.md Instantiate the Map field using its make method. The field name must correspond to a computed attribute on your model that combines latitude and longitude into a Google Point format. ```php Map::make(string $fieldName): static ``` -------------------------------- ### Static Map Bulk Action Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/README.md Add a static map bulk action to a Filament table to generate downloadable static maps of selected locations. ```php use Cheesegrits\FilamentGoogleMaps\Actions\StaticMapAction; // ->bulkActions([ // StaticMapAction::make(), // ]); // ``` -------------------------------- ### Configure Table Records Per Page Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/_autodocs/05-map-table-widget.md Set the number of records to display per page in the associated table. Omit this to use Filament's default. ```php // In your widget class protected static ?int $tableRecordsPerPage = 10; ``` -------------------------------- ### Default Map Control Configuration Source: https://github.com/cheesegrits/filament-google-maps/blob/v3/_autodocs/15-types-and-data-structures.md Defines the visibility of various map controls. Set to true to display, false to hide. ```php [ 'mapTypeControl' => true, // Map type selector (satellite, roadmap, etc.) 'scaleControl' => true, // Scale indicator 'streetViewControl' => true, // Street view toggle 'rotateControl' => true, // Rotation control 'fullscreenControl' => true, // Fullscreen toggle 'searchBoxControl' => false, // Search box (if autocomplete enabled) 'zoomControl' => true, // Zoom buttons ] ```