在谷歌地图v3多边形上检测鼠标事件的shiftKey [英] Detect shiftKey for mouse event on google maps v3 polygon
问题描述
使用google maps V3(.16)JavaScript API时,有没有办法在多边形上检测shift-mouseclick?
https://developers.google.com/maps/documentation/javascript / reference#MouseEvent
我收到鼠标事件,并且可以看到原始事件被封装在一个Google事件类中,这就是需要(访问事件。 Ua .shiftKey属性)。
然而,我发现上个月,谷歌可能已经更新了他们的api,属性重命名为事件。 Pa .shiftKey。
有关参考资料,请参阅 http:// i.stack.imgur.com/80npD.png 获取webinspector中事件结构的屏幕截图。
有没有什么办法可以检测在使用事件点击谷歌地图多边形期间是否按下了shift键,而不必依赖google-not-updating-their-api?我错过了什么?
Thx!
使用未记录的属性几乎总是一个坏主意。如果你可以避免它,避免它。在这种情况下,API可能正在使用Closure Compiler进行压缩,所以下次更新时,它可能不再是 Pa
。
有没有什么方法可以检测在使用事件点击谷歌地图多边形期间是否按下了shift键,而无需依赖google-not-如果只是
Ua
与<$ c
$ b
您可以检测:
var shiftKey =(event.Ua || event.Pa).shiftKey;
使用JavaScript的好奇地强大 假设当他们将它从 具体检查 ...您可以搜索它: 注意: Is there a way to detect a shift-mouseclick on a polygon when using the google maps V3(.16) javascript API?
https://developers.google.com/maps/documentation/javascript/reference#MouseEvent I do receive the mouse event, and I can see that the original event is wrapped in a google event class, which is just what's needed (Access the event.Ua.shiftKey property). I found however that last month, google may have updated their api and now the property is renamed to event.Pa.shiftKey. For reference, see http://i.stack.imgur.com/80npD.png for a screenshot of the event structure in the webinspector.
Is there any way to detect whether the shift key is pressed during a click on a google maps polygon using the event, and without having to rely on google-not-updating-their-api? What am I missing? Thx! Using undocumented properties is almost always a bad idea. If you can possibly avoid it, avoid it. In this case, the API is probably being compressed with the Closure Compiler, and so the next time they update, it may not be Is there any way to detect whether the shift key is pressed during a click on a google maps polygon using the event, and without having to rely on google-not-updating-their-api?
You could feature detect: That uses JavaScript's curiously powerful This assumes that when they change it from That specifically checks for a ...you can search for it: Side note: 这篇关于在谷歌地图v3多边形上检测鼠标事件的shiftKey的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! ||
运算符来引用 Ua
属性的值,如果有的话,它是真的,否则
Ua
更改为 Pa
时,它们不会使用 Ua
作其他用途。如果有机会,这个更彻底的版本可以做到这一点:
var shiftKey =((event.Ua&& amp ;'shiftKey'in event.Ua)?event.Ua:event.Pa).shiftKey;
Ua
对象 shiftKey
属性,如果未找到,则回落到 Pa
。
如果它可以是任何东西
var shiftKey;
if(event.key(event).some(function)(key){
if(事件[key]中的event [key]&'shiftKey'){
shiftKey =事件[key] .shiftKey;
返回true;
}
返回false;
})){
//我们发现它,`shiftKey`的值是
} else {
//我们没有找到它
}
Object.keys
是所有现代浏览器上的ES5功能。如果您需要支持IE8等较旧的浏览器,则可以进行填充。Pa
anymore either.
If just
Ua
vs. Pa
:var shiftKey = (event.Ua || event.Pa).shiftKey;
||
operator to reference the Ua
property's value, if there is one and it's truthy, or the Pa
property's value otherwise.Ua
to Pa
, they don't use Ua
for something else. If there's a chance of that, this more thorough version would do it:var shiftKey = ((event.Ua && 'shiftKey' in event.Ua) ? event.Ua : event.Pa).shiftKey;
Ua
object with a shiftKey
property, falling back to Pa
if not found.If it could be anything
var shiftKey;
if (Object.keys(event).some(function(key) {
if (event[key] && 'shiftKey' in event[key]) {
shiftKey = event[key].shiftKey;
return true;
}
return false;
})) {
// We found it, `shiftKey` has the value
} else {
// We didn't find it
}
Object.keys
is an ES5 feature present on all modern browsers. If you need to support older browsers like IE8, it can be polyfilled.