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: true, 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('');
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]);
102 layersControl.addBaseLayer(layers[i].layer, layers[i].name);
105 layers[0].layer.addTo(map);
107 $("#" + divName).on("resized", function () {
108 map.invalidateSize();
114 function getUserIcon(url) {
116 iconUrl: url || <%= asset_path('marker-red.png').to_json %>,
118 iconAnchor: [12, 41],
119 popupAnchor: [1, -34],
120 shadowUrl: <%= asset_path('images/marker-shadow.png').to_json %>,
125 function addObjectToMap(object, zoom, callback) {
127 url: OSM.apiUrl(object),
129 success: function (xml) {
130 var layer = new L.OSM.DataLayer(xml, {
136 fillColor: "lightblue",
141 var bounds = layer.getBounds();
144 map.fitBounds(bounds);
156 function addBoxToMap(bounds) {
157 var box = L.rectangle(bounds, {
168 function getMapBaseLayer() {
169 for (var i = 0; i < layers.length; i++) {
170 if (map.hasLayer(layers[i].layer)) {
176 function getMapLayers() {
177 for (var i = 0; i < layers.length; i++) {
178 if (map.hasLayer(layers[i].layer)) {
179 return layers[i].layerCode;
186 function setMapLayers(layerConfig) {
187 for (var i = 0; i < layers.length; i++) {
188 if (layerConfig.indexOf(layers[i].layerCode) >= 0) {
189 map.addLayer(layers[i].layer);
191 map.removeLayer(layers[i].layer);