[OpenLayers-Users] Return Popup Map Click latlon Values toParentPage

Obe, Regina robe.dnd at cityofboston.gov
Tue Apr 3 16:23:15 EDT 2007


Brian,

I haven't tried this in openlayers unfortunately, but when I try to
return values to .NET calling forms, my code usually looks something
like this

window.opener.document.forms[0].ctl00$CPH$id2.value = lat

Where ctl00$CPH$id2  is the fullname (which you see by looking at the
view source of the generated html) (not the id but the name=... part) of
the field.  I forget whether I've used
window.opener.document.getElementById and it just didn't work; in theory
that should work too.

I've however never seen what you have before - not saying it wouldn't
work - just never seen that done (window.opener.window - I think you
need to get rid of that second window)

var txtLat =
window.opener.window.document.getElementById("txtLatitude");

You should probably throw an alert in there to make sure your
window.opener is returning an object

e.g.
alert("my opener " + window.opener)

As an additional tip - I usually debug javascript in firefox.  Its much
easier than IE as far as debugging goes and the Error Console on it
usually points out where your javascript is failing.

Also when returning values to a parent form and you don't need to
control that field from the code behind, I usually go with a none run at
server field just because I can control the name and id.

I hope some of what I said has helped. Sorry I couldn't be more
informative.

Thanks,
Regina



-----Original Message-----
From: Brian Krebs [mailto:bkrebs at korterra.com]
Sent: Tuesday, April 03, 2007 12:42 PM
To: Obe, Regina; users at openlayers.org
Subject: RE: [OpenLayers-Users] Return Popup Map Click latlon Values
toParentPage

I'm very new to javascript, so I've been trying to use examples I've
found elsewhere, so think of my bad code as merely a placeholder for
where I want the working code to go.

They are within a master page.  I have attempted to pass their
respective ClientId's all the way through to the MappingFuncs.js file,
but regardless of what code I use, txtLat and txtLon vars always come
back as null.

Should I be using window.opener or is there a better way to make my
popup page communicate with the page it was opened from?  I'm open to
any suggestions that will accomplish this.

-----Original Message-----
From: users-bounces at openlayers.org [mailto:users-bounces at openlayers.org]
On Behalf Of Obe, Regina
Sent: Tuesday, April 03, 2007 11:28 AM
To: users at openlayers.org
Subject: Re: [OpenLayers-Users] Return Popup Map Click latlon Values
toParentPage

Not sure why you are doing innerHTML - those are usually used to fill
span and div elements.
 If its a text box, I would think you should be using
txtLat.value =

Also if they are runat server controls - you should verify that the id
is really txtLatitude by looking at the generated view source.  If the
control is within a master page or another container element, then part
of the rendered html id is the containing elements id and not just the
control's aspx id.



________________________________

From: users-bounces at openlayers.org [mailto:users-bounces at openlayers.org]
On Behalf Of Brian Krebs
Sent: Tuesday, April 03, 2007 12:19 PM
To: users at openlayers.org
Subject: [OpenLayers-Users] Return Popup Map Click latlon Values to
ParentPage



I'm working with C# and ASP.Net and am wondering if anyone else has had
to figure out the following scenario:



I'm opening up the map in a popup page using the following code from a
linkbutton click.



    protected void lbMap_Click(object sender, EventArgs e)

    {

        lblMapWarning.Visible = false;

        if (txtLocateCity.Text.Trim() == "")

        {

            lblMapWarning.Visible = true;

            return;

        }

        string street = txtHouseNumber.Text + " " + ddStreetPrefix.Text
+ " " + txtStreetName.Text + " " + ddStreetType.Text + " ";

        street += ddStreetSuffix.Text;

        string city = txtLocateCity.Text;

        string stateCode = "OK";

        //string zipCode = txtZipCode.Text;



        GeoAddress address = geoAPI.GeoEncodeAddress(street.Trim(),
city.Trim(), stateCode);



        string sLat = address.Latitude;

        string sLon = address.Longitude;

        string sZoom = address.Precision;

        if (address.Precision == "address")

            sZoom = "8";

        else

            sZoom = "7";

        string page = "Mapping/MapServer.aspx?lat=" + sLat + "&lon=" +
sLon + "&zoom=" + sZoom;

        string scriptString = buildMapPopupScript(page);



        if (!Page.IsStartupScriptRegistered("Startup"))

            Page.RegisterStartupScript("Startup", scriptString);

    }

    static public string buildMapPopupScript(string url)

    {

        return buildPopupScript(url, 200, 200, 40, 20, 675, 900);

    }

    static public string buildPopupScript(string url,

        int screenX, int screenY, int left, int top, int height, int
width)

    {

        string s = "";

        s += "<script language=javascript>\n";

        s += "window.open('" + url + "',";

        s += "'_blank',";

        s += "'menubar=no,";

        s += "resizable=yes,";

        s += "location=no,";

        s += "directories=no,";

        s += "status=yes,";

        s += "copyhistory=no,";

        s += "screenX=" + Convert.ToString(screenX) + ",";

        s += "screenY=" + Convert.ToString(screenY) + ",";

        s += "left=" + Convert.ToString(left) + ",";

        s += "top=" + Convert.ToString(top) + ",";

        s += "scrollbars=yes,";

        s += "toolbar=yes,";

        s += "height=" + Convert.ToString(height) + ",";

        s += "width=" + Convert.ToString(width) + "');\n";

        s += "</script>";



        return s;

    }



I'm registering a click event in the MappingFuncs.js with this code to
try to return the lat/lon values back to the parent page:



    openLayersMap.events.register("click", openLayersMap, function(e)

    {

        var lonlat = openLayersMap.getLonLatFromViewPortPx(e.xy);

        var markersLayer = new OpenLayers.Layer.Markers("Locate");

        var marker = new OpenLayers.Marker(new
OpenLayers.LonLat(lonlat.lon, lonlat.lat), new
OpenLayers.Icon("http://openlayers.org/api/img/marker.png", new
OpenLayers.Size(15,25)));

        alert("You clicked " + lonlat.lon + ", " + lonlat.lat);

        markersLayer.addMarker(marker);

        openLayersMap.addLayer(markersLayer); 

//        var txtLat =
window.opener.window.document.getElementById("txtLatitude");

//        txtLat.innerHTML = lonlat.lat;

//        var txtLon =
window.opener.window.document.getElementById("txtLongitude");

//        txtLon.innerHTML = lonlat.lon;    

    });



I found the commented code on www.asp.net <http://www.asp.net/>  to use
window.opener, but my vars txtLat and txtLon are always coming back as
null.  Does anyone know a good way to return the lonlat values back to
my textboxes in the parent page?



Thanks






-----------------------------------------
The substance of this message, including any attachments, may be
confidential, legally privileged and/or exempt from disclosure
pursuant to Massachusetts law. It is intended
solely for the addressee. If you received this in error, please
contact the sender and delete the material from any computer.

_______________________________________________
Users mailing list
Users at openlayers.org
http://openlayers.org/mailman/listinfo/users





More information about the Users mailing list