davidpiesse / nova-map

Laravel Nova Map Field
114 stars 29 forks source link

Total Downloads Latest Stable Version

Map Field

This map field currently ONLY shows in details view

Gif!

You can use this Map Field with three different sort of spatial data:

Spatial Types

To specify what sort of spatial data you are passing to this field you MUST set the spatialType() for example

    ->spatialType('Point')

These are the valid Spatial Types

Examples

Point

Map::make('Some Point Field', 'point_field_name')
    ->spatialType('Point'),

Polygon

Map::make('Some Polygon Field', 'polygon_field_name')
    ->spatialType('Polygon'),

GeoJSON

Map::make('Some GeoJSON Field')
    ->spatialType('GeoJSON')
    ->geojson('geojson_field_name'),

Latitude & Longitude (in seperate fields)

Map::make('Some Point Location')
    ->spatialType('LatLon')
    ->latitude('latitude_field_name')
    ->longitude('longitude_field_name'),

Latitude & Longitude (in single fields)

Map::make('Some Point Location', 'coordinate_field_name')
    ->spatialType('LatLonField'),

Set the Height

Map::make('Some Point Field', 'point_field_name')
    ->spatialType('Point')
    ->height('300px'),

Setting up the Laravel Spatial Types

You need to install grimzy/laravel-mysql-spatial into your main application

composer require grimzy/laravel-mysql-spatial

Add the SpatialTrait to your Model

use SpatialTrait;

You then also need to set any spatial fields you have set in the Model

protected $spatialFields = [
    'geo_point',
    'geo_linestring',
    ...
];

Your Model is now ready to process spatial data to Nova

Future Development