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: - 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())<x )
-
{
-
oddNodes = !oddNodes
-
}
-
}
-
}
-
return oddNodes;
-
}
-
-
-
GEvent.addListener(map, "click", function(overlay,point) {
-
confirm(point);
-
if (!overlay) {
-
for (var i=0; i<polys.length; i++) {
-
if (polys[i].Contains(point)) {
-
var myHTML = "<font color=red><b>" + labels[i] + "</b></font><br /
-
>" + htmls[i];
-
map.openInfoWindowHtml(point,myHTML);
-
//i = 999; // Jump out of loop
-
}
-
}
-
}
-
});
-
-
GEvent.addListener(map, "mousemove", function(point) {
-
for (var i=0; i<polys.length; i++) {
-
if (polys[i].Contains(point)) {
-
var myPoly = polys[i];
-
myPoly.setFillStyle({opacity: 0.3});
-
cur_poly = i;
-
//i = 999; // Jump out of loop
-
}
-
else {
-
var myPoly = polys[i];
-
myPoly.setFillStyle({opacity: 0});
-
}
-
}
-
});
-
-
// Read the data from companies.xml
-
-
var request = GXmlHttp.create();
-
request.open("GET", "' . base_path() . $mod_path . '/
-
companies.xml", true);
-
request.onreadystatechange = function() {
-
if (request.readyState == 4) {
-
var xmlDoc = GXml.parse(request.responseText);
-
-
// ========= Now process the polylines ===========
-
var companies =
-
xmlDoc.documentElement.getElementsByTagName("company");
-
-
// read each line
-
for (var a = 0; a < companies.length; a++) {
-
// get any state attributes
-
var label = companies[a].getAttribute("name");
-
// read each point on that line
-
var points = companies[a].getElementsByTagName("point");
-
var pts = [];
-
for (var i = 0; i < points.length; i++) {
-
pts[i] = new
-
GLatLng(parseFloat(points[i].getAttribute("lat")),
-
-
parseFloat(points[i].getAttribute("lng")));
-
}
-
var htmlObject = companies[a].getElementsByTagName("html");
-
if (htmlObject.length > 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);
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).
Sign in to post your reply or Sign up for a free account.
Similar topics |
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.......
|
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
|
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
|
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...
|
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|
...
| |
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
|
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...
|
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
...
|
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...
|
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...
|
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,...
| |
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,...
|
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...
|
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();...
|
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...
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |