Skip to content

Instantly share code, notes, and snippets.

@odoe
Created November 10, 2015 14:15
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save odoe/bfb5964f0087a733b704 to your computer and use it in GitHub Desktop.
var templateString = '<div class="tool-container">'+
'<div class="w3w-results" data-dojo-attach-point="resultsNode"></div>'+
'<div class="w3w" data-dojo-attach-event="click:toggle"></div>'+
'</div>';
var What3Words = declare([_WidgetBase, _TemplatedMixin], {
templateString: templateString,
postCreate: function() {
esriConfig.request.corsEnabledServers.push("api.what3words.com");
var _view = this.get('view');
domUtils.hide(this.resultsNode);
this.hidden = true;
var node = this.domNode;
var target = document.querySelector(".esriTop.esriRight");
target.appendChild(node);
var resultsNode = this.resultsNode;
this.handler = on.pausable(_view.container, "mousemove", debounce(function (e) {
var mp = new Point();
_view.toMap(e.offsetX, e.offsetY, mp);
var ll = wmu.webMercatorToGeographic(mp);
esriRequest({
url: "https://api.what3words.com/position?key=XXXXX&position=" + ll.y + "," + ll.x
}).then(function(result) {
resultsNode.innerText = result.words.join(",");
});
}, 50));
this.handler.pause();
this.own(this.handler);
},
toggle: function() {
if (!this.hidden) {
domUtils.show(this.resultsNode);
this.handler.resume();
} else {
domUtils.hide(this.resultsNode);
this.handler.pause();
}
this.hidden = !this.hidden;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment