Last active
February 9, 2022 12:17
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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