455,362 Members | 1,354 Online
Need help? Post your question and get tips & solutions from a community of 455,362 IT Pros & Developers. It's quick & easy.

# Google MAP: Can not addListener to polygons which parsed from XML

 P: 1 Anyone help me please. I want anytime mousemove to one polygon, it's opacity becomes 0.3, and mouseout polygon, i'ts opacity return to 0 again. I means mousemove to show the polygon and hiding it when mouseout. I parsed points from XML and then add polygons to the map. But my problem that I can't addListener (mousemove) and (mouseout) for each of polygon, so I decide to addListener to the map and check if any polygon contains clicked point. But my map is too slow with my algorithms. Anyone help me to fix to addListener to each of polygons?. Thank you very much ! Here is my code: Expand|Select|Wrap|Line Numbers var polys = [];         var labels = [];         var htmls = [];           // === A method for testing if a point is inside a polygon       // === Returns true if poly contains point       // === Algorithm shamelessly stolen from http://alienryderflex.com/polygon/       GPolygon.prototype.Contains = function(point) {         var j=0;         var oddNodes = false;         var x = point.lng();         var y = point.lat();         for (var i=0; i < this.getVertexCount(); i++) {           j++;           if (j == this.getVertexCount()) {j = 0;}           if (((this.getVertex(i).lat() < y) && (this.getVertex(j).lat() >= y))           || ((this.getVertex(j).lat() < y) && (this.getVertex(i).lat() >= y))) {             if ( this.getVertex(i).lng() + (y - this.getVertex(i).lat())             /  (this.getVertex(j).lat()-this.getVertex(i).lat())             *  (this.getVertex(j).lng() - this.getVertex(i).lng())" + labels[i] + "" + htmls[i];               map.openInfoWindowHtml(point,myHTML);               //i = 999; // Jump out of loop             }           }         }       });         GEvent.addListener(map, "mousemove", function(point) {           for (var i=0; i 0)                 var html = htmlObject[0].childNodes[0].nodeValue;             else                 var html = "";             var poly = new GPolygon(pts,"#000000",0,0,"#0000CC",0, {clickable:false});             polys.push(poly);             labels.push(label);             htmls.push(html);             map.addOverlay(poly);           }           // ================================================         }       }       request.send(null); Nov 5 '08 #1