473,654 Members | 3,251 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

1 New Member
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
  1. var polys = [];
  2.         var labels = [];
  3.         var htmls = [];
  4.  
  5.  
  6.       // === A method for testing if a point is inside a polygon
  7.       // === Returns true if poly contains point
  8.       // === Algorithm shamelessly stolen from http://alienryderflex.com/polygon/
  9.       GPolygon.prototype.Contains = function(point) {
  10.         var j=0;
  11.         var oddNodes = false;
  12.         var x = point.lng();
  13.         var y = point.lat();
  14.         for (var i=0; i < this.getVertexCount(); i++) {
  15.           j++;
  16.           if (j == this.getVertexCount()) {j = 0;}
  17.           if (((this.getVertex(i).lat() < y) &&
  18. (this.getVertex(j).lat() >= y))
  19.           || ((this.getVertex(j).lat() < y) &&
  20. (this.getVertex(i).lat() >= y))) {
  21.             if ( this.getVertex(i).lng() + (y -
  22. this.getVertex(i).lat())
  23.             /  (this.getVertex(j).lat()-this.getVertex(i).lat())
  24.             *  (this.getVertex(j).lng() - this.getVertex(i).lng())<x )
  25. {
  26.               oddNodes = !oddNodes
  27.             }
  28.           }
  29.         }
  30.         return oddNodes;
  31.       }
  32.  
  33.  
  34.       GEvent.addListener(map, "click", function(overlay,point) {
  35.       confirm(point);
  36.         if (!overlay) {
  37.           for (var i=0; i<polys.length; i++) {
  38.             if (polys[i].Contains(point)) {
  39.               var myHTML = "<font color=red><b>" + labels[i] + "</b></font><br /
  40. >" + htmls[i];
  41.               map.openInfoWindowHtml(point,myHTML);
  42.               //i = 999; // Jump out of loop
  43.             }
  44.           }
  45.         }
  46.       });
  47.  
  48.       GEvent.addListener(map, "mousemove", function(point) {
  49.           for (var i=0; i<polys.length; i++) {
  50.             if (polys[i].Contains(point)) {
  51.               var myPoly = polys[i];
  52.               myPoly.setFillStyle({opacity: 0.3});
  53.               cur_poly = i;
  54.               //i = 999; // Jump out of loop
  55.             }
  56.             else {
  57.                 var myPoly = polys[i];
  58.                 myPoly.setFillStyle({opacity: 0});
  59.             }
  60.           }
  61.       });
  62.  
  63.       // Read the data from companies.xml
  64.  
  65.       var request = GXmlHttp.create();
  66.       request.open("GET", "' . base_path() . $mod_path . '/
  67. companies.xml", true);
  68.       request.onreadystatechange = function() {
  69.         if (request.readyState == 4) {
  70.           var xmlDoc = GXml.parse(request.responseText);
  71.  
  72.           // ========= Now process the polylines ===========
  73.           var companies =
  74. xmlDoc.documentElement.getElementsByTagName("company");
  75.  
  76.           // read each line
  77.           for (var a = 0; a < companies.length; a++) {
  78.             // get any state attributes
  79.             var label  = companies[a].getAttribute("name");
  80.             // read each point on that line
  81.             var points = companies[a].getElementsByTagName("point");
  82.             var pts = [];
  83.             for (var i = 0; i < points.length; i++) {
  84.               pts[i] = new
  85. GLatLng(parseFloat(points[i].getAttribute("lat")),
  86.  
  87. parseFloat(points[i].getAttribute("lng")));
  88.             }
  89.             var htmlObject = companies[a].getElementsByTagName("html");
  90.             if (htmlObject.length > 0)
  91.                 var html = htmlObject[0].childNodes[0].nodeValue;
  92.             else
  93.                 var html = "";
  94.             var poly = new GPolygon(pts,"#000000",0,0,"#0000CC",0,
  95. {clickable:false});
  96.             polys.push(poly);
  97.             labels.push(label);
  98.             htmls.push(html);
  99.             map.addOverlay(poly);
  100.           }
  101.           //
  102. ================================================
  103.         }
  104.       }
  105.       request.send(null);
Nov 5 '08 #1
1 4990
acoder
16,027 Recognized Expert Moderator MVP
I think mouseover might be more efficient unless you need co-ordinates for every mouse movement. Also, you're using the click event, but you've set "clickable" to false when creating the polygon (line 95).
Nov 11 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
4639
by: Jim Land | last post by:
I've got an image and an image map, and they work fine together. See it here: http://www.jim-land.com/testing/MapPage01.htm But the image map has way too many points (vertices) in its 87 polygons. The html file is over 100k. That's too big to fit into our content- managment system, not to mention that it takes too long to load--about 30 seconds--over a 58k dialup connection. The problem is that the polygons are far too accurate.......
0
1886
by: windandwaves | last post by:
Hi Folk Some of you may find this function useful. It makes it easier to create maps using Google Maps. I link it to a database of points. The main use of the function is that it creates all the javascript needed for Google maps to work. Any questions or comments? Please ask. Nicolaas
17
4610
by: MeerkatInFrance | last post by:
There comes a time when you know you are not going to be able to work something out yourself, however hard you try. I have reached that moment. I have a master page and a slave page (or whatever one calls it) All I want to do is show a Google map on the slave page. The map that Google gives as an example when it gives you a key would be just fine. I have searched high and low for a means of doing this but all I could find
1
3843
by: sacksey | last post by:
Hi. I've been trying to play with this for a while now but I haven't seemed to get it to work. I have a admin controller, which is scaffolded, to input the lat and long along with info. I have a restaurant controller that will display the map with the points. I can get the map to show but the points do not show. class CreateRestaurants < ActiveRecord::Migration def self.up create_table :restaurants do |t| t.column...
0
2231
by: ryt2aamir | last post by:
Hi. I've been trying to play with this for a while now but I haven't seemed to get it to work. I have a admin controller, which is scaffolded, to input the lat and long along with info. I have a restaurant controller that will display the map with the points. I can get the map to show but the points do not show. Code: ( text ) class CreateRestaurants < ActiveRecord::Migration def self.up create_table :restaurants do |t| ...
1
10749
by: sunnyluthra1 | last post by:
Hi, I was creating an Application in MS Access for Geocoding a particular Address from Google to get the Lat & Long. I successfully able to did that. Here is the code: **************************** On Error Resume Next 'if address not found, just move along Dim xml_document As DOMDocument Set xml_document = New DOMDocument Dim rootNode As IXMLDOMNode
0
3728
by: TrevRex | last post by:
Hello, I work for a non-profit in San Diego as a GIS Specialist. I have had to teach myself about some scripting to create some dynamic maps, but I am still very limited in my skills, so I have had to explore the internet in order to discover various tutorials and examples that have led me on a positive path. Right now I am working on a Google Mash-Up that will incorporate over 14,000 records, which will appear as separate markers that...
3
4489
by: ziycon | last post by:
I'm not sure if anyone here would know anything about the google map js, i've tried the google maps api community with no luck. I have the below code, it loads ok, but when i click on the map it doesn't place a marker. What should happen is that when you click on the map it should place a marker and when clicked on the map a second time that it should place a marker at the new location and remove the previous one so that there ...
5
2928
by: Nike1984 | last post by:
I'm fairly new to Javascript and it's more of a guessing game for me... I'm trying to build an app for Google Maps and just had some issues recently. First off I just wanted to say that everything works fine in FF and IE. It's Chrome I'm having issues with. I understand that Chrome is still somewhat in beta stages, so some bugs might occur. However this seems like something I might have done. So... I used a code that I found on Econym as...
0
8376
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8290
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8489
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6161
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5622
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4149
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2716
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1916
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1596
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.