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 center = this.getCenter(),
33 zoom = this.getZoom(),
34 precision = zoomPrecision(zoom),
36 lat: center.lat.toFixed(precision),
37 lon: center.lng.toFixed(precision),
39 layers: this.getLayersCode()
42 if (marker && this.hasLayer(marker)) {
43 params.mlat = marker.getLatLng().lat.toFixed(precision);
44 params.mlon = marker.getLatLng().lng.toFixed(precision);
47 return 'http://' + OSM.SERVER_URL + '/?' + querystring.stringify(params);
50 getShortUrl: function(marker) {
51 var zoom = this.getZoom(),
52 latLng = marker && this.hasLayer(marker) ? marker.getLatLng() : this.getCenter(),
54 char_array = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_~",
55 x = Math.round((latLng.lng + 180.0) * ((1 << 30) / 90.0)),
56 y = Math.round((latLng.lat + 90.0) * ((1 << 30) / 45.0)),
57 // JavaScript only has to keep 32 bits of bitwise operators, so this has to be
58 // done in two parts. each of the parts c1/c2 has 30 bits of the total in it
59 // and drops the last 4 bits of the full 64 bit Morton code.
60 c1 = interlace(x >>> 17, y >>> 17), c2 = interlace((x >>> 2) & 0x7fff, (y >>> 2) & 0x7fff),
63 for (var i = 0; i < Math.ceil((zoom + 8) / 3.0) && i < 5; ++i) {
64 digit = (c1 >> (24 - 6 * i)) & 0x3f;
65 str += char_array.charAt(digit);
67 for (i = 5; i < Math.ceil((zoom + 8) / 3.0); ++i) {
68 digit = (c2 >> (24 - 6 * (i - 5))) & 0x3f;
69 str += char_array.charAt(digit);
71 for (i = 0; i < ((zoom + 8) % 3); ++i) str += "-";
73 // Called to interlace the bits in x and y, making a Morton code.
74 function interlace(x, y) {
75 x = (x | (x << 8)) & 0x00ff00ff;
76 x = (x | (x << 4)) & 0x0f0f0f0f;
77 x = (x | (x << 2)) & 0x33333333;
78 x = (x | (x << 1)) & 0x55555555;
79 y = (y | (y << 8)) & 0x00ff00ff;
80 y = (y | (y << 4)) & 0x0f0f0f0f;
81 y = (y | (y << 2)) & 0x33333333;
82 y = (y | (y << 1)) & 0x55555555;
86 if (marker && this.hasLayer(marker)) {
90 return (window.location.hostname.match(/^www\.openstreetmap\.org/i) ?
91 'http://osm.org/go/' : 'http://' + window.location.hostname + '/go/') + str;
95 L.Icon.Default.imagePath = <%= "#{asset_prefix}/images".to_json %>;