2 L.extend(L.LatLngBounds.prototype, {
3 getSouthLat: function () {
4 return this._southWest.lat;
7 getWestLng: function () {
8 return this._southWest.lng;
11 getNorthLat: function () {
12 return this._northEast.lat;
15 getEastLng: function () {
16 return this._northEast.lng;
21 var mult = Math.pow(10, decimal);
22 var xmin = Math.round(this.getWestLng() * mult) / mult;
23 var ymin = Math.round(this.getSouthLat() * mult) / mult;
24 var xmax = Math.round(this.getEastLng() * mult) / mult;
25 var ymax = Math.round(this.getNorthLat() * mult) / mult;
26 return xmin + "," + ymin + "," + xmax + "," + ymax;
29 getSize: function () {
30 return (this._northEast.lat - this._southWest.lat) *
31 (this._northEast.lng - this._southWest.lng);
35 return new L.LatLngBounds(this._southWest.wrap(), this._northEast.wrap());
39 L.extend(L.Bounds.prototype, {
40 getWidth: function () {
41 return this.max.x - this.min.x;
44 getHeight: function () {
45 return this.max.y - this.min.y;
49 L.Icon.Default.imagePath = <%= "#{asset_prefix}/images".to_json %>;
59 name: I18n.t("javascripts.map.base.standard")
62 klass: L.OSM.CycleMap,
63 attribution: "Tiles courtesy of <a href='http://www.opencyclemap.org/' target='_blank'>Andy Allan</a>",
66 name: I18n.t("javascripts.map.base.cycle_map")
69 klass: L.OSM.TransportMap,
70 attribution: "Tiles courtesy of <a href='http://www.opencyclemap.org/' target='_blank'>Andy Allan</a>",
71 keyid: "transportmap",
73 name: I18n.t("javascripts.map.base.transport_map")
76 klass: L.OSM.MapQuestOpen,
77 attribution: "Tiles courtesy of <a href='http://www.mapquest.com/' target='_blank'>MapQuest</a> <img src='http://developer.mapquest.com/content/osm/mq_logo.png'>",
80 name: I18n.t("javascripts.map.base.mapquest")
84 function createMap(divName, options) {
85 options = $.extend({zoomControl: true, panZoomControl: true, layerControl: true}, options);
87 map = L.map(divName, $.extend({}, options, {panControl: false, zoomsliderControl: false, maxZoom: 18}));
89 if (map.attributionControl) {
90 map.attributionControl.setPrefix('');
93 if (options.panZoomControl) {
94 new L.Control.Pan().addTo(map);
95 new L.Control.Zoomslider({stepHeight: 7}).addTo(map);
98 var layersControl = L.control.layers();
100 if (options.layerControl) {
101 layersControl.addTo(map);
102 map.layersControl = layersControl;
105 for (var i = 0; i < layers.length; i++) {
106 layers[i].layer = new (layers[i].klass)(layers[i]);
107 layersControl.addBaseLayer(layers[i].layer, layers[i].name);
110 layers[0].layer.addTo(map);
112 $("#" + divName).on("resized", function () {
113 map.invalidateSize();
119 function getUserIcon(url) {
121 iconUrl: url || <%= asset_path('marker-red.png').to_json %>,
123 iconAnchor: [12, 41],
124 popupAnchor: [1, -34],
125 shadowUrl: <%= asset_path('images/marker-shadow.png').to_json %>,
130 function addObjectToMap(object, zoom, callback) {
132 url: OSM.apiUrl(object),
134 success: function (xml) {
135 var layer = new L.OSM.DataLayer(xml, {
141 fillColor: "lightblue",
146 var bounds = layer.getBounds();
149 map.fitBounds(bounds);
161 function addBoxToMap(bounds) {
162 var box = L.rectangle(bounds, {
173 function getMapBaseLayer() {
174 for (var i = 0; i < layers.length; i++) {
175 if (map.hasLayer(layers[i].layer)) {
181 function getMapLayers() {
182 for (var i = 0; i < layers.length; i++) {
183 if (map.hasLayer(layers[i].layer)) {
184 return layers[i].layerCode;
191 function setMapLayers(layerConfig) {
192 var foundLayer = false;
193 for (var i = 0; i < layers.length; i++) {
194 if (layerConfig.indexOf(layers[i].layerCode) >= 0) {
195 map.addLayer(layers[i].layer);
198 map.removeLayer(layers[i].layer);
202 map.addLayer(layers[0].layer);