14 function lon2merc(lon) {
15 return 20037508.34 * lon / 180;
18 function lat2merc(lat) {
19 lat = Math.log(Math.tan( (90 + lat) * PI / 360)) / PI;
20 return 20037508.34 * lat;
23 function merc2lon(lon) {
24 return lon*180/20037508.34;
27 function merc2lat(lat) {
28 return Math.atan(Math.exp(lat*PI/20037508.34))*360/PI-90;
31 OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, {
32 defaultHandlerOptions: {
40 initialize: function(options) {
41 this.handlerOptions = OpenLayers.Util.extend(
42 {}, this.defaultHandlerOptions
44 OpenLayers.Control.prototype.initialize.apply(
47 this.handler = new OpenLayers.Handler.Click(
50 }, this.handlerOptions
54 trigger: function(e) {
55 var lonlat = map.getLonLatFromViewPortPx(e.xy);
56 lat=merc2lat(lonlat.lat);
57 lon=merc2lon(lonlat.lon);
58 if(parent.document.getElementById(latfield_id)==null){
59 latfield=document.getElementById('osmlat');
61 latfield=parent.document.getElementById(latfield_id);
63 if(parent.document.getElementById(lonfield_id)==null){
64 lonfield=document.getElementById('osmlon');
66 lonfield=parent.document.getElementById(lonfield_id);
74 var field = window.name.substring(0, window.name.lastIndexOf("."));
75 if(parent.document.getElementById(field+".latfield")!=null){
76 latfield_id = parent.document.getElementById(field+".latfield").value;
77 document.getElementById('osm').style.display="none";
79 if(parent.document.getElementById(field+".lonfield")!=null){
80 lonfield_id = parent.document.getElementById(field+".lonfield").value;
82 if(parent.document.getElementById(field+".centerlat")!=null){
83 centerlat =parseFloat(parent.document.getElementById(field+".centerlat").value);
85 if(parent.document.getElementById(field+".centerlon")!=null){
86 centerlon = parseFloat(parent.document.getElementById(field+".centerlon").value);
88 if(parent.document.getElementById(field+".zoom")!=null){
89 zoom = parseFloat(parent.document.getElementById(field+".zoom").value);
94 OpenLayers.Lang.setCode('de');
95 mapdiv=document.getElementById('map');
96 mapdiv.style.height=window.innerHeight+"px";
97 mapdiv.style.width=window.innerWidth+"px";
98 map = new OpenLayers.Map('map', {
99 projection: new OpenLayers.Projection("EPSG:900913"),
100 displayProjection: new OpenLayers.Projection("EPSG:4326"),
102 new OpenLayers.Control.MouseDefaults(),
103 new OpenLayers.Control.PanZoomBar()],
105 new OpenLayers.Bounds(-20037508.34,-20037508.34, 20037508.34, 20037508.34),
107 maxResolution: 156543,
111 layer_mapnik = new OpenLayers.Layer.OSM.Mapnik("Mapnik");
113 map.addLayers([layer_mapnik]);
114 var y =lat2merc(centerlat);
115 var x =lon2merc(centerlon);
116 map.setCenter(new OpenLayers.LonLat(x, y), zoom);
118 // Check for geolocation support
119 if(navigator.geolocation){
120 navigator.geolocation.getCurrentPosition(function(position){
121 var y =lat2merc(position.coords.latitude);
122 var x =lon2merc(position.coords.longitude);
123 map.setCenter(new OpenLayers.LonLat(x, y), '17');
127 var click = new OpenLayers.Control.Click();
128 map.addControl(click);