So I've bascially got an isMobile var set up to handle various tools that I want to use on the desktop or on mobile and vice versa:
var isMobile = {
Android: function() {
return navigator.userAgent.match(/Android/i);
},
BlackBerry: function() {
return navigator.userAgent.match(/BlackBerry/i);
},
iOS: function() {
return navigator.userAgent.match(/iPhone|iPad|iPod/i);
},
Opera: function() {
return navigator.userAgent.match(/Opera Mini/i);
},
Windows: function() {
return navigator.userAgent.match(/IEMobile/i);
},
any: function() {
return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
}
};
So what I'm trying to do is get the snappingManager to be always on if moble, else set the CTRL key:
| var snapManager = mapMain.enableSnapping({ |
if(!isMobile){[
console.log("im a desktop");
alwaysSnap: true,
tolerance: 5,
| snapPointSymbol: snapSym |
} else {
snapKey: has("mac") ? keys.META : keys.CTRL,
tolerance: 5,
snapPointSymbol: snapSym
}
});
var layerInfos = [{
layer: lyrParcels
}];
snapManager.setLayerInfos(layerInfos);
Anyway, the syntax isn't quite right setting the snappingManagers' constructor paramters in an if else block. Any help is appreciated.
Forgive the non-js highlighting on this part please - the editor syntax highlighter stopped beahving
Thanks
David
David,
Since the isMobile is an object and not a boolean value are you sure that it is not always something besides null and thus only entering the first part of the if?
Thanks Robert let me think about that . . .
Ok let's see if I get this right. Since ifMobile is an object, it should never be null unless I am not accounting for a particular OS as part of its properties, I think. That said, I should then be able to flip the script around by invoking(?) snapManager inside of ifMobile thusly:
if (isMobile.any()){
console.log("Mobile");
snapManager = mapMain.enableSnapping({
alwaysSnap: true,
tolerance: 5,
snapPointSymbol: snapSym
});
} else {
console.log("Not Mobile");
snapManager = mapMain.enableSnapping({
tolerance: 5,
snapPointSymbol: snapSym,
snapKey: has("mac") ? keys.META : keys.CTRL
});
}And this seems to work pretty well, but I'll know defineitevely once I push this up so I can test on a mobile platform.
Thanks also to @michael Stranovsky
Thanks for your reply Robert Scheitlin, GISP
David