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 %>;
61 name: I18n.t("javascripts.map.base.standard")
64 klass: L.OSM.CycleMap,
65 attribution: "Tiles courtesy of <a href='http://www.opencyclemap.org/' target='_blank'>Andy Allan</a>",
68 name: I18n.t("javascripts.map.base.cycle_map")
71 klass: L.OSM.TransportMap,
72 attribution: "Tiles courtesy of <a href='http://www.opencyclemap.org/' target='_blank'>Andy Allan</a>",
73 keyid: "transportmap",
75 name: I18n.t("javascripts.map.base.transport_map")
78 klass: L.OSM.MapQuestOpen,
79 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'>",
82 name: I18n.t("javascripts.map.base.mapquest")
86 function createMap(divName, options) {
87 options = $.extend({zoomControl: true, panZoomControl: true, layerControl: true}, options);
89 map = L.map(divName, $.extend({}, options, {panControl: false, zoomsliderControl: false, maxZoom: 18}));
91 if (map.attributionControl) {
92 map.attributionControl.setPrefix('');
95 if (options.panZoomControl) {
96 new L.Control.Pan().addTo(map);
97 new L.Control.Zoomslider({stepHeight: 7}).addTo(map);
100 var layersControl = L.control.layers();
102 if (options.layerControl) {
103 layersControl.addTo(map);
104 map.layersControl = layersControl;
107 for (var i = 0; i < layers.length; i++) {
108 layers[i].layer = new (layers[i].klass)(layers[i]);
109 layersControl.addBaseLayer(layers[i].layer, layers[i].name);
112 layers[0].layer.addTo(map);
114 $("#" + divName).on("resized", function () {
115 map.invalidateSize();
121 function getUserIcon(url) {
123 iconUrl: url || <%= asset_path('marker-red.png').to_json %>,
125 iconAnchor: [12, 41],
126 popupAnchor: [1, -34],
127 shadowUrl: <%= asset_path('images/marker-shadow.png').to_json %>,
132 function addObjectToMap(object, zoom, callback) {
134 objectLoader.abort();
138 map.removeLayer(objectLayer);
141 objectLoader = $.ajax({
142 url: OSM.apiUrl(object),
144 success: function (xml) {
145 objectLayer = new L.OSM.DataLayer(xml, {
151 fillColor: "lightblue",
156 var bounds = objectLayer.getBounds();
159 map.fitBounds(bounds);
166 objectLayer.addTo(map);
171 function addBoxToMap(bounds) {
172 var box = L.rectangle(bounds, {
183 function getMapBaseLayer() {
184 for (var i = 0; i < layers.length; i++) {
185 if (map.hasLayer(layers[i].layer)) {
191 function getMapLayers() {
192 for (var i = 0; i < layers.length; i++) {
193 if (map.hasLayer(layers[i].layer)) {
194 return layers[i].layerCode;
201 function setMapLayers(layerConfig) {
202 var foundLayer = false;
203 for (var i = 0; i < layers.length; i++) {
204 if (layerConfig.indexOf(layers[i].layerCode) >= 0) {
205 map.addLayer(layers[i].layer);
208 map.removeLayer(layers[i].layer);
212 map.addLayer(layers[0].layer);