]> git.openstreetmap.org Git - rails.git/blob - public/export/embed.html
7fe7d46834476c88567ff3e7451ffc1f34a49c86
[rails.git] / public / export / embed.html
1 <html xmlns="http://www.w3.org/1999/xhtml">
2   <head>
3     <style type="text/css">
4         #map {
5             width: 100%;
6             height: 100%;
7         }
8         .olControlAttribution {
9             bottom: 3px!important;
10         }
11     </style>
12     <script src="http://openstreetmap.org/openlayers/OpenLayers.js"></script>
13     <script src="http://openstreetmap.org/openlayers/OpenStreetMap.js"></script>
14     <script type="text/javascript">
15         var map, layer;
16         function localUpdateLink() {
17             var center = this.map.getCenter();
18
19             // Map not initialized yet. Break out of this function.
20             if (!center) {
21                 return;
22             }
23
24             var params = OpenLayers.Util.getParameters(this.base);
25
26             params.zoom = this.map.getZoom();
27             var lat = center.lat;
28             var lon = center.lon;
29
30             if (this.displayProjection) {
31                 var mapPosition = OpenLayers.Projection.transform(
32                   { x: lon, y: lat },
33                   this.map.getProjectionObject(),
34                   this.displayProjection );
35                 lon = mapPosition.x;
36                 lat = mapPosition.y;
37             }
38
39             params.lat = Math.round(lat*100000)/100000;
40             params.lon = Math.round(lon*100000)/100000;
41
42             var href = this.base;
43             if(href.indexOf('?') != -1) {
44                 href = href.substring( 0, href.indexOf('?') );
45             }
46
47             href += '?' + OpenLayers.Util.getParameterString(params);
48             this.element.href = href;
49         }
50
51         function init(){
52             OpenLayers.Lang.en.permalink = "Larger Map";
53             map = new OpenLayers.Map ("map", {
54               controls: [
55                   new OpenLayers.Control.Attribution(),
56                   new OpenLayers.Control.Navigation(),
57                   new OpenLayers.Control.Permalink(null, "http://openstreetmap.org/", { updateLink: localUpdateLink })
58               ],
59               maxExtent: new OpenLayers.Bounds(-20037508.34,-20037508.34,
60                                                20037508.34,20037508.34),
61               numZoomLevels: 20,
62               maxResolution: 156543.0339,
63               displayProjection: new OpenLayers.Projection("EPSG:4326"),
64               units: 'm',
65               projection: new OpenLayers.Projection("EPSG:900913")
66             });
67
68             var attribution = 'Data by <a target="_parent" href="http://www.openstreetmap.org">OpenStreetMap</a>';
69             var args = OpenLayers.Util.getParameters();
70             if (!args.layer || args.layer == "mapnik") {
71                 var mapnik = new OpenLayers.Layer.OSM.Mapnik("Mapnik", {
72                    displayOutsideMaxExtent: true,
73                    wrapDateLine: true,
74                    attribution: attribution 
75                 });
76                 map.addLayer(mapnik);
77             } else {        
78                 var osmarender = new OpenLayers.Layer.OSM.Osmarender("Osmarender", {
79                    displayOutsideMaxExtent: true,
80                    wrapDateLine: true,
81                    attribution: attribution 
82                 });
83                 map.addLayer(osmarender); 
84             } 
85             if (args.marker) {
86                 var markers = new OpenLayers.Layer.Markers();
87                 map.addLayer(markers);
88                 markers.addMarker( new OpenLayers.Marker(new OpenLayers.LonLat(args.marker[1], args.marker[0]).transform(map.displayProjection, map.getProjectionObject())));
89                 map.marker = true;
90             }    
91             if (args.bbox) { 
92                 var bounds = OpenLayers.Bounds.fromArray(args.bbox).transform(map.displayProjection, map.getProjectionObject());
93                 map.zoomToExtent(bounds)
94             } else {
95                 map.zoomToMaxExtent(); 
96             }
97             var size = map.getSize();
98             if (size.h > 320) {
99                 map.addControl(new OpenLayers.Control.PanZoomBar());
100             } else {
101                 map.addControl(new OpenLayers.Control.PanZoom());
102             }
103         }
104     </script>
105   </head>
106   <body onload="init()">
107     <div id="map"></div>
108   </body>
109 </html>