[Users] Javscript challenge: put map.getcenter into print form
Robert Buckley
robertdbuckley at yahoo.com
Tue Nov 22 11:27:26 CET 2011
Hi,
I have almost completed this task, but am stuck with the last bit.
....with the following code I can output the current map.getcenter coordinates to a hidden div called 'centercoords'. When the map is panned, the div is updated.
var centercoordsOutput = document.getElementById('centercoords');
function getMapCenter() {
var latlon =map.getCenter();
centercoordsOutput.innerHTML = latlon;
return latlon
}
// update the bounds with each map move
map.events.register('moveend', map, getMapCenter);
// and update the bounds on first load
getMapCenter();
....I then use the innerHTML of the hidden div 'centercoords' to enter the latlon center coords into a textarea in my printpreview window which in turn will print them on the map by defining the variable in config.yaml
{
text:" - PDF Drucken",
icon: "../images/printer.png",
tooltip: {
title: "Export",
text: "Karte als PDF-Datei exportieren"
},
handler: function () {
printsettings.show();
pageLayer.setVisibility(true);
// get contents of div
var getmapbounds = document.getElementById('centercoords').innerHTML;
// assign content to textarea
var coordsbox = document.getElementById('coordstextarea');
coordstextarea.value=getmapbounds;
}
This basically works as can be seen here....http://maps.zgb.de/lws.html but I still have a couple of challenges...
1. once the print window is shown, the mapcenter coordinates are not updated anymore, so if I then pan the map, the mapcenter coordinates will be wrong.
2. The variable doesn´t get printed unless I set the textarea focus property to true.
3. I have to set a variable in config.yaml for the coordinates. This means other apps which do not have this variable now get an error and do not print
If anyone can see any workarounds or ways to improve my code I would be most grateful,
Yours,
Rob
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.geoext.org/pipermail/users/attachments/20111122/33d9681c/attachment.htm
More information about the Users
mailing list