Google maps api 3 谷歌地图自定义标记图标配置从精灵表与视网膜支持
我的谷歌地图使用从精灵表加载的自定义标记pin,在1x、2x和3x显示时一切正常,除了@2x,@3x图像显示为原始图像大小的三倍 如果我尝试在@2x和@3x显示时将其缩放回1x尺寸,则标记将显示,而不显示图像 谷歌搜索表明我做的一切都是对的,图标配置是基于文档的 有人能发现我的Google maps api 3 谷歌地图自定义标记图标配置从精灵表与视网膜支持,google-maps-api-3,Google Maps Api 3,我的谷歌地图使用从精灵表加载的自定义标记pin,在1x、2x和3x显示时一切正常,除了@2x,@3x图像显示为原始图像大小的三倍 如果我尝试在@2x和@3x显示时将其缩放回1x尺寸,则标记将显示,而不显示图像 谷歌搜索表明我做的一切都是对的,图标配置是基于文档的 有人能发现我的scaleImage配置有什么问题吗 if(devicePixelRatio > 1) { pinImage['scaledSize'] = new google.maps.Size(15, 36); } 从J
scaleImage
配置有什么问题吗
if(devicePixelRatio > 1) {
pinImage['scaledSize'] = new google.maps.Size(15, 36);
}
从JavaScript中提取代码:
var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
// Retina support
var requireImagePrefix = "";
var devicePixelRatio = (window.devicePixelRatio===undefined?1:window.devicePixelRatio);
if(devicePixelRatio == 2) {
requireImagePrefix = "@2x";
}
else if(devicePixelRatio == 3) {
requireImagePrefix = "@3x";
}
// Image for the marker
var pinImage = {
url: "/assets/sprite" + requireImagePrefix + ".png",
size: new google.maps.Size(15*devicePixelRatio, 36*devicePixelRatio),
origin: new google.maps.Point(430*devicePixelRatio, 20*devicePixelRatio),
};
if(devicePixelRatio > 1) {
pinImage['scaledSize'] = new google.maps.Size(15, 36);
}
var officeMarker = new google.maps.Marker({
position: hqLocation,
map: map,
title: "Anomaly HQ",
icon: pinImage,
optimized: false
});
非常感谢您的时间。我在上面的错误是:
参数是1x精灵的尺寸scaledSize
- 我们不需要将
和size
参数乘以纵横比origin