Skip to content

Instantly share code, notes, and snippets.

@DylanCodeCabin
Created March 24, 2020 06:12
Show Gist options
  • Save DylanCodeCabin/a3d9b20d922b8a731f2091e8e391f8b4 to your computer and use it in GitHub Desktop.
Save DylanCodeCabin/a3d9b20d922b8a731f2091e8e391f8b4 to your computer and use it in GitHub Desktop.
jQuery(function($){
var lastMarkerId = false;
var scaleMultiplier = 1.3;
$(document.body).on('infowindowopen.wpgmza', function(e){
var tmarkid = e.target.mapObject.id;
var tmapid = e.target.mapObject.map_id;
if(lastMarkerId !== tmarkid){
var lastMark = WPGMZA.getMapByID(tmapid).getMarkerByID(lastMarkerId);
if(lastMark !== null){
lastMark.updateIcon();
}
lastMarkerId = tmarkid;
var tmark = WPGMZA.getMapByID(tmapid).getMarkerByID(tmarkid);
var icon = tmark.getIcon();
if(icon && icon.url){
icon.url = icon.url.replace(/^http(s?):/, "");
var img = new Image();
img.onload = function(event) {
var autoDetect = false;
var size;
if(tmark.retina == 1){
if(!autoDetect){
size = new google.maps.Size(
WPGMZA.settings.retinaWidth ? Math.round( parseInt(WPGMZA.settings.retinaWidth) * scaleMultiplier) : Math.round( (img.width / 2) * scaleMultiplier),
WPGMZA.settings.retinaHeight ? Math.round( parseInt(WPGMZA.settings.retinaHeight) * scaleMultiplier) : Math.round( (img.height / 2) * scaleMultiplier)
);
} else {
size = new google.maps.Size(
Math.round( (img.width / 2) * scaleMultiplier),
Math.round( (img.height / 2) * scaleMultiplier)
);
}
} else {
size = new google.maps.Size(
Math.round( (img.width) * scaleMultiplier),
Math.round( (img.height) * scaleMultiplier)
);
}
tmark.googleMarker.setIcon(
new google.maps.MarkerImage(icon.url, null, null, null, size)
);
};
img.src = icon.url;
}
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment