This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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