You can also use javascript onmousedown event to get the x,y and then
send the x,y values on the querystring.
Javascript:
//put this code on the page load event or something like that
var isNav = (navigator.appName.indexOf("Netscape") >= 0);
document.onmousedown = getImageXY;
if (isNav)
{
document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE |
Event.MOUSEUP);
}
// this is the function that gets called when the user clicks the left
mouse button on the screen // you probably want to embed an iframe in
your main page that has an img tag whose .href property is set to the
url of your map servlet // and put all the map javascript in that frame
page.
function getImageXY(e)
{
try
{
if (isNav)
{
mouseX=e.pageX;
mouseY=e.pageY;
}
else
{
mouseX=event.clientX + document.body.scrollLeft;
mouseY=event.clientY + document.body.scrollTop;
}
mouseX = mouseX-hspc; //height
mouseY = mouseY-vspc; // width
}
catch(e)
{
alert(e.description);
}
}
// once you get the x, y values from the image you can set the .href of
the image which will automatically call your servlet passing in the href
querystring. Another example is like this...
// turn on click mode
function Menu_onCenter()
{
try
{
if ( !isIE5 )
document.theImage.style.cursor = 'default';
document.onmousedown = "";
document.onmouseup = "";
document.onmousemove = "";
document.theImage.onmouseup = "";
document.theImage.onmousedown = "";
document.theImage.onmousemove = "";
document.theImage.onclick = map_image_onCenter; // set onclick
event to the function listed below
}
catch(e)
{
alert(e.description);
}
}
// handle mouse click
function map_image_onCenter(evt)
{
try
{
var nMapX;
var nMapY;
var ua = window.navigator.userAgent;
var an = window.navigator.appName;
bExplorer = (ua.indexOf("MSIE ") >= 1);
if (bExplorer)
{
nMapX = parseInt(window.event.offsetX);
nMapY = parseInt(window.event.offsetY);
}
else
{
var Element = evt.target ;
var CalculatedTotalOffsetLeft = CalculatedTotalOffsetTop =
0;
while (Element.offsetParent)
{
CalculatedTotalOffsetLeft += Element.offsetLeft ;
CalculatedTotalOffsetTop += Element.offsetTop ;
Element = Element.offsetParent ;
}
nMapX = parseInt(OffsetXForNS6 = evt.pageX -
CalculatedTotalOffsetLeft);
nMapY = parseInt(OffsetYForNS6 = evt.pageY -
CalculatedTotalOffsetTop);
}
var vHref = "mapimageservlet";
vHref += "?projtype=MERCATOR";
vHref += "&action=center";
vHref += "&scale=" + m_vScale;
vHref += "&lat=" + m_vLatitude;
vHref += "&lon=" + m_vLongitude;
vHref += "&width=" + m_vWidth;
vHref += "&height=" + m_vHeight;
vHref += "&bgcolor=FFFFFF";
vHref += "&x=" + nMapX;
vHref += "&y=" + nMapY;
window.frames["map_image"].location.href = vHref;
}
catch(e)
{
alert(e.description);
}
}
Martin Chapman
-----Original Message-----
From: owner-openmap-users@bbn.com [mailto:owner-openmap-users@bbn.com]
On Behalf Of David Garnier
Sent: Wednesday, May 14, 2003 1:52 PM
To: openmap-users@bbn.com
Subject: RE: [OpenMap Users] servlet example
Le mar 13/05/2003 à 19:46, Keith Alphonso a écrit :
> Generating the map via servlet is relatively simple, making it
> clickable is a little bit more difficult. The approach we took was to
> create a servlet for generating the map, then we created a servlet
> that would convert X/Y coordinates into Lat/Lon based on that map's
> settings. We used the Projection.inverse method to convert the X/Y to
> Lat/Lon. Then you can use the servlet map image as an input field in
> your HTML to send the X/Y via click.
I've been using the ismap attribute of the IMG tag. It adds the
coordinates of the cursor on the map to the url of the image, if there
is one. It works quite well and is supported since HTML 2.0. Still, it
is a little tricky to use, so I think that I will try your idea. Thanks.
Best Regards
-- David Garnier <david.garnier@etudier-online.com> -- [To unsubscribe to this list send an email to "majdart@bbn.com" with the following text in the BODY of the message "unsubscribe openmap-users"] -- [To unsubscribe to this list send an email to "majdart@bbn.com" with the following text in the BODY of the message "unsubscribe openmap-users"]Received on Wed May 14 17:04:04 2003
This archive was generated by hypermail 2.1.8 : Thu May 12 2005 - 07:18:35 EDT