@sv-tools/map-styles
v1.0.0
Published
Encode and decode the compact Google Maps style string format
Downloads
70
Readme
@sv-tools/map-styles
Encode and decode the compact Google Maps style string format.
import { parseGoogleMapsStyle, serializeGoogleMapsStyle } from '@sv-tools/map-styles'
serializeGoogleMapsStyle(styles: google.maps.MapTypeStyle[]): string
Stringify an array of styles. Invalid element types, feature types, and styler keys are all ignored.
import assert from 'node:assert'
const s = serializeGoogleMapsStyle([{
featureType: 'road.highway',
elementType: 'geometry.fill',
stylers: [
{ color: '#dc6b5f' },
{ saturation: 65 },
],
}])
assert(s === 's.t:49|s.e:g.f|p.c:#dc6b5f|p.s:65')
serializeGoogleMapsStyle(styles: google.maps.MapTypeStyle[]): string
Parse a style string. Incorrect syntax is silently ignored.
import assert from 'node:assert'
const styles = parseGoogleMapsStyle('s.t:49|s.e:g.f|p.c:#dc6b5f|p.s:65')
assert.deepEqual(styles, [{
featureType: 'road.highway',
elementType: 'geometry.fill',
stylers: [
{ color: '#dc6b5f' },
{ saturation: 65 },
],
}])
License
MIT · ⓒ 2023 Renée Kooi