[OpenLayers-Users] How to create a map on the fly, by clicking a button

David Alda Fernandez de Lezea dalda at ikt.es
Tue Jan 26 11:23:03 EST 2010


Hello list, 

I'm trying to make a Gis Web Viewer and I need to generate a Map, after clicking a link/button from one div, into another div. I've created an Object class like this

function MyViewer(){

	
	var map;
	var container;
	
	
	this.MyViewer= MyViewer;
	
	
	function MyViewer(div){
		this.container = div;
		this.map = new OpenLayers.Map( div, {projection: new OpenLayers.Projection("EPSG:23030"), units: 'm', maxExtent: new OpenLayers.Bounds(460000, 4710000, 610000, 4820000), maxResolution: 292.96875});
		 
		...layer definition...
			
		map.zoomToMaxExtent();

		document.getElementById(this.container).style.visibility = "visible";
	}
}

And my html looks like this:

#map { border-style: solid;
border-width: 1px;
margin: 0px auto;
width: 650px;
height: 450px;
position: relative;
float: right;
overflow: auto;
visibility: hidden;
}

....

<body>
<div id="cabecera">
<h2>header</h2>
</div>
<div id="body">
<script type="text/javascript">
		
	function init(){
		var visor = new MyViewer('map');
	}

</script>	
<a href="#" onclick="init();">ShowMap</a><br>

</div>
<div id="map">map...
</div>
</body>

...

But I get an error on line

document.getElementById(this.container).style.visibility = "visible";

Saying:

Uncaught TypeError: Cannot read property 'style' of null

Is it possible to do what I'm trying to do ??

Thanks.

 
 
Un saludo,
 
··················································································

David Alda Fernández de Lezea
Lurralde eta Biodibertsitate Saila / Dpto. de Territorio y Biodiversidad
 
IKT
Granja Modelo s/n · 01192 · Arkaute (Araba)

··················································································
Tlfnos.: 945-00-32-95                         Fax: 945-00.32.90
··················································································
email: dalda at ikt.es                                web: www.ikt.es
··················································································



More information about the Users mailing list