[OpenLayers-Dev] Return Popup Map Click latlon Values to Parent Page

Brian Krebs bkrebs at korterra.com
Mon Apr 2 12:43:49 EDT 2007


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?  Also, is there anyway to not have the
click event called when panning or zooming?

 

Thanks.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-dev/attachments/20070402/94e452a9/attachment.html


More information about the Dev mailing list