2 L.LatLngBounds.include({
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);
36 getWidth: function () {
37 return this.max.x - this.min.x;
40 getHeight: function () {
41 return this.max.y - this.min.y;
45 L.Icon.Default.imagePath = <%= "#{asset_prefix}/images".to_json %>;
55 name: I18n.t("javascripts.map.base.standard")
58 klass: L.OSM.CycleMap,
59 attribution: "Tiles courtesy of <a href='http://www.opencyclemap.org/' target='_blank'>Andy Allan</a>",
62 name: I18n.t("javascripts.map.base.cycle_map")
65 klass: L.OSM.TransportMap,
66 attribution: "Tiles courtesy of <a href='http://www.opencyclemap.org/' target='_blank'>Andy Allan</a>",
67 keyid: "transportmap",
69 name: I18n.t("javascripts.map.base.transport_map")
72 klass: L.OSM.MapQuestOpen,
73 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'>",
76 name: I18n.t("javascripts.map.base.mapquest")
80 function createMap(divName, options) {
81 options = $.extend({zoomControl: false, panZoomControl: true, layerControl: true}, options);
83 map = L.map(divName, $.extend({}, options, {panControl: false, zoomsliderControl: false, maxZoom: 18}));
85 if (map.attributionControl) {
86 map.attributionControl.setPrefix(''); // For tmcw
89 if (options.panZoomControl) {
90 new L.Control.Pan().addTo(map);
91 new L.Control.Zoomslider({stepHeight: 7}).addTo(map);
94 var layersControl = L.control.layers();
96 if (options.layerControl) {
97 layersControl.addTo(map);
100 for (var i = 0; i < layers.length; i++) {
101 layers[i].layer = new (layers[i].klass)(layers[i]);
103 layers[i].layer.addTo(map);
105 layersControl.addBaseLayer(layers[i].layer, layers[i].name);
108 $("#" + divName).on("resized", function () {
109 map.invalidateSize();
115 function getArrowIcon() {
117 iconUrl: <%= asset_path('arrow.png').to_json %>,
123 function getUserIcon(url) {
125 iconUrl: url || <%= asset_path('marker-red.png').to_json %>,
131 function addObjectToMap(object, zoom, callback) {
133 url: OSM.apiUrl(object),
135 success: function (xml) {
136 var layer = new L.OSM.DataLayer(xml, {
142 fillColor: "lightblue",
147 var bounds = layer.getBounds();
150 map.fitBounds(bounds);
162 function addBoxToMap(bounds) {
163 var box = L.rectangle(bounds, {
174 function getMapBaseLayer() {
175 for (var i = 0; i < layers.length; i++) {
176 if (map.hasLayer(layers[i].layer)) {
182 function getMapLayers() {
183 for (var i = 0; i < layers.length; i++) {
184 if (map.hasLayer(layers[i].layer)) {
185 return layers[i].layerCode;
192 function setMapLayers(layerConfig) {
193 for (var i = 0; i < layers.length; i++) {
194 if (~layerConfig.indexOf(layers[i].layerCode)) {
195 map.addLayer(layers[i].layer);
197 map.removeLayer(layers[i].layer);