Google map custom marker with css rounded corner
As of version 3.17, the google.maps.Marker objects exists in the markerLayer
pane which is just a fancy name for a div.
To get a reference to the markerLayer you need to create an OverlayView Object. Now, this object is a bit abstract. You need to implement a draw function for it to work. For example, open the basic example in a new tab and paste this to the console
var overlay = new google.maps.OverlayView();
overlay.draw=function() {};
overlay.setMap(map);
overlay.getPanes();
it returns:
{
floatPane: div
floatShadow: div
mapPane: div
markerLayer: div
overlayImage: div
overlayLayer: div
overlayMouseTarget: div
overlayShadow: div
}
Thay markerLayer is a div which contains the markers. If I create your marker using a given icon image,
var marker = new google.maps.Marker({
position: map.getCenter(),
map: map,
icon: 'http://ruralshores.com/assets/marker-icon.png',
optimized:false
});
My markerLayer will be:
Where the selected div (the one with z-index 103) is the markerLayer.
If you wanted to access the markerLayer programatically, you could add a "markerLayer" class to it after getting its reference with the getPanes
method. I guess that every image inside the markerLayer is a marker, so you could style it at will.
TL/DR : you can style it, provided you went through all the trouble of finding the DOM reference to your marker.
Edit: I made a bl.ocks for you to check
When you know the url of the image used for the marker you know how to access it via CSS: use a attribute-selector.
Let's create a circle-marker based on your avatar with a 1px black border:
Marker-setup:
icon:{
url: 'https://www.gravatar.com/avatar/0a9745ea7ac5c90d7acadb02ab1020cd?s=32&d=identicon&r=PG&f=1',
//the size of the image is 32x32,
//when you want to add a border you must add 2*borderWidth to the size
size:new google.maps.Size(34,34)},
//define the shape
shape:{coords:[17,17,18],type:'circle'},
//set optimized to false otherwise the marker will be rendered via canvas
//and is not accessible via CSS
optimized:false
}
the CSS:
img[src="https://www.gravatar.com/avatar/0a9745ea7ac5c90d7acadb02ab1020cd?s=32&d=identicon&r=PG&f=1"]{
border-radius:16px;
border:1px solid #000 !important;
}
....done.
Demo: http://jsfiddle.net/doktormolle/5raf237u/
When you use a shadow use a larger size(depending on the size of the shadow ):
http://jsfiddle.net/doktormolle/L2o2xwj3/
Hello i try all this answers but no one work as i wanna Try this first Create a div contains the image (MarkerImage) and add CSS
var map;
function initialize() {
var mapOptions = {
zoom: 9,
center: new google.maps.LatLng(40.6, -74)
};
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
// I create 3 markers using http://ruralshores.com/assets/marker-icon.png as icon
var myIcon='http://ruralshores.com/assets/marker-icon.png';
var marker1 = new google.maps.Marker({ position: {lat:40.8, lng:-74}, map: map, icon: myIcon, optimized:false });
var marker2 = new google.maps.Marker({ position: {lat:40.6, lng:-74.5}, map: map, icon: myIcon , optimized:false });
var marker3 = new google.maps.Marker({ position: {lat:40.5, lng:-74.3}, map: map, icon: myIcon , optimized:false });
// I create an OverlayView, and set it to add the "markerLayer" class to the markerLayer DIV
var myoverlay = new google.maps.OverlayView();
myoverlay.draw = function () {
this.getPanes().markerLayer.id='markerLayer';
};
myoverlay.setMap(map);
}
google.maps.event.addDomListener(window, 'load', initialize);
and now add somme CSS
#markerLayer img {
border: 2px solid red !important;
width: 85% !important;
height: 90% !important;
border-radius: 5px;
}
The full Tutorial is her