[OpenLayers-Users] GET mouse position
Gregor Mosheh
gregor at hostgis.com
Tue Mar 11 21:49:35 EDT 2008
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);
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');
}
--
Gregor Mosheh / Greg Allensworth, BS, A+
System Administrator
HostGIS cartographic development & hosting services
http://www.HostGIS.com/
"Remember that no one cares if you can back up,
only if you can restore." - AMANDA
More information about the Users
mailing list