Skip to content

Instantly share code, notes, and snippets.

@carmoreira
Last active February 9, 2022 12:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carmoreira/f9040d8f575b60e3c5f04ab2ff84db71 to your computer and use it in GitHub Desktop.
Save carmoreira/f9040d8f575b60e3c5f04ab2ff84db71 to your computer and use it in GitHub Desktop.
Add Lines and markers to the map on the fly with PHP - Interactive Geo Maps
<?php
add_filter( 'igm_add_meta', 'igm_lines_on_the_fly', 1 );
function igm_lines_on_the_fly( $meta ){
// point 1
$lat01 = floatval( '-7.508726' );
$lon01 = floatval( '-36.119106' );
// point 2
$lat02 = floatval('40.833240' );
$lon02 = floatval('-8.231797' );
// add markers
if( empty( $meta['roundMarkers'] ) ){
$meta['roundMarkers'] = [];
}
// add first marker
$meta['roundMarkers'][] = [
'id' => 'MyMaker01',
'latitude' => $lat01,
'longitude' => $lon01,
'tooltipContent' => 'Tooltip for marker 01',
'useDefaults' => '1',
];
// add second marker
$meta['roundMarkers'][] = [
'id' => 'MyMaker01',
'latitude' => $lat02,
'longitude' => $lon02,
'tooltipContent' => 'Tooltip for marker 02',
'useDefaults' => '1',
];
// add the line connecting the markers
if( empty( $meta['lines'] ) ){
$meta['lines'] = [];
}
$meta['lines'][] = [
'title' => 'myLine',
'multiGeoLine' => [
[
'latitude' => $lat01,
'longitude' => $lon01,
],
[
'latitude' => $lat02,
'longitude' => $lon02,
],
],
'useDefaults' => '1',
];
return $meta;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment