diff --git a/resources/js/filament-google-maps-widget.js b/resources/js/filament-google-maps-widget.js index 17ca230..a1ff4ae 100644 --- a/resources/js/filament-google-maps-widget.js +++ b/resources/js/filament-google-maps-widget.js @@ -144,13 +144,28 @@ export default function filamentGoogleMapsWidget({ if ( location.icon.hasOwnProperty("type") && - location.icon.type === "svg" && - location.icon.hasOwnProperty("scale") + location.icon.type === "svg" ) { - markerIcon.scaledSize = new google.maps.Size( - location.icon.scale[0], - location.icon.scale[1] - ); + if (location.icon.hasOwnProperty("color")) { + fetch(location.icon.url) + .then(response => response.text()) + .then(svgContent => { + const coloredSvg = svgContent.replace(/fill="[^"]*"/g, `fill="${location.icon.color}"`); + + const svgBlob = new Blob([coloredSvg], { type: 'image/svg+xml' }); + const svgUrl = URL.createObjectURL(svgBlob); + + markerIcon.url = svgUrl; + marker.setIcon(markerIcon); + }); + } + + if (location.icon.hasOwnProperty("scale")) { + markerIcon.scaledSize = new google.maps.Size( + location.icon.scale[0], + location.icon.scale[1] + ); + } } } }