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 var latLng = marker.getLatLng().wrap();
37 params.mlat = latLng.lat.toFixed(precision);
38 params.mlon = latLng.lng.toFixed(precision);
42 params[this._object.type] = this._object.id;
45 var url = 'http://' + OSM.SERVER_URL + '/',
46 query = querystring.stringify(params),
47 hash = OSM.formatHash(this);
49 if (query) url += '?' + query;
50 if (hash) url += hash;
55 getShortUrl: function(marker) {
56 var zoom = this.getZoom(),
57 latLng = marker && this.hasLayer(marker) ? marker.getLatLng().wrap() : this.getCenter().wrap(),
58 str = window.location.hostname.match(/^www\.openstreetmap\.org/i) ?
59 'http://osm.org/go/' : 'http://' + window.location.hostname + '/go/',
60 char_array = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_~",
61 x = Math.round((latLng.lng + 180.0) * ((1 << 30) / 90.0)),
62 y = Math.round((latLng.lat + 90.0) * ((1 << 30) / 45.0)),
63 // JavaScript only has to keep 32 bits of bitwise operators, so this has to be
64 // done in two parts. each of the parts c1/c2 has 30 bits of the total in it
65 // and drops the last 4 bits of the full 64 bit Morton code.
66 c1 = interlace(x >>> 17, y >>> 17), c2 = interlace((x >>> 2) & 0x7fff, (y >>> 2) & 0x7fff),
69 for (var i = 0; i < Math.ceil((zoom + 8) / 3.0) && i < 5; ++i) {
70 digit = (c1 >> (24 - 6 * i)) & 0x3f;
71 str += char_array.charAt(digit);
73 for (i = 5; i < Math.ceil((zoom + 8) / 3.0); ++i) {
74 digit = (c2 >> (24 - 6 * (i - 5))) & 0x3f;
75 str += char_array.charAt(digit);
77 for (i = 0; i < ((zoom + 8) % 3); ++i) str += "-";
79 // Called to interlace the bits in x and y, making a Morton code.
80 function interlace(x, y) {
81 x = (x | (x << 8)) & 0x00ff00ff;
82 x = (x | (x << 4)) & 0x0f0f0f0f;
83 x = (x | (x << 2)) & 0x33333333;
84 x = (x | (x << 1)) & 0x55555555;
85 y = (y | (y << 8)) & 0x00ff00ff;
86 y = (y | (y << 4)) & 0x0f0f0f0f;
87 y = (y | (y << 2)) & 0x33333333;
88 y = (y | (y << 1)) & 0x55555555;
94 if (marker && this.hasLayer(marker)) {
99 params[this._object.type] = this._object.id;
102 var query = querystring.stringify(params);
110 addObject: function(object, options) {
111 this._object = object;
113 if (this._objectLoader) this._objectLoader.abort();
114 if (this._objectLayer) this.removeLayer(this._objectLayer);
117 this._objectLoader = $.ajax({
118 url: OSM.apiUrl(object),
120 success: function (xml) {
121 map._objectLayer = new L.OSM.DataLayer(null, {
129 map._objectLayer.interestingNode = function (node, ways, relations) {
130 if (object.type === "node") {
132 } else if (object.type === "relation") {
133 for (var i = 0; i < relations.length; i++)
134 if (relations[i].members.indexOf(node) != -1)
141 map._objectLayer.addData(xml);
143 if (options.zoom) map.fitBounds(map._objectLayer.getBounds());
144 if (options.callback) options.callback(map._objectLayer.getBounds());
146 map._objectLayer.addTo(map);
151 removeObject: function() {
153 if (this._objectLoader) this._objectLoader.abort();
154 if (this._objectLayer) this.removeLayer(this._objectLayer);
158 L.Icon.Default.imagePath = "/images";
160 L.Icon.Default.imageUrls = {
161 "/images/marker-icon.png": "<%= asset_path("images/marker-icon.png") %>",
162 "/images/marker-icon-2x.png": "<%= asset_path("images/marker-icon-2x.png") %>",
163 "/images/marker-shadow.png": "<%= asset_path("images/marker-shadow.png") %>",
164 "/images/marker-shadow-2x.png": "<%= asset_path("images/marker-shadow-2x.png") %>"
167 L.extend(L.Icon.Default.prototype, {
168 _oldGetIconUrl: L.Icon.Default.prototype._getIconUrl,
170 _getIconUrl: function (name) {
171 var url = this._oldGetIconUrl(name);
172 return L.Icon.Default.imageUrls[url];
176 L.Hash.prototype.parseHash = OSM.parseHash;
177 L.Hash.prototype.formatHash = OSM.formatHash;