Skip to content

Commit

Permalink
Merge branch 'addColorIconMarker' into forkMain
Browse files Browse the repository at this point in the history
  • Loading branch information
Heyian committed Nov 14, 2024
2 parents e09326c + df58643 commit 20b2d0a
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions resources/js/filament-google-maps-widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
);
}
}
}
}
Expand Down

0 comments on commit 20b2d0a

Please sign in to comment.