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()),
35 if (marker && this.hasLayer(marker)) {
36 params.mlat = marker.getLatLng().lat.toFixed(precision);
37 params.mlon = marker.getLatLng().lng.toFixed(precision);
41 params[this._object.type] = this._object.id;
44 var url = 'http://' + OSM.SERVER_URL + '/',
45 query = querystring.stringify(params),
46 hash = OSM.formatHash(this);
48 if (query) url += '?' + query;
49 if (hash) url += hash;
54 getShortUrl: function(marker) {
55 var zoom = this.getZoom(),
56 latLng = marker && this.hasLayer(marker) ? marker.getLatLng() : this.getCenter(),
57 str = window.location.hostname.match(/^www\.openstreetmap\.org/i) ?
58 'http://osm.org/go/' : 'http://' + window.location.hostname + '/go/',
59 char_array = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_~",
60 x = Math.round((latLng.lng + 180.0) * ((1 << 30) / 90.0)),
61 y = Math.round((latLng.lat + 90.0) * ((1 << 30) / 45.0)),
62 // JavaScript only has to keep 32 bits of bitwise operators, so this has to be
63 // done in two parts. each of the parts c1/c2 has 30 bits of the total in it
64 // and drops the last 4 bits of the full 64 bit Morton code.
65 c1 = interlace(x >>> 17, y >>> 17), c2 = interlace((x >>> 2) & 0x7fff, (y >>> 2) & 0x7fff),
68 for (var i = 0; i < Math.ceil((zoom + 8) / 3.0) && i < 5; ++i) {
69 digit = (c1 >> (24 - 6 * i)) & 0x3f;
70 str += char_array.charAt(digit);
72 for (i = 5; i < Math.ceil((zoom + 8) / 3.0); ++i) {
73 digit = (c2 >> (24 - 6 * (i - 5))) & 0x3f;
74 str += char_array.charAt(digit);
76 for (i = 0; i < ((zoom + 8) % 3); ++i) str += "-";
78 // Called to interlace the bits in x and y, making a Morton code.
79 function interlace(x, y) {
80 x = (x | (x << 8)) & 0x00ff00ff;
81 x = (x | (x << 4)) & 0x0f0f0f0f;
82 x = (x | (x << 2)) & 0x33333333;
83 x = (x | (x << 1)) & 0x55555555;
84 y = (y | (y << 8)) & 0x00ff00ff;
85 y = (y | (y << 4)) & 0x0f0f0f0f;
86 y = (y | (y << 2)) & 0x33333333;
87 y = (y | (y << 1)) & 0x55555555;
93 if (marker && this.hasLayer(marker)) {
98 params[this._object.type] = this._object.id;
101 var query = querystring.stringify(params);
109 addObject: function(object, options) {
110 this._object = object;
112 if (this._objectLoader) this._objectLoader.abort();
113 if (this._objectLayer) this.removeLayer(this._objectLayer);
116 this._objectLoader = $.ajax({
117 url: OSM.apiUrl(object),
119 success: function (xml) {
120 map._objectLayer = new L.OSM.DataLayer(null, {
128 map._objectLayer.interestingNode = function (node, ways, relations) {
129 if (object.type === "node") {
131 } else if (object.type === "relation") {
132 for (var i = 0; i < relations.length; i++)
133 if (relations[i].members.indexOf(node) != -1)
140 map._objectLayer.addData(xml);
142 if (options.zoom) map.fitBounds(map._objectLayer.getBounds());
143 if (options.callback) options.callback(map._objectLayer.getBounds());
145 map._objectLayer.addTo(map);
151 L.Icon.Default.imagePath = <%= "#{asset_prefix}/images".to_json %>;
153 L.Hash.prototype.parseHash = OSM.parseHash;
154 L.Hash.prototype.formatHash = OSM.formatHash;