3

I have successfully got Smart Map up & running and now want to tailor it for my own purposes.

I will have hundreds of markers for businesses, which I am categorising via fields in Craft. What I would love to do is pass custom options to the markers on an individual basis. E.g.:

Marker 1 - Business-type: Retail; Market-sector: Domestic, Educational; Products: Chair, Table, Upholstery.

Marker 2 - Business-type: Manufacturer; Market-sector: Office, Children; Products: Soft seating, Divider panels.

As you see there are 3 keys with multiple values in each.

-

I know I can pass custom options into the map using the API, but can it be done manually in conjunction with the plugin?

It is possible to pass information per-marker for the info Bubble, but I don't see anything in the documentation about custom option data.

  • I see somebody else has manually passed in data per marker in a loop, but this is not using the Smart Map plugin. craftcms.stackexchange.com/a/9664/3991 – Adam Menczykowski Dec 1 '15 at 17:04
  • You can access every property via a variable "element" in the marker template. But I probably didn't really get what you're asking. – carlcs Dec 1 '15 at 18:28
  • Thanks @carlcs - I am using the element variable for my infoWindow. Can I pass the element variable into the markerOptions? – Adam Menczykowski Dec 1 '15 at 20:14
  • Sorry, I thought that's what you're after, adding markup to the marker's info window. I've no clue what markerOptions config is good for. – carlcs Dec 1 '15 at 20:17
  • OK Not to worry, thanks for offering assistance @carlcs – Adam Menczykowski Dec 1 '15 at 21:28
3

OK So without being too verbose about this, here is how I managed to attach information to each marker.

  1. It is important to remember that each marker has an ID which corresponds to the entry / user that it is derived from. Using javascript, I created a small function that when given a numeric ID, it creates the smartmap ID by prepending adn appending characters to the ID. So 43 would return smartmap-mapcanvas-1.43.memberAddress in my case.
  2. Using that function as a building block, I was able to create a craft loop on my template that queries the user, gets their id, gets the relevant information, and then using javascript to apply it to the matching id marker.
  3. Google markers are just javascript objects. So you can add anything to them.... Strings, Arrays, Objects, whatever... Then use javascript to query that extra

If anyone needs help, hit me up and I'll happily share my code.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.