kirby tag
once you have installed the plugin you can use the styledmapkirby tag inside the panel (inside any content textarea) so no php required at all. if you want styling you can either upload a json file to the content folder or create a snippet. the snippet does not contain any real php mostly just the json – see example provided.
config
of course you still have to get an google map api key and add it to your /site/config/config.php.
thank you very much for your kind response! I didn´t want to sound rude, the error is on my side: I completely oversaw, that your plugin gives me a tag, that I can use in panel text fields. Now I see, how to use your examples that I erroneously described as “pseudo-code”.
Now its up to me, to use it the right way: I have an overview page/template “projects” with many children “project”. I would like to show a map on the overwiew page with markers for all children. I think, I have to build a snippet, looping through all children and collecting lat, lng, title and a link. Building this multi-dimensional associative array will be the real challenge for me.
you need to replace title with something like $page->title()->value() or another field
you can omit/delete the icon and info if you do not need them
try something like this.
$markers = array();
foreach($projects as $project) {
// custom
$markers[] =
[ 'title' => 'Makaiwa Beach Park', // $project->title()->value()
'lat' => 21.347355,
'lng' => -158.127777,
// get an icon from somewhere. could be a svg too.
'icon' => site()->url() . '/assets/plugins/kirby-styledmap/sm-example-icon.svg',
// open url on click
'info' => 'https://www.google.de/maps/place/Makaha+Beach+Park/@21.3569219,-158.1442995,12z',
];
// or with kirby tag field (named in my case 'location')
$projectmarker =
[ 'title' => 'Makaiwa Beach Park',
// get an icon from somewhere. could be a svg too.
'icon' => site()->url() . '/assets/plugins/kirby-styledmap/sm-example-icon.svg',
// open url on click
'info' => 'https://www.google.de/maps/place/Makaha+Beach+Park/@21.3569219,-158.1442995,12z',
];
$markers[] = array_merge($projectmarker, $project->location()->yaml()); // https://github.com/AugustMiller/kirby-map-field#usage
}
echo a::json($markers);
this looks very promising, thank you so much! I will try it, as soon as possible - for the next hours I´m traveling by train with very spotty internet access.
ah yes. the field object can not be converted into a string when calling a::json – thats why $field->value() is needed. you could also wrap it into a trim($field) etc. to trigger string conversion.