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

Arnd Wippermann arnd.wippermann at web.de
Tue Jan 26 12:00:59 EST 2010


Hi,

Your parameter is a string and not an object

var visor = new MyViewer('map'); 

Perhaps this will work:

	function MyViewer(div){
		this.container = document.getElementById(div);


-----Ursprüngliche Nachricht-----
Von: users-bounces at openlayers.org [mailto:users-bounces at openlayers.org] Im
Auftrag von David Alda Fernandez de Lezea
Gesendet: Dienstag, 26. Januar 2010 17:23
An: openlayers users
Betreff: [OpenLayers-Users] How to create a map on the fly,by clicking a
button

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
············································································
······
_______________________________________________
Users mailing list
Users at openlayers.org
http://openlayers.org/mailman/listinfo/users




More information about the Users mailing list