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;
49 urlTemplate: 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
53 name: I18n.t("javascripts.map.base.standard")
56 urlTemplate: 'http://{s}.tile.opencyclemap.org/cycle/{z}/{x}/{y}.png',
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 urlTemplate: 'http://{s}.tile2.opencyclemap.org/transport/{z}/{x}/{y}.png',
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 urlTemplate: 'http://otile{s}.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.png',
72 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'>",
75 name: I18n.t("javascripts.map.base.mapquest")
79 function createMap(divName, options) {
80 map = L.map(divName, options);
82 if (map.attributionControl) {
83 map.attributionControl.setPrefix(''); // For tmcw
86 var layersControl = L.control.layers();
88 if (!options || options.layerControl !== false) {
89 layersControl.addTo(map);
92 for (var i = 0; i < layers.length; i++) {
93 layers[i].layer = L.tileLayer(layers[i].urlTemplate, layers[i]);
95 layers[i].layer.addTo(map);
97 layersControl.addBaseLayer(layers[i].layer, layers[i].name);
100 $("#" + divName).on("resized", function () {
101 map.invalidateSize();
107 function getArrowIcon() {
109 iconUrl: <%= asset_path('arrow.png').to_json %>,
115 function addMarkerToMap(position, icon, description) {
116 var marker = L.marker(position, icon ? {icon: icon} : null).addTo(map);
119 marker.bindPopup(description);
125 function removeMarkerFromMap(marker) {
126 map.removeLayer(marker);
129 function addObjectToMap(object, zoom, callback) {
131 url: OSM.apiUrl(object),
133 success: function (xml) {
134 var layer = new L.OSM(xml, {
140 fillColor: "lightblue",
145 var bounds = layer.getBounds();
148 map.fitBounds(bounds);
160 function addBoxToMap(bounds) {
161 var box = L.rectangle(bounds, {
172 function getMapBaseLayer() {
173 for (var i = 0; i < layers.length; i++) {
174 if (map.hasLayer(layers[i].layer)) {
180 function getMapLayers() {
181 for (var i = 0; i < layers.length; i++) {
182 if (map.hasLayer(layers[i].layer)) {
183 return layers[i].layerCode;
190 function setMapLayers(layerConfig) {
191 for (var i = 0; i < layers.length; i++) {
192 if (~layerConfig.indexOf(layers[i].layerCode)) {
193 map.addLayer(layers[i].layer);
195 map.removeLayer(layers[i].layer);