<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;"><DIV><BR>Dear Andreas,</DIV>
<DIV> </DIV>
<DIV>I have removed "var" from:</DIV>
<DIV> </DIV>
<DIV>> var map = new OpenLayers.Map('map', options );<BR></DIV>
<DIV>it stilt doesn't work, firebug give 2 error messages:</DIV>
<DIV> </DIV>
<DIV>1) header is null -</DIV>
<DIV>header.style.width=(getWindowWidth()-20) + "px";\r\n</DIV>
<DIV> </DIV>
<DIV>(I think this error is not critical, it is from resize() function of TMS)</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>2) map is undefined in go() function</DIV>
<DIV> </DIV>
<DIV>map.setCenter(new OpenLayers.Lonlat(longitude, latitude),5)\r\n</DIV>
<DIV> </DIV>
<DIV>( I have fixed zoom value to 5)</DIV>
<DIV> </DIV>
<DIV>could you please give me further suggestion,</DIV>
<DIV> </DIV>
<DIV>kind regards,</DIV>
<DIV> </DIV>
<DIV>surya</DIV>
<DIV><BR>--- On <B>Tue, 9/8/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: Tuesday, September 8, 2009, 10:00 AM<BR><BR>
<DIV class=plainMail>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 handles the<BR>> map.setCenter, it seems that this function doesn't react to the change<BR>> of lonlat value in drop down list. I have two layers, my base layer is<BR>> a big quickbird image tiled into 6 zoom levels and other layer is WMS<BR>> layer with hundreds of river names. Drop down list should help user to<BR>> pin point selected river in the quickbird image.<BR>> <BR>> When I call init() function it doeas react, but create a series of map<BR>> which doesn't overwrite each other. I certainly do not want to create<BR>> new map every time I change lonlat value, it will double/tripple<BR>> processing time.<BR>> <BR>> <BR>> <BR>>
<BR>> -----------------<BR>> <BR>> function init(){<BR>> <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>> <BR>> var mapBounds = new OpenLayers.Bounds( 225389.527874, 9627709.46055,<BR>> 244613.714826, 9639853.34683 );<BR>> <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 in the<BR>go() function. Remove "var" to make it global.<BR><BR>> <BR>> var layer = new OpenLayers.Layer.TMS( "TMS
Layer","",<BR>> { url: '', serviceVersion: '.', layername: '.', alpha: true,<BR>> type: 'png', getURL: overlay_getTileURL });<BR>> <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>> <BR>> map.addLayers([layer, river]);<BR>> <BR>> map.addControl(new OpenLayers.Control.Scale($('scale')));<BR>> map.setCenter(new OpenLayers.LonLat(231064.944,9631783.43),4);<BR>> } //function init<BR>> <BR>> function go() {<BR>> //Get the selected value for lonlat<BR>> var lonlat = 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 = 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() function.<BR>See my comment above in the init function.<BR><BR>Also, save yourself some lines of code: instead of calculating longitude<BR>and latitude like above, use<BR><BR>map.setCenter(OpenLayers.LonLat.fromString(lonlat);<BR><BR>Regards,<BR>Andreas.<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>