doublesecretagency / craft-googlemaps

Google Maps plugin for Craft CMS - Maps in minutes. Powered by the Google Maps API.
https://plugins.doublesecretagency.com/google-maps/
Other
10 stars 8 forks source link

Static map + markerPptions = Array to string conversion #29

Closed philipboomy closed 3 years ago

philipboomy commented 3 years ago

Hi

Great plugin. Almost make working with Google Maps a pleasure :)

I got markerOptions working with dynamic map but with static map I cant. I get this error Array to string conversion. See screenshot for more info. https://share.getcloudapp.com/2NuwLw77 - Is it a user error?

{% set options = {
    markerOptions: {
        icon: {
            url: '/assets/visuals/map-pin.png',
            scaledSize: {width: 25, height: 33}
        }
    },
} %}

{{ googleMaps.img(locations, options).tag() }}

As far as I can see then I should be able to pass in the options into a static map like I do on the dynamic map but perhaps I am wrong?

Thanks

lindseydiloreto commented 3 years ago

Looks like you may have discovered a bug. Thanks for the heads up!

I'll try to get this patched in the near future. 👍

lindseydiloreto commented 3 years ago

So it turns out this isn't a bug, it kinda is a user error (combined with confusing Google documentation). scaledSize is not actually a real property for the icon value of static maps... it's strictly a property of the icon value for dynamic maps.

In fact, for static maps, the icon value must be a string and nothing more (specifically an icon URL)...

{% set options = {
    markerOptions: {
        icon: '/assets/visuals/map-pin.png'
    }
} %}

The official Google docs are a bit scattered, but it looks like most of the information you need is here...

https://developers.google.com/maps/documentation/maps-static/start#CustomIcons

Reading through the docs, it appears that custom icons can't be assigned an arbitrary size. With a custom image, the image will appear in its natural dimensions. Non-custom markers allow you to specify a size, but obviously have several other limitations.

To be a bit more defensive, I've added a new error message for this scenario.

error@2x

Feel free to DM me on Discord if you want to chat in greater detail!

lindseydiloreto commented 3 years ago

Following up a bit more... each static map marker property must be a string. I've updated the screenshot above.

I guess I forgot this nuance from the documentation...

https://plugins.doublesecretagency.com/google-maps/models/static-map-model/#markers-locations-options

options@2x

The only one that isn't required to be a string is the field option. That's because the field gets parsed at the PHP level... everything else gets squashed down into the actual URL which Google uses to generate the image.

In other words, the string(s) you set in the markerOptions array will be sent directly to Google as part of the image URL.

philipboomy commented 3 years ago

Reading through the docs, it appears that custom icons can't be assigned an arbitrary size. With a custom image, the image will appear in its natural dimensions. Non-custom markers allow you to specify a size, but obviously have several other limitations.

As per your screenshot above I managed to use "scale" to make my png look high res.

Thank you for your very detailed replies.