Geochart capturing clientx and clienty after click even

315 views
Skip to first unread message

Matt Nuttall

unread,
Nov 19, 2011, 9:05:08 PM11/19/11
to google-visua...@googlegroups.com
Hi Fellow Geochart persons;

Hats off to Google for this interface. I have one last piece to put into place for my project.

I have a standard listener on a geochart. Here's a reduced sample of the relevant code:

function ClickHandler()
{
  google.visualization.events.addListener(qohla.chart, 'regionClick', function(eventData)
  {
    alert("x " + eventData.clientX + " y " + .clientY);
  });
}

Both clientX and clientY return as undefined.

My goal is to allow geomap to process the event business as usual so I can capture the region name selected on the map click. Then, I want to capture the exact location of the region where the click happened so that I could then overlay some text at exactly where the click occurred.

Is it possible to get the coordinates after the event? Is it possible to write text over the map using the coordinates?

Thanks in advance.

Matt

Roni Biran

unread,
Nov 20, 2011, 4:46:13 AM11/20/11
to google-visua...@googlegroups.com
your code should look something like this:

      google.visualization.events.addListener(geochart, 'regionClick', function(eventData)
      {
        alert('You clicked on a region named: ' + eventData.region);
      });

the eventData (as you called it) returns an object named region that hold an ISO-3166 name of the region clicked.
if you want the exact position of the mouse where you clicked you'll need to use the window event.





Matt

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-visualization-api/-/i9YnDHjYy8YJ.
To post to this group, send email to google-visua...@googlegroups.com.
To unsubscribe from this group, send email to google-visualizati...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-visualization-api?hl=en.

Matt Nuttall

unread,
Nov 20, 2011, 10:15:53 AM11/20/11
to google-visua...@googlegroups.com
Hi TheNez;

Thanks for the update.

I already have actions that trigger off the returned region name. I know that the Google Visualization API is using the clientX and clientY values -- that's the way the API is able to return the region to my application. There is no reason the Visualization API could not expose the clientX and clientY values it is using. I've browsed the DOM for the Visualization and seen clientX and clientY referenced in several places.

Exposing the coordinates would allow the Visualization API to not only provide the region name, but also the exact position within the region that the user is clicking on. For example, when my application is returned a region of US, was the user clicking on Alaska, Hawaii or continental United States? When you get down to the province/state level, the coordinates of the click are even more useful. Let's say I'm displaying the US map only: when the API returns, say, a region of US-CA (California), did the user click near San Diego or near San Francisco? I'd like to be able to provide a pull-down list to the user at the exact location they clicked. Then, after they make their selection I want to place a tiny amount of text at the exact location.

Any of the Google Visualization API programmers have a comment? I'd sure be a happy programmer if this data can be exposed somehow.

Thanks again -- Matt

Roni Biran

unread,
Nov 20, 2011, 11:05:32 AM11/20/11
to google-visua...@googlegroups.com
I understand, but still you'll have to get more information on the area on which you're standing on, the proximity to the border, nearby regions etc.
I think there's more to it than you think of, however I don't think it's you'll be able to get that except by using an outside listener to mouse movements.



--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.

Matt Nuttall

unread,
Nov 20, 2011, 1:51:32 PM11/20/11
to google-visua...@googlegroups.com
Hi TheNez;

Thanks again for the reply!

Yeah, I don't mind where the user clicks, as long as I get the region returned from geochart, it is the use that has defined where on the region they have chosen to click (i.e. if the user clicks close to the border of, say, Alberta, that is just fine -- I'll still want to put an "x" on the exact spot the user has clicked. It would be crazy for me to write a whole new canvas just to be able to capture information that we know the Google geochart visualization can provide to my code....

I'm still sifting through the Google visualization DOM hoping to stumble upon some way of accessing clientX and clientY from the preceding onclick event.

If you come up with any more ideas, I'm all ears!

Cheers -- Matt

Roni Biran

unread,
Nov 20, 2011, 2:14:15 PM11/20/11
to google-visua...@googlegroups.com
My main concern on this capturing is the conversion between the x-y position, the relative offsets and the transformation you'll have to do with the chart itself. You will have to dive into the SVG to search for the relevant (or closest) text object.

I fear for your sanity ;-)




--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.

Matt Nuttall

unread,
Nov 21, 2011, 7:32:44 PM11/21/11
to google-visua...@googlegroups.com
Yeah, you're right. I'm getting nowhere. I give up!

Roni Biran

unread,
Nov 22, 2011, 12:42:01 AM11/22/11
to google-visua...@googlegroups.com
Never give up, never surrender ;-) ...... and when you'll find a way, please post it so others will be able to do with it some good...



On Tue, Nov 22, 2011 at 2:32 AM, Matt Nuttall <matten...@gmail.com> wrote:
Yeah, you're right. I'm getting nowhere. I give up!

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.

MC Get Vizzy

unread,
Nov 23, 2011, 6:57:25 AM11/23/11
to google-visua...@googlegroups.com
This is not currently supported.

Sometimes, the only way to succeed is to give up.

Roni Biran

unread,
Nov 23, 2011, 6:58:40 AM11/23/11
to google-visua...@googlegroups.com
:-)


Reply all
Reply to author
Forward
0 new messages