Convert google maps style json to url arguments to use for google maps static images.
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 | |
public function mapStylesUrlArgs($mapStyleJson) | |
{ | |
$params = []; | |
foreach (json_decode($mapStyleJson, true) as $style) { | |
$styleString = ''; | |
if (isset($style['stylers']) && count($style['stylers']) > 0) { | |
$styleString .= (isset($style['featureType']) ? ('feature:' . $style['featureType']) : 'feature:all') . '|'; | |
$styleString .= (isset($style['elementType']) ? ('element:' . $style['elementType']) : 'element:all') . '|'; | |
foreach ($style['stylers'] as $styler) { | |
$propertyname = array_keys($styler)[0]; | |
$propertyval = str_replace('#', '0x', $styler[$propertyname]); | |
$styleString .= $propertyname . ':' . $propertyval . '|'; | |
} | |
} | |
$styleString = substr($styleString, 0, strlen($styleString) - 1); | |
$params[] = 'style=' . $styleString; | |
} | |
return implode("&", $params); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment