<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;"><DIV>Dear Andreas,</DIV>
<DIV> </DIV>
<DIV>it is working now. Thank you very much for the hints and also thank you for Jerome, who has provided script for lonlat input form .</DIV>
<DIV> </DIV>
<DIV>kind regards,</DIV>
<DIV> </DIV>
<DIV>surya</DIV>
<DIV> </DIV>
<DIV><BR><BR>--- On <B>Wed, 9/9/09, Andreas Hocevar <I><ahocevar@opengeo..org></I></B> wrote:<BR></DIV>
<BLOCKQUOTE style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: rgb(16,16,255) 2px solid"><BR>From: Andreas Hocevar <ahocevar@opengeo.org><BR>Subject: Re: [OpenLayers-Users] Ovewriting previous map<BR>To: "Surya Tarigan" <surya.tarigan@yahoo.com><BR>Cc: users@openlayers.org<BR>Date: Wednesday, September 9, 2009, 8:54 AM<BR><BR>
<DIV class=plainMail>Surya Tarigan wrote:<BR>> <BR>> Dear Andreas,<BR>> I have removed "var" from:<BR>> > var map = new OpenLayers.Map('map', options );<BR>> it stilt doesn't work, firebug give 2 error messages:<BR>> 1) header is null -<BR>> header..style.width=(getWindowWidth()-20) + "px";\r\n<BR>> (I think this error is not critical, it is from resize() function of TMS)<BR>> 2) map is undefined in go() function<BR>> <BR><BR>Maybe because you call go() before init()? To make sure, you can also define var outside the go and init functions:<BR><BR><script><BR>...<BR>var map;<BR>function init() {}<BR>function go() {}<BR>...<BR></script><BR><BR>Just look at the OpenLayers examples, there are many with forms and do just about the same...<BR><BR>Regards,<BR>Andreas.<BR><BR>> map.setCenter(new OpenLayers.Lonlat(longitude, latitude),5)\r\n<BR>> ( I have
fixed zoom value to 5)<BR>> could you please give me further suggestion,<BR>> kind regards,<BR>> surya<BR>> <BR>> --- On *Tue, 9/8/09, Andreas Hocevar /<<A href="http://us.mc1119.mail.yahoo.com/mc/compose?to=ahocevar@opengeo.org" ymailto="mailto:ahocevar@opengeo.org">ahocevar@opengeo.org</A>>/* wrote:<BR>> <BR>> <BR>> From: Andreas Hocevar <<A href="http://us.mc1119.mail.yahoo.com/mc/compose?to=ahocevar@opengeo.org" ymailto="mailto:ahocevar@opengeo.org">ahocevar@opengeo.org</A>><BR>> Subject: Re: [OpenLayers-Users] Ovewriting previous map<BR>> To: "Surya Tarigan" <<A href="http://us.mc1119.mail.yahoo.com/mc/compose?to=surya.tarigan@yahoo.com" ymailto="mailto:surya.tarigan@yahoo.com">surya.tarigan@yahoo.com</A>><BR>> Cc: <A
href="http://us.mc1119.mail.yahoo.com/mc/compose?to=users@openlayers.org" ymailto="mailto:users@openlayers.org">users@openlayers.org</A><BR>> Date: Tuesday, September 8, 2009, 10:00 AM<BR>> <BR>> Hi,<BR>> <BR>> see my comments inline, and use a javascript debugger like Firebug for<BR>> Firefox to see what is going on.<BR>> <BR>> Surya Tarigan wrote:<BR>> ><BR>> > Formerly, I call go() function (see snippet below) which<BR>> handles the<BR>> > map.setCenter, it seems that this function doesn't react to the<BR>> change<BR>> > of lonlat value in drop down list. I have two layers, my base<BR>> layer
is<BR>> > a big quickbird image tiled into 6 zoom levels and other layer<BR>> is WMS<BR>> > layer with hundreds of river names. Drop down list should help<BR>> user to<BR>> > pin point selected river in the quickbird image.<BR>> > > When I call init() function it doeas react, but create a series<BR>> of map<BR>> > which doesn't overwrite each other. I certainly do not want to<BR>> create<BR>> > new map every time I change lonlat value, it will double/tripple<BR>> > processing time.<BR>> > > > >
> -----------------<BR>> > > function init(){<BR>> > > var options = {<BR>> > theme: null,<BR>> > maxExtent: new OpenLayers.Bounds(225389.527874, 9627709.46055,<BR>> > 244613.714826, 9639853.34683 ),<BR>> > maxResolution: 103.338482,<BR>> > projection: 'EPSG:4326',<BR>> > units: 'm',<BR>> > controls: [<BR>> > new OpenLayers.Control.LayerSwitcher(),<BR>> > new OpenLayers.Control.MousePosition(),<BR>> > new OpenLayers.Control.PanZoom(),<BR>> > new OpenLayers.Control.ScaleLine()<BR>>
> ]<BR>> > }; //option<BR>> > > var mapBounds = new OpenLayers.Bounds( 225389.527874, 9627709.46055,<BR>> > 244613.714826, 9639853.34683 );<BR>> > > var map = new OpenLayers.Map('map', options );<BR>> ><BR>> <BR>> map is local to the init function here, so it won't be available<BR>> in the<BR>> go() function. Remove "var" to make it global.<BR>> <BR>> > > var layer = new OpenLayers.Layer.TMS( "TMS Layer","",<BR>> > { url: '', serviceVersion: '.', layername: '.', alpha: true,<BR>> > type: 'png', getURL: overlay_getTileURL
});<BR>> > > var river = new OpenLayers.Layer.WMS(<BR>> > "topp:sungai_nr - river", "<A href="http://localhost:8080/geoserver/wms" target=_blank>http://localhost:8080/geoserver/wms</A>",<BR>> > {layers: 'topp:sungai_nr',<BR>> > format: 'image/png',transparent:'true'},{'opacity': 0.2});<BR>> > > map.addLayers([layer, river]);<BR>> > > map.addControl(new OpenLayers.Control.Scale($('scale')));<BR>> > map.setCenter(new OpenLayers.LonLat(231064.944,9631783.43),4);<BR>> > } //function init<BR>> > > function go() {<BR>> > //Get the selected value for
lonlat<BR>> > var lonlat =<BR>> document.getElementById('lonlat').options[document.getElementById('lonlat').selectedIndex].value;<BR>> > // Parse the lonlat to get the longitude<BR>> > var longitude = lonlat.substring(0,lonlat.indexOf(','));<BR>> > // Parse the lonlat to get the latitude<BR>> > var latitude =<BR>> lonlat.substring(lonlat.indexOf(',')+1,lonlat.length);<BR>> > // set Center<BR>> > map.setCenter(new OpenLayers.LonLat(longitude,latitude),zoom);<BR>> ><BR>> <BR>> The above will fail because your map is not known to the go()<BR>> function.<BR>> See my comment above in the
init function.<BR>> <BR>> Also, save yourself some lines of code: instead of calculating<BR>> longitude<BR>> and latitude like above, use<BR>> <BR>> map.setCenter(OpenLayers.LonLat.fromString(lonlat);<BR>> <BR>> Regards,<BR>> Andreas.<BR>> <BR>> -- Andreas Hocevar<BR>> OpenGeo - <A href="http://opengeo.org/" target=_blank>http://opengeo.org/</A><BR>> Expert service straight from the developers.<BR>> <BR>> <BR>> ------------------------------------------------------------------------<BR>> <BR>> _______________________________________________<BR>> Users mailing list<BR>> <A href="http://us.mc1119.mail.yahoo.com/mc/compose?to=Users@openlayers.org"
ymailto="mailto:Users@openlayers.org">Users@openlayers.org</A><BR>> <A href="http://openlayers.org/mailman/listinfo/users" target=_blank>http://openlayers.org/mailman/listinfo/users</A><BR>> <BR><BR><BR>-- Andreas Hocevar<BR>OpenGeo - <A href="http://opengeo.org/" target=_blank>http://opengeo.org/</A><BR>Expert service straight from the developers.<BR><BR></DIV></BLOCKQUOTE></td></tr></table><br>