javascript - Google Maps V3 Custom Overlay children stopped receiving mouse events -


Custom overlays (google.maps.OverlayView ()) Children had to respond to mouse events. I saw that they stop them from doing so.

Here is an example ("Overlay, click" ing should click on its text "Work for Overlay", whenever clicked, but never happens):

Here is the code (Cut / Paste for debugging), Overlay is highlighted in the child click listener USGSOverlay.prototype.onAdd ()

  Div.addEventListener ("click", function () {this.innerHTML = "worked for overlay";});   

// overlay-problem.js

  var overlay; USGSOverlay.prototype = New google.maps.OverlayView (); // Start the map and custom overlay function initialize () {var div = document.createElement ('div'); Div.style.borderStyle = 'none'; Div.style.borderthid = '0px'; Div.style.position = 'Done'; Div.className = "FindMe"; Div.style.width = "150px"; Div.style.height = "150px"; Div.style.backgroundColor = "red"; Div.innerHTML = "no overlay, click me"; Div.addEventListener ("click", function () {this.innerHTML = "thank you, it worked for a regular divas";}); Document.body.appendChild (div); Var map option = {zoom: 8, center: new google.maps.LatLng (62.323907, -150.109291), type the map: google.maps.MapTypeId.SATELLITE}; Var map = new google.maps.Map (document.getElementById ('map-canvas'), map options); Var swBound = new google.maps.LatLng (62.281819, -150.287132); Var nebound = new google.maps.LatLng (62.400471, -150.005608); Var bound = new google.maps.LatLngBounds (swBound, neBound); Overlay = new USGS overlay (border, map); } / ** @ constructor * / function USGS overlays (borders, maps) {// starting all properties This.bounds_ = bounds; This.map_ = map; This.div_ = null; // Make a clearmap call this overlay on this overlay this.setMap (map); } / ** * Onid is called when the map pan is ready and the overlay is added to the * map. * / USGSoverLay.prototype.onead = function () {var div = document.createElement ('div'); Div.style.borderStyle = 'none'; Div.style.borderthid = '0px'; Div.style.position = 'Done'; Div.className = "FindMe"; Div.style.width = "150px"; Div.style.height = "50px"; Div.style.backgroundColor = "yellow"; Div.innerHTML = "Overlay, Click Me"; Div.addEventListener ("click", function () {this.innerHTML = "worked for overlay";}); This.div_ = div; // Add element to the "Overlayer" pane var pan = this.getPanes (); Panes.overlayLayer.appendChild (div); }; USGSOverlay.prototype.draw = function () {// We use coordinates of southwest and north-east // overlay so that it can peg at the correct position and size. // To do this, we need to recover the projection from the overlay. Var OverlayProtection = this.getProjection (); // Retrieve the south-west and north-east coordinates of this overlay / in the latenax / and convert them into pixel coordinates. // We will use these coordinates to change the shape of the div i var sw = overlayproogation From Lett Longtodie Pixel (this.bounds_.getSouthWest ()); Var = overlay projection From Lett Longtoday Pixel (this.bounds_.getNorthEast ()); Var div = this.div_; Div.style.left = sw.x + 'px'; Div.style.top = ne.y + 'px'; Div.style.width = (ne.x - sw.x) + 'px'; Div.style.height = (sw.y - ne.y) + 'px'; }; // onRemove () method will be automatically asked by API if // we ever set the property of the overlays map to 'tap' USGSOverlay.prototype.onRemove = function (this.div_.parentNode.removeChild (this .div_); This.div_ = null; };a????    

If you change your overlay then your code should work:

  panes.overlayLayer.appendChild (div);   

From:

  panes.overlayMouseTarget.appendChild (div);  

Overlayouce targeted contains elements that get dom mouse events, such as transparent targets for markers. It is above the FloashShadow, so that markers can be clickable in the shadow of the info window.


(updated to include styles of your overlay).


Cheers.

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -