[OpenLayers-Users] GET mouse position
Tim Schaub
tschaub at openplans.org
Wed Mar 12 11:52:17 EDT 2008
Hey-
Gregor Mosheh wrote:
> Tara wrote:
>> Is it possible to capture the mouse position by a click event and send it to
>> another page via GET (or POST or whatever)? I would like to have users click
>> on the map to fill in long and lat in <input /> fields.
>
> Sure, happens all the time. Bind an event handler to the map, and create
> a callback function to handle the event. Here's an example:
>
> map.events.register('click', map, handleMapClick);
>
Note that if you want notification of single clicks but not two
notifications about double clicks, or if you only want notifications
about clicks that do not include a drag, you're better off using our
click handler (rather than the browser's click event).
See the click handler example for use:
http://openlayers.org/dev/examples/click-handler.html
Tim
> function handleMapClick(evt) {
> // don't select the point, select a square around the click-point
> var clickbuffer = 18; //how many pixels around should it look?
> var sw = map.getLonLatFromViewPortPx(new
> OpenLayers.Pixel(evt.xy.x-clickbuffer , evt.xy.y+clickbuffer) );
> var ne = map.getLonLatFromViewPortPx(new
> OpenLayers.Pixel(evt.xy.x+clickbuffer , evt.xy.y-clickbuffer) );
>
> // open a popup window, supplying the coords in GET
> var url = click_url + '?bbox='+sw.lon+','+sw.lat+','+ne.lon+','+ne.lat;
> window.open(url,'popup');
> }
>
>
More information about the Users
mailing list