Reputation: 213
so what iv been trying to do for like two days now is.
var arr = [
{
path: "M239.68,331.38c34.206,58.142,87.12,150.48,87.12,150.48s49.609-84.922,88.56-149.76C327.52,275.94,241.84,326.34,239.68,331.38z",
fillColor: 'red',
fillOpacity: 1,
anchor: new google.maps.Point(0, 0),
strokeWeight: 0,
scale: .6,
},
{
path: "M150 0 L75 200 L225 200 Z",
fillColor: 'black',
fillOpacity: 1,
anchor: new google.maps.Point(0, 0),
strokeWeight: 0,
scale: .6,
}
];
var marker = new google.maps.Marker({
position: location,
map: map,
draggable: false,
icon: arr,
zIndex: -20,
});
so basically what iv been trying to do is to dynamically build an svg by combining two or more svgs and using that as a marker, is this possible at all? does anyone know? the only important property i want to style is the color, so that i have a marker with more than one color.
Upvotes: 3
Views: 73
Reputation: 1
In the html you'll see your "svg notation" converted to an actual SVG
There are many libraries you can use that make creating SVG's a little easier, or you can learn how to create them directly in javascript ... it's easier than you think - but I hard coded it - you can easily change the colors in the SVG using standard DOM getElementById etc -
for example, see how the original colours are red and black and the line
document.getElementById('p1').setAttribute('fill','green');
set's the red bit to green -
var map;
var polyLine;
var polyOptions;
function initialize() {
var mapOptions = {
zoom: 5,
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: new google.maps.LatLng(0,0)
};
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
google.maps.event.addListener(map, 'click', function(event) {
addPoint(event);
});
}
function addPoint(event) {
document.getElementById('p1').setAttribute('fill','green');
var iconUrl = "data:image/svg+xml;charset=utf-8," + escape(document.getElementById("marker").innerHTML)
var icon = {
url: iconUrl,
anchor: new google.maps.Point(0,0),
scaledSize: new google.maps.Size(40,55)
}
var marker = new google.maps.Marker({
position: event.latLng,
map: map,
draggable: false,
icon: icon,
zIndex : -20
});
}
initialize();
<script src="http://maps.googleapis.com/maps/api/js?sensor=false&x=.js"></script>
<div id="map-canvas" style="height:400px"></div>
<div id='marker' style='display:none'><svg
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
width="110mm" height="150mm"
id="svg111"
version="1.1">
<path id="p1"
fill="red"
fill-opacity="1"
stroke-weight="0"
d="M239.68,331.38c34.206,58.142,87.12,150.48,87.12,150.48s49.609-84.922,88.56-149.76C327.52,275.94,241.84,326.34,239.68,331.38z" />
<path id="p2"
fill="black"
fill-opacity="1"
stroke-weight="0"
d="M150 0 L75 200 L225 200 Z" />
</svg></div>
Upvotes: 1