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;
53 name: I18n.t("javascripts.map.base.standard")
56 klass: L.OSM.CycleMap,
57 attribution: "Tiles courtesy of <a href='http://www.opencyclemap.org/' target='_blank'>Andy Allan</a>",
60 name: I18n.t("javascripts.map.base.cycle_map")
63 klass: L.OSM.TransportMap,
64 attribution: "Tiles courtesy of <a href='http://www.opencyclemap.org/' target='_blank'>Andy Allan</a>",
65 keyid: "transportmap",
67 name: I18n.t("javascripts.map.base.transport_map")
70 klass: L.OSM.MapQuestOpen,
71 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'>",
74 name: I18n.t("javascripts.map.base.mapquest")
78 function createMap(divName, options) {
79 map = L.map(divName, options);
81 if (map.attributionControl) {
82 map.attributionControl.setPrefix(''); // For tmcw
85 var layersControl = L.control.layers();
87 if (!options || options.layerControl !== false) {
88 layersControl.addTo(map);
91 for (var i = 0; i < layers.length; i++) {
92 layers[i].layer = new (layers[i].klass)(layers[i]);
94 layers[i].layer.addTo(map);
96 layersControl.addBaseLayer(layers[i].layer, layers[i].name);
99 $("#" + divName).on("resized", function () {
100 map.invalidateSize();
106 function getArrowIcon() {
108 iconUrl: <%= asset_path('arrow.png').to_json %>,
114 function addMarkerToMap(position, icon, description) {
115 var marker = L.marker(position, icon ? {icon: icon} : null).addTo(map);
118 marker.bindPopup(description);
124 function removeMarkerFromMap(marker) {
125 map.removeLayer(marker);
128 function addObjectToMap(object, zoom, callback) {
130 url: OSM.apiUrl(object),
132 success: function (xml) {
133 var layer = new L.OSM.DataLayer(xml, {
139 fillColor: "lightblue",
144 var bounds = layer.getBounds();
147 map.fitBounds(bounds);
159 function addBoxToMap(bounds) {
160 var box = L.rectangle(bounds, {
171 function getMapBaseLayer() {
172 for (var i = 0; i < layers.length; i++) {
173 if (map.hasLayer(layers[i].layer)) {
179 function getMapLayers() {
180 for (var i = 0; i < layers.length; i++) {
181 if (map.hasLayer(layers[i].layer)) {
182 return layers[i].layerCode;
189 function setMapLayers(layerConfig) {
190 for (var i = 0; i < layers.length; i++) {
191 if (~layerConfig.indexOf(layers[i].layerCode)) {
192 map.addLayer(layers[i].layer);
194 map.removeLayer(layers[i].layer);