1 L.extend(L.LatLngBounds.prototype, {
3 return (this._northEast.lat - this._southWest.lat) *
4 (this._northEast.lng - this._southWest.lng);
8 return new L.LatLngBounds(this._southWest.wrap(), this._northEast.wrap());
12 L.extend(L.Map.prototype, {
13 getLayersCode: function () {
15 for (var i in this._layers) { // TODO: map.eachLayer
16 var layer = this._layers[i];
17 if (layer.options && layer.options.code) {
18 layerConfig += layer.options.code;
24 getMapBaseLayerId: function () {
25 for (var i in this._layers) { // TODO: map.eachLayer
26 var layer = this._layers[i];
27 if (layer.options && layer.options.keyid) return layer.options.keyid;
31 getUrl: function(marker) {
32 var precision = zoomPrecision(this.getZoom()),
33 params = { layers: this.getLayersCode() };
35 if (marker && this.hasLayer(marker)) {
36 params.mlat = marker.getLatLng().lat.toFixed(precision);
37 params.mlon = marker.getLatLng().lng.toFixed(precision);
40 return 'http://' + OSM.SERVER_URL + '/?' + querystring.stringify(params) +
41 OSM.formatHash({lat: this.getCenter().lat, lon: this.getCenter().lng, zoom: this.getZoom()});
44 getShortUrl: function(marker) {
45 var zoom = this.getZoom(),
46 latLng = marker && this.hasLayer(marker) ? marker.getLatLng() : this.getCenter(),
48 char_array = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_~",
49 x = Math.round((latLng.lng + 180.0) * ((1 << 30) / 90.0)),
50 y = Math.round((latLng.lat + 90.0) * ((1 << 30) / 45.0)),
51 // JavaScript only has to keep 32 bits of bitwise operators, so this has to be
52 // done in two parts. each of the parts c1/c2 has 30 bits of the total in it
53 // and drops the last 4 bits of the full 64 bit Morton code.
54 c1 = interlace(x >>> 17, y >>> 17), c2 = interlace((x >>> 2) & 0x7fff, (y >>> 2) & 0x7fff),
57 for (var i = 0; i < Math.ceil((zoom + 8) / 3.0) && i < 5; ++i) {
58 digit = (c1 >> (24 - 6 * i)) & 0x3f;
59 str += char_array.charAt(digit);
61 for (i = 5; i < Math.ceil((zoom + 8) / 3.0); ++i) {
62 digit = (c2 >> (24 - 6 * (i - 5))) & 0x3f;
63 str += char_array.charAt(digit);
65 for (i = 0; i < ((zoom + 8) % 3); ++i) str += "-";
67 // Called to interlace the bits in x and y, making a Morton code.
68 function interlace(x, y) {
69 x = (x | (x << 8)) & 0x00ff00ff;
70 x = (x | (x << 4)) & 0x0f0f0f0f;
71 x = (x | (x << 2)) & 0x33333333;
72 x = (x | (x << 1)) & 0x55555555;
73 y = (y | (y << 8)) & 0x00ff00ff;
74 y = (y | (y << 4)) & 0x0f0f0f0f;
75 y = (y | (y << 2)) & 0x33333333;
76 y = (y | (y << 1)) & 0x55555555;
80 if (marker && this.hasLayer(marker)) {
84 return (window.location.hostname.match(/^www\.openstreetmap\.org/i) ?
85 'http://osm.org/go/' : 'http://' + window.location.hostname + '/go/') + str;
89 L.Icon.Default.imagePath = <%= "#{asset_prefix}/images".to_json %>;