English 中文(简体)
• 海关超额可点击(谷歌地图
原标题:Make custom overlay clickable (Google Maps API v3)

我有一个习俗超时班(ImageOverlay),继承google.maps.OverlayView。 我想对谷歌地图的点击事件(不仅仅是OM点事件)做出回应,而只是使用<条码>。 似乎没有 do。

e.g. 我有<代码>shapes的阵容,其中包含<条码>google.maps.Polygon和 ImageOverlay的混合物:

for (var i in shapes) {
  google.maps.event.addListener(shapes[i],  click , function(){alert( hi )});
}

聚戈斯角的振荡触发了警惕,但点击了海关的超支。

我如何使谷歌地图第二版将超支视为可点击?

最佳回答

Update for v3:overlay Layer 更不用说接受 mo事。 将你的超支添加到<条码>中,代之以增加听众,通常应接受模拟活动。

//add element to clickable layer 
this.getPanes().overlayMouseTarget.appendChild(div);

// set this as locally scoped var so event does not get confused
var me = this;

// Add a listener - we ll accept clicks anywhere on this div, but you may want
// to validate the click i.e. verify it occurred in some portion of your overlay.
google.maps.event.addDomListener(div,  click , function() {
    google.maps.event.trigger(me,  click );
});

问题回答

地图标本可以自动确定贵方的中继部分应当被点击(即,如果你使图像具有透明背景的话,如果要达到你的超支类别,以确定在透明区域点击是否有效点击)。

你们应当把新闻部的听众添加到你所选的超支中,然后,如果这真的点击,就引发你们自己的地图AP。

例:

FooBar.prototype.onAdd = function() {
  // Create a div and append it to a map pane. 
  var div = document.createElement( div );
  div.style = "height: 100px; width: 100px";
  this.getPanes().overlayLayer.appendChild(div);

  // set this as locally scoped var so event does not get confused
  var me = this;

  // Add a listener - we ll accept clicks anywhere on this div, but you may want
  // to validate the click i.e. verify it occurred in some portion of your overlay.
  google.maps.event.addDomListener(div,  click , function() {
    google.maps.event.trigger(me,  click );
  });

  // Position your overlay etc.
}

页: 1 v3. 如下文所述,但有一些更正:

< LocalityCustomOverlay.prototype.onAdd function:

var self = this;
google.maps.event.addDomListener(this._div,  click , function(event) {
    // stop click reaction on another layers
    event.stopPropagation();

    // add also event to 3rd parameter for catching
    google.maps.event.trigger(self,  click , event); 
});

在外,直接与您的习俗相传:

google.maps.event.addListener(CUSTOM_OVERLAY_OBJECT,  click , function(event) {
    console.log( event: , event);
});

您还可能希望停止活动传播,这样,在超莱的点击不会传播到以下要素(如多角、标识等,取决于你的潘基文)。

//add element to clickable layer 
this.getPanes().overlayMouseTarget.appendChild(div); // or floatPane

// set this as locally scoped var so event does not get confused
var me = this;

// Add a listener - we ll accept clicks anywhere on this div, but you may want
// to validate the click i.e. verify it occurred in some portion of your overlay.
google.maps.event.addDomListener(div,  click , function(events) {
    if (/*handling event*/) {
        event.preventDefault(); // The important part
    }
    else {
        google.maps.event.trigger(me,  click );
    }
});




相关问题
Overlay blocks in a multi-part form

I ve a form with three sections, markup looks something like this: div.section1 legend fieldset button.continue div.section2 legend fieldset button.continue div.section3 legend fieldset ...

GWT RPC or Request Builder using Javascript Overlay?

GWT RPC is a mechanism provided by gwt to communicate between client and server. Also there s a Request Builder, through which you can connect to the server. Which mechanism would you recommend for a ...

How to create an overlay window in Java?

I m trying to create a HUD style display for a foreign application. To do this, I d need to make a transparent overlay window, that would be placed on top of the window of the foreign application. ...

Plot Overlay MATLAB

How do you take one plot and place it in the corner (or anywhere for that matter) of another plot in MATLAB? I have logarithmic data that has a large white space in the upper right-hand side of the ...

RSS to KML Overlay

I m want to display my blog as a Google Map overlay (each post contains geotags). How can I dynamically create a KML overlay from an RSS? Or better, how can I create a loop (PHP) that would display ...

热门标签