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 addMarkerToMap(position, icon, description) {
124 var marker = L.marker(position, icon ? {icon: icon} : null).addTo(map);
127 marker.bindPopup(description);
133 function removeMarkerFromMap(marker) {
134 map.removeLayer(marker);
137 function addObjectToMap(object, zoom, callback) {
139 url: OSM.apiUrl(object),
141 success: function (xml) {
142 var layer = new L.OSM.DataLayer(xml, {
148 fillColor: "lightblue",
153 var bounds = layer.getBounds();
156 map.fitBounds(bounds);
168 function addBoxToMap(bounds) {
169 var box = L.rectangle(bounds, {
180 function getMapBaseLayer() {
181 for (var i = 0; i < layers.length; i++) {
182 if (map.hasLayer(layers[i].layer)) {
188 function getMapLayers() {
189 for (var i = 0; i < layers.length; i++) {
190 if (map.hasLayer(layers[i].layer)) {
191 return layers[i].layerCode;
198 function setMapLayers(layerConfig) {
199 for (var i = 0; i < layers.length; i++) {
200 if (~layerConfig.indexOf(layers[i].layerCode)) {
201 map.addLayer(layers[i].layer);
203 map.removeLayer(layers[i].layer);