davidpiesse / nova-map

Laravel Nova Map Field
114 stars 29 forks source link

Cannot read property 'long' of null #4

Closed packytagliaferro closed 5 years ago

packytagliaferro commented 5 years ago

Just recently my map stopped working. On my resource I have


Map::make('Location')
                ->spatialType('LatLon')
                ->latitude('lat')
                ->longitude('long')
                ->height('300px'),

in my model:

use SpatialTrait;

...

protected $spatialFields = [ 'geo_latlon'];

my fields lat and long do have coordinates in them but get the errors:

Cannot read property 'long' of null
Cannot read property 'mapObject' of undefined
davidpiesse commented 5 years ago

How odd. Is there any instance of null in the long field? It may be a Nova update (there have been 20+ since I first built this). D

bernhardh commented 5 years ago

Same here, thats why I switched to POINT field, instead of 2 separete fields.

I am just wondering, how 2 fields should work, since there is no option to use separate lat/lng fields in laravel-mysql-spatial. I meanprotected $spatialFields = [ 'geo_latlon']; isn't connected in any means with the separate fields lat or long.

davidpiesse commented 5 years ago

When using two seperate lat long fields it does not need to use the spatialfields protected variable.

@bernhardh have you got any more info for me to work with? Could you post a snippet of the migration relevant to these fields and your nova service provider code?

bernhardh commented 5 years ago

Not sure what would help, but basically I have tried the same as packy..

 Map::make('Karte')
                    ->spatialType('LatLon')
                    ->latitude('lat')
                    ->longitude('lng')
                    ->height("300px"),

And thats the field definition of mysql

image

And thats the complete error:

image

bernhardh commented 5 years ago

Ok, found the error - and its basically a documentation error ;)

Use ->spatialType('LatLong') instead of ->spatialType('LatLon') and it works.

davidpiesse commented 5 years ago

Ahhh! I'll fix this tonight

packytagliaferro commented 5 years ago

I got the map to once again show using @bernhardh solution but still no coordinates. The map lat long is showing as undefined when I check out the map.js. So the map now just shows some random part of the ocean

bernhardh commented 5 years ago

Can you maybe provide table definition and the content of the lat/long field of your SQL Table? Btw. "long" is not an ideal name for a column, since its a reserved word in sql.

packytagliaferro commented 5 years ago

I can change it to Lon but as of right now:

$table->decimal('lat', 10, 7)->nullable();
$table->decimal('long', 10, 7)->nullable();

Lat: 47.7625209 Long: -116.7858218

It was working a few weeks ago

bernhardh commented 5 years ago

Ok. I can reproduce your error and have no clue whats wrong.

With ->spatialType('Point') its working

davidpiesse commented 5 years ago

I have MacOS upgrade woes - I will try and work out the issue tomorrow once I am back up and able to run PHP!

davidpiesse commented 5 years ago

Right

          return {
                    type: 'Point',
                    coordinates: [
                        this.value[this.longitude_field],
                        this.value[this.latitude_field],
                    ]
                }

This worked before but a change in Nova has broken this. Before this.value gave a js object with all the resources values (including the other fields); Now it doesn't...

It is passed in as a prop

:value="field.value"

and now that is where I see the issue

value: null 

Any clues/thoughts before I dive into this tomorrow?

D

davidpiesse commented 5 years ago

OK! I have made a fix! @bernhardh and @packytagliaferro could you pull from dev-master and see if it works before I create a new release?

Thanks

packytagliaferro commented 5 years ago

@davidpiesse I can confirm it worked on my setup with

 Map::make('Location')
                ->spatialType('LatLon')
                ->latitude('lat')
                ->longitude('long')
                ->height('300px'),
davidpiesse commented 5 years ago

Awesome I'll push a release tonight

davidpiesse commented 5 years ago

Pushed new release 0.0.4

bernhardh commented 5 years ago

Sorry for late answer. Yes, now its working. Thank you!