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 getUserIcon(url) {
117 iconUrl: url || <%= asset_path('marker-red.png').to_json %>,
119 iconAnchor: [12, 41],
120 popupAnchor: [1, -34],
121 shadowUrl: <%= asset_path('images/marker-shadow.png').to_json %>,
126 function addObjectToMap(object, zoom, callback) {
128 url: OSM.apiUrl(object),
130 success: function (xml) {
131 var layer = new L.OSM.DataLayer(xml, {
137 fillColor: "lightblue",
142 var bounds = layer.getBounds();
145 map.fitBounds(bounds);
157 function addBoxToMap(bounds) {
158 var box = L.rectangle(bounds, {
169 function getMapBaseLayer() {
170 for (var i = 0; i < layers.length; i++) {
171 if (map.hasLayer(layers[i].layer)) {
177 function getMapLayers() {
178 for (var i = 0; i < layers.length; i++) {
179 if (map.hasLayer(layers[i].layer)) {
180 return layers[i].layerCode;
187 function setMapLayers(layerConfig) {
188 for (var i = 0; i < layers.length; i++) {
189 if (~layerConfig.indexOf(layers[i].layerCode)) {
190 map.addLayer(layers[i].layer);
192 map.removeLayer(layers[i].layer);