在Google Maps多边形数组上设置点击优先级 [英] Setting click priority on google maps polygon array

查看:57
本文介绍了在Google Maps多边形数组上设置点击优先级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Google Maps API在JavaScript中进行编码,我很好奇是否有一种方法可以设置单击区域时显示哪个多边形阵列信息窗口的优先级.我有两个重叠的多边形,当您单击重叠区域时,我需要控制显示哪个信息提示框.谢谢!

I am coding in JavaScript using the Google Maps API, and I was curious if there was a way to set the priority of what polygon array info window is shown when I click on an area. I have two polygons that are overlapping, and I need to control which info bubble appears when you click on the overlapped area. Thank you!

推荐答案

点击将在最顶部的多边形上触发.

The click will be triggered on the most top Polygon.

多边形的顺序通常取决于将其添加到地图的顺序(设置 map -属性时)或通过设置自定义的 zIndex -属性.

The order of the polygons usually depends on the order in which they have been added to the map(when the map-property has been set) or by setting a custom zIndex-property.

因此,当您要定义优先级时,必须为多边形定义 zIndex .

So when you want to define a priority you must define the zIndex for the Polygons.

当您希望能够单击每个多边形(以及每个多边形的每个部分)时,有一种简单的方法:

When you want to be able to click on each polygon(and each part of each polygon) there is a simple approach:

观察多边形的鼠标悬停,并将悬停的多边形的 zIndex 设置为高于其他多边形的zIndex的值.这将使多边形位于最前面,您现在也可以单击先前覆盖的区域.

Observe the mouseover of the polygons and set the zIndex of the hovered polygon to a value higher than the zIndex of the other polygons. This will bring the polygon into front and you now may also click on the previously covered area.

您可以通过扩展多边形原型来实现此目的:

You may implement this by extending the polygon-prototype:

(function(){
  var a=z=0;
  google.maps.Polygon_=function(opts){


     this.setValues(opts)
     google.maps.event.addListener(this,'mouseover',function(){
        this.set('zIndex',++z);
     });    
     google.maps.event.addListener(this,'rightclick',function(){
        this.set('zIndex',--a);
     });

  };
  google.maps.Polygon_.prototype = google.maps.Polygon.prototype;
  google.maps.Polygon = google.maps.Polygon_;}
)();

演示: http://jsfiddle.net/doktormolle/wznd5nsy/

Demo: http://jsfiddle.net/doktormolle/wznd5nsy/

(使用右键单击可将多边形发送回去,例如当其完全覆盖另一个多边形时.)

(Use rightclick to send a polygon to back, e.g. when it completely covers another polygon).

这篇关于在Google Maps多边形数组上设置点击优先级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆