]> git.openstreetmap.org Git - rails.git/blob - app/assets/javascripts/embed.js.erb
57572ca48ff31dee1cd998d5312c6886443f37fb
[rails.git] / app / assets / javascripts / embed.js.erb
1 //= require leaflet
2 //= require leaflet.osm
3
4 window.onload = function () {
5   var query = (window.location.search || '?').substr(1),
6       args  = {};
7
8   query.replace(/([^&=]+)=?([^&]*)(?:&+|$)/g, function(match, key, value) {
9     value = value.split(",");
10     if (value.length == 1)
11       value = value[0];
12     args[key] = value;
13   });
14
15   var map = L.map("map");
16   map.attributionControl.setPrefix('');
17
18   if (!args.layer || args.layer == "mapnik" || args.layer == "osmarender") {
19     new L.OSM.Mapnik().addTo(map);
20   } else if (args.layer == "cyclemap" || args.layer == "cycle map") {
21     new L.OSM.CycleMap().addTo(map);
22   } else if (args.layer == "transportmap") {
23     new L.OSM.TransportMap().addTo(map);
24   } else if (args.layer == "mapquest") {
25     new L.OSM.MapQuestOpen().addTo(map);
26   }
27
28   if (args.marker) {
29     L.marker(args.marker, {icon: L.icon({
30       iconUrl: <%= asset_path('images/marker-icon.png').to_json %>,
31       iconSize: new L.Point(25, 41),
32       iconAnchor: new L.Point(12, 41),
33       shadowUrl: <%= asset_path('images/marker-shadow.png').to_json %>,
34       shadowSize: new L.Point(41, 41)
35     })}).addTo(map);
36   }
37
38   if (args.bbox) {
39     map.fitBounds([L.latLng(args.bbox[1], args.bbox[0]),
40                    L.latLng(args.bbox[3], args.bbox[2])])
41   } else {
42     map.fitWorld();
43   }
44 };