Include object in share link
This commit is contained in:
parent
95ce2515d1
commit
a125ee829a
4 changed files with 64 additions and 48 deletions
|
@ -57,8 +57,8 @@ $(document).ready(function () {
|
||||||
object.version = params.version - 1;
|
object.version = params.version - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
addObjectToMap(object, map, {
|
map.addObject(object, {
|
||||||
zoom: true,
|
zoom: true,
|
||||||
callback: function(extent) {
|
callback: function(extent) {
|
||||||
$("#loading").hide();
|
$("#loading").hide();
|
||||||
$("#browse_map .geolink").show();
|
$("#browse_map .geolink").show();
|
||||||
|
|
|
@ -136,7 +136,7 @@ $(document).ready(function () {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (params.object) {
|
if (params.object) {
|
||||||
addObjectToMap(params.object, map, { zoom: params.object_zoom });
|
map.addObject(params.object, { zoom: params.object_zoom });
|
||||||
}
|
}
|
||||||
|
|
||||||
$("body").on("click", "a.set_position", setPositionLink(map));
|
$("body").on("click", "a.set_position", setPositionLink(map));
|
||||||
|
@ -195,7 +195,7 @@ function setPositionLink(map) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.type && data.id) {
|
if (data.type && data.id) {
|
||||||
addObjectToMap(data, map, { zoom: true, style: { opacity: 0.2, fill: false } });
|
map.addObject(data, { zoom: true, style: { opacity: 0.2, fill: false } });
|
||||||
}
|
}
|
||||||
|
|
||||||
map.markerLayer.clearLayers();
|
map.markerLayer.clearLayers();
|
||||||
|
|
|
@ -37,6 +37,10 @@ L.extend(L.Map.prototype, {
|
||||||
params.mlon = marker.getLatLng().lng.toFixed(precision);
|
params.mlon = marker.getLatLng().lng.toFixed(precision);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this._object) {
|
||||||
|
params[this._object.type] = this._object.id;
|
||||||
|
}
|
||||||
|
|
||||||
var url = 'http://' + OSM.SERVER_URL + '/',
|
var url = 'http://' + OSM.SERVER_URL + '/',
|
||||||
query = querystring.stringify(params),
|
query = querystring.stringify(params),
|
||||||
hash = OSM.formatHash(this);
|
hash = OSM.formatHash(this);
|
||||||
|
@ -50,7 +54,8 @@ L.extend(L.Map.prototype, {
|
||||||
getShortUrl: function(marker) {
|
getShortUrl: function(marker) {
|
||||||
var zoom = this.getZoom(),
|
var zoom = this.getZoom(),
|
||||||
latLng = marker && this.hasLayer(marker) ? marker.getLatLng() : this.getCenter(),
|
latLng = marker && this.hasLayer(marker) ? marker.getLatLng() : this.getCenter(),
|
||||||
str = '',
|
str = window.location.hostname.match(/^www\.openstreetmap\.org/i) ?
|
||||||
|
'http://osm.org/go/' : 'http://' + window.location.hostname + '/go/',
|
||||||
char_array = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_~",
|
char_array = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_~",
|
||||||
x = Math.round((latLng.lng + 180.0) * ((1 << 30) / 90.0)),
|
x = Math.round((latLng.lng + 180.0) * ((1 << 30) / 90.0)),
|
||||||
y = Math.round((latLng.lat + 90.0) * ((1 << 30) / 45.0)),
|
y = Math.round((latLng.lat + 90.0) * ((1 << 30) / 45.0)),
|
||||||
|
@ -83,12 +88,63 @@ L.extend(L.Map.prototype, {
|
||||||
return (x << 1) | y;
|
return (x << 1) | y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var params = {};
|
||||||
|
|
||||||
if (marker && this.hasLayer(marker)) {
|
if (marker && this.hasLayer(marker)) {
|
||||||
str += '?m'
|
params.m = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
return (window.location.hostname.match(/^www\.openstreetmap\.org/i) ?
|
if (this._object) {
|
||||||
'http://osm.org/go/' : 'http://' + window.location.hostname + '/go/') + str;
|
params[this._object.type] = this._object.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
var query = querystring.stringify(params);
|
||||||
|
if (query) {
|
||||||
|
str += '?' + query;
|
||||||
|
}
|
||||||
|
|
||||||
|
return str;
|
||||||
|
},
|
||||||
|
|
||||||
|
addObject: function(object, options) {
|
||||||
|
this._object = object;
|
||||||
|
|
||||||
|
if (this._objectLoader) this._objectLoader.abort();
|
||||||
|
if (this._objectLayer) this.removeLayer(this._objectLayer);
|
||||||
|
|
||||||
|
var map = this;
|
||||||
|
this._objectLoader = $.ajax({
|
||||||
|
url: OSM.apiUrl(object),
|
||||||
|
dataType: "xml",
|
||||||
|
success: function (xml) {
|
||||||
|
map._objectLayer = new L.OSM.DataLayer(null, {
|
||||||
|
styles: {
|
||||||
|
node: options.style,
|
||||||
|
way: options.style,
|
||||||
|
area: options.style
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
map._objectLayer.interestingNode = function (node, ways, relations) {
|
||||||
|
if (object.type === "node") {
|
||||||
|
return true;
|
||||||
|
} else if (object.type === "relation") {
|
||||||
|
for (var i = 0; i < relations.length; i++)
|
||||||
|
if (relations[i].members.indexOf(node) != -1)
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
map._objectLayer.addData(xml);
|
||||||
|
|
||||||
|
if (options.zoom) map.fitBounds(map._objectLayer.getBounds());
|
||||||
|
if (options.callback) options.callback(map._objectLayer.getBounds());
|
||||||
|
|
||||||
|
map._objectLayer.addTo(map);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
var objectLoader;
|
|
||||||
|
|
||||||
function getUserIcon(url) {
|
function getUserIcon(url) {
|
||||||
return L.icon({
|
return L.icon({
|
||||||
iconUrl: url || <%= asset_path('marker-red.png').to_json %>,
|
iconUrl: url || <%= asset_path('marker-red.png').to_json %>,
|
||||||
|
@ -10,41 +8,3 @@ function getUserIcon(url) {
|
||||||
shadowSize: [41, 41]
|
shadowSize: [41, 41]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function addObjectToMap(object, map, options) {
|
|
||||||
if (objectLoader) objectLoader.abort();
|
|
||||||
if (map.objectLayer) map.removeLayer(map.objectLayer);
|
|
||||||
|
|
||||||
objectLoader = $.ajax({
|
|
||||||
url: OSM.apiUrl(object),
|
|
||||||
dataType: "xml",
|
|
||||||
success: function (xml) {
|
|
||||||
map.objectLayer = new L.OSM.DataLayer(null, {
|
|
||||||
styles: {
|
|
||||||
node: options.style,
|
|
||||||
way: options.style,
|
|
||||||
area: options.style
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
map.objectLayer.interestingNode = function (node, ways, relations) {
|
|
||||||
if (object.type === "node") {
|
|
||||||
return true;
|
|
||||||
} else if (object.type === "relation") {
|
|
||||||
for (var i = 0; i < relations.length; i++)
|
|
||||||
if (relations[i].members.indexOf(node) != -1)
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
map.objectLayer.addData(xml);
|
|
||||||
|
|
||||||
if (options.zoom) map.fitBounds(map.objectLayer.getBounds());
|
|
||||||
if (options.callback) options.callback(map.objectLayer.getBounds());
|
|
||||||
|
|
||||||
map.objectLayer.addTo(map);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue