Skip to content

Commit

Permalink
Add a Geo URI link to the share panel
Browse files Browse the repository at this point in the history
Fixes #799
  • Loading branch information
erictheise authored and tomhughes committed Jun 25, 2015
1 parent 4676179 commit 6403cb9
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
18 changes: 18 additions & 0 deletions app/assets/javascripts/leaflet.map.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,24 @@ L.OSM.Map = L.Map.extend({
return str;
},

getGeoUri: function(marker) {
var precision = OSM.zoomPrecision(this.getZoom()),
latLng,
params = {};

if (marker && this.hasLayer(marker)) {
latLng = marker.getLatLng().wrap();
} else {
latLng = this.getCenter();
}

params.lat = latLng.lat.toFixed(precision);
params.lon = latLng.lng.toFixed(precision);
params.zoom = this.getZoom();

return 'geo:' + params.lat + ',' + params.lon + '?z=' + params.zoom;
},

addObject: function(object, callback) {
var objectStyle = {
color: "#FF6200",
Expand Down
21 changes: 21 additions & 0 deletions app/assets/javascripts/leaflet.share.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,21 @@ L.OSM.share = function (options) {
.text(I18n.t('javascripts.share.paste_html'))
.appendTo($linkSection));

// Geo URI

var $geoUriSection = $('<div>')
.attr('class', 'section share-geo-uri')
.appendTo($ui);

$('<h4>')
.text(I18n.t('javascripts.share.geo_uri'))
.appendTo($geoUriSection);

$('<div>')
.appendTo($geoUriSection)
.append($('<a>')
.attr('id', 'geo_uri'));

// Image

var $imageSection = $('<div>')
Expand Down Expand Up @@ -320,6 +335,12 @@ L.OSM.share = function (options) {
'<small><a href="' + escapeHTML(map.getUrl(marker)) + '">' +
escapeHTML(I18n.t('javascripts.share.view_larger_map')) + '</a></small>');

// Geo URI

$('#geo_uri')
.attr('href', map.getGeoUri(marker))
.html(map.getGeoUri(marker));

// Image

if (locationFilter.isEnabled()) {
Expand Down
2 changes: 1 addition & 1 deletion app/assets/stylesheets/common.scss
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,7 @@ nav.secondary {
text-decoration: none;
background-color: $lightblue;
padding: 5px 10px;
border-right: 1px solid #fff;
}

a:first-child {
Expand All @@ -729,7 +730,6 @@ nav.secondary {
}

a:last-child {
border-left: 1px solid #fff;
border-radius: 0 4px 4px 0;
}

Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2163,6 +2163,7 @@ en:
link: "Link or HTML"
long_link: "Link"
short_link: "Short Link"
geo_uri: "Geo URI"
embed: "HTML"
custom_dimensions: "Set custom dimensions"
format: "Format:"
Expand Down

0 comments on commit 6403cb9

Please sign in to comment.