Skip to content

Commit

Permalink
Support android intent uri for JOSM style remote control
Browse files Browse the repository at this point in the history
when on an android device.
  • Loading branch information
Simon Poole committed Mar 7, 2017
1 parent 33669da commit 7821ec9
Showing 1 changed file with 32 additions and 6 deletions.
38 changes: 32 additions & 6 deletions app/assets/javascripts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,37 @@ $(document).ready(function () {
L.marker(center, {icon: OSM.getUserIcon()}).addTo(map);
});

var isMobile = {
Windows: function() {
return /IEMobile/i.test(navigator.userAgent);
},
Android: function() {
return /Android/i.test(navigator.userAgent);
},
BlackBerry: function() {
return /BlackBerry/i.test(navigator.userAgent);
},
iOS: function() {
return /iPhone|iPad|iPod/i.test(navigator.userAgent);
},
any: function() {
return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Windows());
}
};

function url() {
if (isMobile.Android()) {
return "intent:/load_and_zoom?";
} else {
return document.location.protocol === "https:" ?
"https://127.0.0.1:8112/load_and_zoom?" :
"http://127.0.0.1:8111/load_and_zoom?";
}
}

function remoteEditHandler(bbox, object) {
var loaded = false,
url = document.location.protocol === "https:" ?
"https://127.0.0.1:8112/load_and_zoom?" :
"http://127.0.0.1:8111/load_and_zoom?",
android = isMobile.Android(),
query = {
left: bbox.getWest() - 0.0001,
top: bbox.getNorth() + 0.0001,
Expand All @@ -255,17 +281,17 @@ $(document).ready(function () {
var iframe = $('<iframe>')
.hide()
.appendTo('body')
.attr("src", url + querystring.stringify(query))
.attr("src", url() + querystring.stringify(query) + (android ? '#Intent;scheme=josm;end;':''))
.on('load', function() {
$(this).remove();
loaded = true;
});

setTimeout(function () {
if (!loaded) {
if (!android && !loaded) {
alert(I18n.t('site.index.remote_failed'));
iframe.remove();
}
iframe.remove();
}, 1000);

return false;
Expand Down

0 comments on commit 7821ec9

Please sign in to comment.