I am using SVG path notation to create markers along with a polyline using Google Maps API v3. Sometimes, after adding a few markers, they just stop showing from the map. If I pan the map, even just 1px, they show again.
SVG markers stop showing after adding a few
SVG markers show again after pan
This happens in FF, Safari, Chrome and iPhone browsers.
Here is my code for the polyline:
var lineSymbol = {
path: g.SymbolPath.FORWARD_OPEN_ARROW,
scale:1.5
};
polyOptions = {
strokeColor: '#0026b3',
strokeOpacity: 1.0,
strokeWeight: 1,
geodesic: true,
icons: [{
icon: lineSymbol,
repeat: '100px'
}],
zIndex: 10
};
polyLine = new g.Polyline(polyOptions);
polyLine.setMap(map);
And the code for the SVG marker:
var path = polyLine.getPath();
path.push(event.latLng);
var icon = {
path: "M68.501,23.781 43.752,48.529 66.918,71.695 66.918,120.362 70.085,120.362 70.085,71.694 93.249,48.529",
fillColor: iconColor,
fillOpacity: .8,
anchor: new g.Point(70.085, 120.362),
strokeWeight: 0,
scale:.4
};
var marker = new g.Marker({
position: event.latLng,
map: map,
draggable: false,
icon: icon,
title: title,
zIndex : -20
});
Any idea why my markers just vanish when they actually are on the map? Thanks in advance.
Here is a fiddle where you can reproduce the problem: http://jsfiddle.net/upsidown/gNQRB/
Here is a YT video to illustrate the issue: https://www.youtube.com/watch?v=uGAiwAuasmU
Edit:
A bug report has been created at Google: http://code.google.com/p/gmaps-api-issues/issues/detail?id=5351
First, remember we are playing with Google maps and SVG, so we must accomodate the way in which Google deploys it's implementation of SVG for markers (or actually symbols). Google sets its anchor for the SVG marker image at 0,0 which IS NOT the upper left corner of the SVG viewBox.
2048 characters in URL is just under 100 GeoCode values. So, again no more than 100 markers.
Works for me, tested with Chrome (Windows) Version 26.0.1410.64
However, few things to try out:
zIndex -20
google.maps.event.trigger(map, 'drag');
google.maps.event.trigger(marker, 'icon_changed');
Here is JS fiddle where I tried some of these things.
Edit:
After several tests I noticed that using map.panTo(latLng);
instead of map.setCenter(latLng);
makes SVG markers to draw correctly. Alternatively, if you dont want to pan to center, using map.panBy(x, y);
as 1 pixel and then back to previous center (fast) might have similar effect of solving this problem.
Here is JS fiddle to see that in action.
I had the same problem using png markers icons for markers, some times after fitBounds (some markers disappears and they appear when I zoom-in) and only dissappears if I make this markers draggables.
I tried this:
map.panTo(map.getCenter());
after setting markers draggables. And now it works fine.
It seem a bug on the V3 implementation.
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