2 L.extend(L.LatLngBounds.prototype, {
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);
35 return new L.LatLngBounds(this._southWest.wrap(), this._northEast.wrap());
39 L.extend(L.Bounds.prototype, {
40 getWidth: function () {
41 return this.max.x - this.min.x;
44 getHeight: function () {
45 return this.max.y - this.min.y;
49 L.Icon.Default.imagePath = <%= "#{asset_prefix}/images".to_json %>;
56 function createMap(divName, options) {
64 name: I18n.t("javascripts.map.base.standard")
67 klass: L.OSM.CycleMap,
68 attribution: "Tiles courtesy of <a href='http://www.opencyclemap.org/' target='_blank'>Andy Allan</a>",
71 name: I18n.t("javascripts.map.base.cycle_map")
74 klass: L.OSM.TransportMap,
75 attribution: "Tiles courtesy of <a href='http://www.opencyclemap.org/' target='_blank'>Andy Allan</a>",
76 keyid: "transportmap",
78 name: I18n.t("javascripts.map.base.transport_map")
81 klass: L.OSM.MapQuestOpen,
82 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'>",
85 name: I18n.t("javascripts.map.base.mapquest")
90 options = $.extend({zoomControl: true, panZoomControl: true, layerControl: true}, options);
92 map = L.map(divName, $.extend({}, options, {panControl: false, zoomsliderControl: false, maxZoom: 18}));
94 if (map.attributionControl) {
95 map.attributionControl.setPrefix('');
98 if (options.panZoomControl) {
99 new L.Control.Pan().addTo(map);
100 new L.Control.Zoomslider({stepHeight: 7}).addTo(map);
103 var layersControl = L.control.layers();
105 if (options.layerControl) {
106 layersControl.addTo(map);
107 map.layersControl = layersControl;
110 for (var i = 0; i < layers.length; i++) {
111 layers[i].layer = new (layers[i].klass)(layers[i]);
112 layersControl.addBaseLayer(layers[i].layer, layers[i].name);
115 layers[0].layer.addTo(map);
117 $("#" + divName).on("resized", function () {
118 map.invalidateSize();
124 function getUserIcon(url) {
126 iconUrl: url || <%= asset_path('marker-red.png').to_json %>,
128 iconAnchor: [12, 41],
129 popupAnchor: [1, -34],
130 shadowUrl: <%= asset_path('images/marker-shadow.png').to_json %>,
135 function addObjectToMap(object, zoom, callback) {
137 objectLoader.abort();
141 map.removeLayer(objectLayer);
144 objectLoader = $.ajax({
145 url: OSM.apiUrl(object),
147 success: function (xml) {
148 objectLayer = new L.OSM.DataLayer(null, {
154 fillColor: "lightblue",
159 objectLayer.interestingNode = function (node, ways, relations) {
160 if (object.type === "node") {
162 } else if (object.type === "relation") {
163 for (var i = 0; i < relations.length; i++)
164 if (relations[i].members.indexOf(node) != -1)
171 objectLayer.addData(xml);
173 var bounds = objectLayer.getBounds();
176 map.fitBounds(bounds);
183 objectLayer.addTo(map);
188 function addBoxToMap(bounds) {
189 var box = L.rectangle(bounds, {
200 function getMapBaseLayer() {
201 for (var i = 0; i < layers.length; i++) {
202 if (map.hasLayer(layers[i].layer)) {
208 function getMapLayers() {
209 var layerConfig = "";
210 for (var i = 0; i < layers.length; i++) {
211 if (map.hasLayer(layers[i].layer)) {
212 layerConfig += layers[i].layerCode;
218 function setMapLayers(layerConfig) {
219 var foundLayer = false;
220 for (var i = 0; i < layers.length; i++) {
221 if (layerConfig.indexOf(layers[i].layerCode) >= 0) {
222 map.addLayer(layers[i].layer);
225 map.removeLayer(layers[i].layer);
229 map.addLayer(layers[0].layer);