Why my svg icons for google.maps.Marker are cut off? I tried many of combinations with size and scaledSize...
var marker = new google.maps.Marker({
position: new google.maps.LatLng({lat: el.lat, lng: el.lon}),
icon: {
url: "/images/icons/observation_" + el.rate + ".svg",
size: new google.maps.Size(20, 20),
origin: new google.maps.Point(0, 0),
anchor: new google.maps.Point(10, 10),
scaledSize: new google.maps.Size(20, 20)
},
zIndex: 6,
map: map.map
});
Svg icons should by 20x20 px.
https://jsfiddle.net/d3v5huzr/
Here is preview:
You have to set width and height attributes of the svg element like this:
<svg height="40px" width="40px" ... >
https://jsfiddle.net/zvtnohyv/
You can use zoom_changed
from events and add event Listener, for refreshing the marker icon on zoom
Fiddle Demo
Code below
var map;
map = new google.maps.Map(document.getElementById('map'), {
center: {
lat: -34.397,
lng: 150.644
},
zoom: 8
});
var icon = {
url: "http://svgshare.com/i/1jz.svg",
}
var marker = new google.maps.Marker({
position: new google.maps.LatLng({
lat: -34.397,
lng: 150.644
}),
icon: icon,
/*icon: {
url: "http://svgshare.com/i/1jz.svg",
// size: new google.maps.Size(20, 20),
// origin: new google.maps.Point(5, 5),
// anchor: new google.maps.Point(10, 10),
// scaledSize: new google.maps.Size(20, 20)
},*/
zIndex: 6,
map: map
});
google.maps.event.addListener(map, 'zoom_changed', function() {
marker.setIcon(icon);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With