poldixd/json-mapstyle-converter

Converts Google Maps JSON Style to Google Maps Static Maps Style

0.1.0 2021-02-05 10:23 UTC

This package is auto-updated.

Last update: 2024-05-05 17:19:47 UTC


README

Converts JSON Style Schemes for Google Maps to Styles for Google Static Maps.

From this:

[
  {
    "elementType": "geometry",
    "stylers": [
      {
        "color": "#212121"
      }
    ]
  },
  {
    "elementType": "labels.icon",
    "stylers": [
      {
        "visibility": "off"
      }
    ]
  }
]

To this:

&style=element:geometry|color:0x212121&style=element:labels.icon|visibility:off

You can use JSON Style Schemes from snazzymaps.com or mapstyle.withgoogle.com.

I converted this JavaScript Tool to a PHP Class.

Usage

$converter = new poldixd\JsonMapstyleConverter\JsonMapstyleConverter();

echo $converter->convert('[{"elementType": "geometry", "stylers": [ { "color": "#212121"}]},{"elementType": "labels.icon","stylers": [ {"visibility": "off"}]}]');

// &style=element:geometry|color:0x212121&style=element:labels.icon|visibility:off