davidpiesse / nova-map

Laravel Nova Map Field
114 stars 29 forks source link

Point is not displayed #7

Closed AGNICO closed 3 years ago

AGNICO commented 5 years ago

Hi, I have problem to display map point. I used default example from LaravelMysqlSpacial:

$place1->name = 'Empire State Building';
$place1->point = new Point(40.7484404, -73.9878441);

but if I use in Nova:

Map::make('Position', 'Empire State Building')
            ->spatialType('Point')

The map points somewhere to the middle of Atlantic ocean and point is not displayed.

'point' column in DB has value : 000000000101000000FBC275D6387F52C0A98020E5CC5F4440

davidpiesse commented 5 years ago

Hi @AGNICO , It is likely if your point is in the Atlantic it is at 0,0 (off the west coast of Africa). This could mean a few things:

The code for a Map field should be

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

I think your 'Empire State Building' field should refer to a DB column / model property.

Let me know what you find out :)

AGNICO commented 5 years ago

My Model.php

protected $spatialFields = [
        'geometry',
        'point',
        'line_string',
        'polygon',
        'multi_point',
        'multi_line_string',
        'multi_polygon',
        'geometry_collection'
    ];

My Nova/Model.php

Map::make('Position', 'point')
            ->spatialType('Point')
            ->height('300px'),

My Place.php model:

protected $spatialFields = [
        'geometry',
        'point',
        'line_string',
        'polygon',
        'multi_point',
        'multi_line_string',
        'multi_polygon',
        'geometry_collection'
    ];

My DB record (table places): id: 1 name: point geometry: null point: 000000000101000000FBC275D6387F52C0A98020E5CC5F4440 line_string: null other columns also null, only point column is not empty

The map still points to the Atlantic

davidpiesse commented 5 years ago

Hi!

Are you using the Spatial trait from Grimzy? https://github.com/grimzy/laravel-mysql-spatial

such as

class Place extends Model
{
    use SpatialTrait;

    protected $spatialFields = [
        'geometry',
        'point'
    ];
}
AGNICO commented 5 years ago

yes, of course

davidpiesse commented 5 years ago

Any errors in the console on the front end in Nova? Any way you can confirm it is at Null Island? https://en.wikipedia.org/wiki/Null_Island

AGNICO commented 5 years ago

No errors in console.

Yes, the map is centered at Null Island, but the point icon is missing.

davidpiesse commented 5 years ago

OK; The default center is [0,0].

If no error is being called then it must be running this.setCenter() once mounted.

Which means this is where the error/issue starts and the geojson prop is null.

if(this.geojson !== null){
    ...
}

this means that the value being passed to the map is null or is being left as the default (which is null)

return this.value

The value is set by

<map-detail 
    :type="field.spatialType" 
    :value="field.value"

Could you confirm that null is being sent to the page? It is contained within a XHR call /1 (the id of the record) and look into the field resource {resource->fields[x]->value}

I can't see where is it obviously going awry - so hoping to get a bit of insight :)

AGNICO commented 5 years ago

Yes, resource->fields[:id]->value is null

AGNICO commented 5 years ago

Also namespace for Model.php is not App\Model.php, but App\Models\Model.php, but I don't think this is an issue.

Anyway, nice package, thank you for your effort, hope we can solve this.

davidpiesse commented 5 years ago

Does your nova resource have the spatialfields property or the Spatial trait? It shouldn't have either.

Whatever is happening is passing a null value to the frontend. Just finding out where...

AGNICO commented 5 years ago

Nova resource does not have any SpatialTrait. Only 'Model.php' and Place.php have.

davidpiesse commented 5 years ago

@AGNICO is this still an issue? Just catching up on issues :)