link goes into external frame, not in the iframe
[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             this.element.target="_blank";
48             href += '?' + OpenLayers.Util.getParameterString(params);
49             this.element.href = href;
50         }
51
52         function init(){
53             OpenLayers.Lang.en.permalink = "Larger Map";
54             map = new OpenLayers.Map ("map", {
55               controls: [
56                   new OpenLayers.Control.Attribution(),
57                   new OpenLayers.Control.Navigation(),
58                   new OpenLayers.Control.Permalink(null, "http://openstreetmap.org/", { updateLink: localUpdateLink })
59               ],
60               maxExtent: new OpenLayers.Bounds(-20037508.34,-20037508.34,
61                                                20037508.34,20037508.34),
62               numZoomLevels: 20,
63               maxResolution: 156543.0339,
64               displayProjection: new OpenLayers.Projection("EPSG:4326"),
65               units: 'm',
66               projection: new OpenLayers.Projection("EPSG:900913")
67             });
68
69             var attribution = 'Data by <a target="_parent" href="http://www.openstreetmap.org">OpenStreetMap</a>';
70             var args = OpenLayers.Util.getParameters();
71             if (!args.layer || args.layer == "mapnik") {
72                 var mapnik = new OpenLayers.Layer.OSM.Mapnik("Mapnik", {
73                    displayOutsideMaxExtent: true,
74                    wrapDateLine: true,
75                    attribution: attribution
76                 });
77                 map.addLayer(mapnik);
78             } else {
79                 var osmarender = new OpenLayers.Layer.OSM.Osmarender("Osmarender", {
80                    displayOutsideMaxExtent: true,
81                    wrapDateLine: true,
82                    attribution: attribution
83                 });
84                 map.addLayer(osmarender);
85             }
86
87             if (args.marker) {
88                 var markers = new OpenLayers.Layer.Markers();
89                 map.addLayer(markers);
90                 markers.addMarker(new OpenLayers.Marker(new OpenLayers.LonLat(args.marker[1], args.marker[0]).transform(map.displayProjection, map.getProjectionObject())));
91                 map.marker = true;
92             }
93
94             if (args.bbox) {
95                 var bounds = OpenLayers.Bounds.fromArray(args.bbox).transform(map.displayProjection, map.getProjectionObject());
96                 map.zoomToExtent(bounds)
97             } else {
98                 map.zoomToMaxExtent();
99             }
100
101             var size = map.getSize();
102             if (size.h > 320) {
103                 map.addControl(new OpenLayers.Control.PanZoomBar());
104             } else {
105                 map.addControl(new OpenLayers.Control.PanZoom());
106             }
107         }
108     </script>
109   </head>
110   <body onload="init()">
111     <div id="map"></div>
112   </body>
113 </html>