I am struggling to apply a icon zoom level change function to my google maps api script.
My current icon size is 48px and the actually graphic is also 48px.
jsfiddle.net/motocomdigital/hQkb3/6
Determined like this…
var image = new google.maps.MarkerImage(
'<?php bloginfo('template_url'); ?>/images/marker-images/image-48px.png',
new google.maps.Size(48,48),
new google.maps.Point(0,0),
new google.maps.Point(24,48)
);
I don’t suppose it is possible to change these sizes and graphics depending on 3 zoom levels?
For example, when a zoom is at…
Zoom Level 0 > 6 – uses…
'<?php bloginfo('template_url'); ?>/images/marker-images/image-12px.png',
new google.maps.Size(12,12),
new google.maps.Point(0,0),
new google.maps.Point(6,6)
Zoom Level 6 > 8 – uses…
'<?php bloginfo('template_url'); ?>/images/marker-images/image-24px.png',
new google.maps.Size(24,24),
new google.maps.Point(0,0),
new google.maps.Point(12,12)
Zoom Level 8+ – uses…
'<?php bloginfo('template_url'); ?>/images/marker-images/image-48px.png',
new google.maps.Size(48,48),
new google.maps.Point(0,0),
new google.maps.Point(24,24)
This is my original script below…
jQuery(function($){
var image = new google.maps.MarkerImage(
'<?php bloginfo('template_url'); ?>/images/marker-images/image.png',
new google.maps.Size(48,48),
new google.maps.Point(0,0),
new google.maps.Point(24,24)
);
$('#map_div').gmap3({
action:'init',
options: {
center:[<?php echo $lt;?>,<?php echo $lo;?>],
zoom: 7,
scrollwheel: false
}
},
{
action: 'addMarkers',
markers: [ <?php echo $lat_long;?> ],
marker: {
options: {
draggable: false,
icon: image
},
events:{
mouseover: function(marker, event, data){
var map = $(this).gmap3('get'),
infowindow = $(this).gmap3({ action:'get', name:'infowindow' });
if (infowindow) {
infowindow.open(map, marker);
infowindow.setContent(data);
} else {
$(this).gmap3({action:'addinfowindow', anchor:marker, options:{content: data}});
}
},
mouseout: function(){
var infowindow = $(this).gmap3({ action:'get', name:'infowindow' });
if (infowindow){
infowindow.close();
}
}
}
}
});
});
I am really not great with this level of scripting, and any pointers ideas or help would be great thanks.
Josh
I added a “zoom_changed” event to your map that changes all marker icons according to the zoom level.
The function UseMarkerIcon(image) iterates through all your markers and sets the image you pass to it.