0

Google Maps - GPolyline/GPolygon: onClick Event?

asked 2009-10-06 12:47:24 +0800

Ligerzero gravatar image Ligerzero
9 1

Good morning,
Is there a way to set a Gpolygon Object to have a clickable event much like the one in the demo located here: http://www.bdcc.co.uk/Gmaps/BdccGmapBits.htm? If so, how can I implement it or where is there a guide or example that shows the available events for a Gpolyline/Gpolygon Object? The demo is under the "CLICKABLE POLYLINES & POLYGONS" Section, second to last google map. The polygon examples on the map are polygons 1 and 3 (The green dotted lined, blue filled triangle and the solid line blue, red filled triangle respectivly).

Thank you for your time,
Dan Farns

delete flag offensive retag edit

5 Replies

Sort by ยป oldest newest
link publish delete flag offensive edit

answered 2009-10-07 13:02:41 +0800

Ligerzero gravatar image Ligerzero
9 1

Sorry, I've already referenced those pages before, including the demo for Zkoss. Here's the code that I'm using:

<?page title="Try to click the Polygon!"?>

<zk>
<script src="http://maps.google.com/maps?file=api&v=2&key=abcdefg" type="text/javascript"></script>
<zscript>
	public void polyClick(){
		lbl.value="You've clicked on a polygon.";
	}
	public void mapClick(){
		lbl.value="You've clicked on the map.";
	}
	public void markerClick(){
		lbl.value="You've clicked on the marker.";
	
	}
</zscript>

<gmaps id="map" width="600px" height="360px" showLargeCtrl="true" showTypeCtrl="true" lat="40" lng="-73" zoom="8" >

    <attribute name="onMapClick">
		 mapClick();
			Gmarker gmarker = event.getGmarker();
				if (gmarker != null) {
					markerClick();
				}
    </attribute>
    
   	<gmarker id="mymark" lat="40.0" lng="-73.1490">
		<attribute name="content">
			GMarker
		</attribute>
	</gmarker>
		
	<gpolygon id="poly" onClick="polyClick()"/>

</gmaps>
<zscript>
    poly.addPoint(40.0,-73.0,3);
    poly.addPoint(40.0,-73.5,3);
    poly.addPoint(40.5,-73.5,3);
    poly.addPoint(40.5,-73.0,3);
    poly.addPoint(40.0,-73.0,3);
</zscript>

<button label="panTo" onClick="map.panTo(40, -73)"/>
<vbox>
Last Click: <label id="lbl" pre="true"/>
</vbox>

</zk>

The contents of the code should be very straight forward, but I'll add any clarification to help allow me to click on a polygon.

link publish delete flag offensive edit

answered 2009-10-08 01:21:41 +0800

jimmyshiau gravatar image jimmyshiau
4921 5
http://www.zkoss.org/ ZK Team

updated 2009-10-08 01:22:17 +0800

you can try this

    <gmaps id="map" width="600px" height="360px" showLargeCtrl="true" showTypeCtrl="true" lat="40" lng="-73" zoom="8" >

        <attribute name="onMapClick"><![CDATA[
		mapClick();
//		Gmarker gmarker = event.getGmarker();
//		if (gmarker != null) {
//			markerClick();
//		}
	Component comp = event.getReference();
	if(comp == null) return;
	String id = comp.getId();
	if(id.equals(mymark.getId())){
		markerClick();
	}else if(id.equals(poly.getId())){
		polyClick();
	}else{
		mapClick();
	}
	

	]]></attribute>
    
   	<gmarker id="mymark" lat="40.0" lng="-73.1490">
		<attribute name="content">
			GMarker
		</attribute>
	</gmarker>
		
	<gpolygon id="poly" onClick="polyClick()"/>

</gmaps>

//jimmy

link publish delete flag offensive edit

answered 2009-10-11 04:49:44 +0800

Ligerzero gravatar image Ligerzero
9 1

I'll give it a shot the next chance I get. It won't be for a few days.

link publish delete flag offensive edit

answered 2012-05-21 10:13:37 +0800

gganassin gravatar image gganassin flag of Luxembourg
540 6
http://www.hybris.com/

updated 2012-05-21 11:18:14 +0800

It works using gmapz v3.0.0 :)

GG

/**
Hi all!
i have the same problem here and Jimmy's code is not working for polygons.
I'm using the EE evaluation version: any ideas? Any way to catch the click event over a polygon?

Giovanni
**/

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2009-10-06 12:47:24 +0800

Seen: 1,499 times

Last updated: May 21 '12

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More