谷歌地图自定义标记视网膜分辨率
我正在 html5 中开发 iPhone 应用程序并使用 Phonegap 进行构建。 在应用程序中有一个带有自定义标记的Google地图,标记图标的创建方式如下:
var image = new google.maps.MarkerImage("hat.png", null, null, null, new google.maps.Size(20,30));
var shadow = new google.maps.MarkerImage("shadow.png", null, null, null, new google.maps.Size(20,30));
var marker = new google.maps.Marker({
map: map,
position: latlng,
index: markers.length,
icon: image,
shadow: shadow,
animation: google.maps.Animation.DROP,
html: htmlContent
});
与代码中定义的尺寸相比,图标的实际尺寸是两倍。这样做是为了确保图标在视网膜显示屏上以高分辨率显示。 上面的代码直到今天都运行良好,但现在发生的情况如下。
当图标下拉时,使用 google.maps.Animation.DROP,图标在下降过程中以高分辨率显示,但是当图标“降落”在地图上时,图标会切换到低分辨率版本。
有人有过同样的经历吗?
谢谢...
更新 发现如果我指定 Google 地图版本,例如:
http://maps.googleapis.com/maps/api/js?v=3.0
所以我猜这是最新的 Google 地图 API 中的一个错误。
I'm developing an iPhone app in html5 and making the build with Phonegap.
In the app there's a Google map with custom markers, the way the marker icons are created is as follows:
var image = new google.maps.MarkerImage("hat.png", null, null, null, new google.maps.Size(20,30));
var shadow = new google.maps.MarkerImage("shadow.png", null, null, null, new google.maps.Size(20,30));
var marker = new google.maps.Marker({
map: map,
position: latlng,
index: markers.length,
icon: image,
shadow: shadow,
animation: google.maps.Animation.DROP,
html: htmlContent
});
The actual size of the icon's are double size compared to the sizes defined in the code. This is done to make sure the icons are shown in high res on the Retina display.
The code above worked fine until today, but what happens now is the following.
When the icons Drop down, using the google.maps.Animation.DROP, the icon is shown in high res on the way down, but when the icon "lands" on the map, the icon switches to a low res resolution version.
Has anyone ever experienced the same?
Thank you...
UPDATE
Found out that if I specify the Google map version like:
http://maps.googleapis.com/maps/api/js?v=3.0
So I guess it's a bug in the newest Goolge map API.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我通过使用
scaledSize
而不是size
来定义图像的宽度和高度找到了解决方案。I found my solution to this by using
scaledSize
instead ofsize
to define the width and height of the image.只需使用具有
url
、size
和scaledSize
属性的对象即可:其中
path/img/[电子邮件受保护]
是60px
x80px
PNG。Simply use an object with
url
,size
, andscaledSize
attributes:Where
path/img/[email protected]
is a60px
x80px
PNG.我也刚刚发现这个问题。该错误似乎出现在其 API 的最新版本 (v3.7) 中,因此如果您通过 URL 参数 ?v=3.6 指定 v3.6,它将正常工作。
更新: 在 3.8+ 版本中(我认为),如果您正在使用的话,您可以使用 optimization: false 来强制显示视网膜图像。这是因为 optimized: true 会获取所有精灵并将它们编织到一个主精灵中。这意味着只有在标记很少的情况下才应该这样做。另外,与 Clusterer 配合得不太好。
默认值现已优化:true,这将首先确定设备是否可以处理渲染如此多的高分辨率图标,然后再以更高分辨率创建主精灵。例如,在视网膜 Macbook Pro 上加载带有大量标记的地图,它们会显示为高分辨率,但尝试 iPhone 4 时却不会。如果你强迫iPhone 4使用optimized: false,并且有很多标记,它可能会很卡顿。不确定 4S,但我认为它可能会使用更高分辨率的版本,因为它具有更好的处理能力。
I just found this problem too. The bug appears to be in latest (v3.7) of their API, so if you specify v3.6 via the URL parameter ?v=3.6 it'll work fine.
Update: In version 3.8+ (I think) you can use optimized: false to force a retina image, if you are using one. This is because optimized: true takes all your sprites and weaves them together into a master sprite. This means you should only do this if you have very few markers. Also, doesn't work too well with Clusterer.
The default is now optimized: true, which will determine first if the device can even handle rendering so many high-res icons before creating a master sprite at a higher resolution. For example, load a map with a lot of markers on a retina Macbook Pro, and they'll appear high-res, but try an iPhone 4 and it will not. If you force the iPhone 4 using optimized: false, and have a lot of markers, it might stutter a lot. Not sure about the 4S but I assume it'll probably use the higher res version as it has a lot better processing capability.
如果您遇到任何将图标切换到较低分辨率的情况,那是因为地图 api 使用画布来渲染图标(对它们进行分组等等?),显然是为了更快的用户体验。因此,从技术上讲,这不是一个错误,但它确实会导致某些浏览器(例如较旧的 ie)中发生错误,
但是您可以使用一个设置来使用
optimized 在
MarkerOptions
中关闭该设置:假If you encounter any switching of icons to lower resolution, it's because the maps api uses canvas to render the icons (grouping them and whatnot?) for a faster user experience apparently. So it isn't technically a bug, but it does cause buggy things to happen in certain browsers (like older ie)
But there is a setting you can use to turn off in
MarkerOptions
usingoptimized: false
缩放尺寸属性是 Google 此处引用的正确使用属性: https://developers.google.com/maps/documentation/javascript/3.exp/reference#Icon
Scaled Size property is the correct one to use as referenced by Google here: https://developers.google.com/maps/documentation/javascript/3.exp/reference#Icon