Reputation: 1466
I have no idea how to do this. I am using swt browser to run openlayers , I had some basic function. So I want to capture the coordinates where I click on a map.
I try ta add a listener to the browser widget, so it calls a function on javascript that returns the coordinates of the mouse, but for what I can tell the click listener on the browser gets executed first, then on javascript the clik event gets executed, so on the first try it returns undefined and then it returns the previews clicks, not the current one.
So part of the problem is that in order to get the coordinates i am using ol3 function to get the position
I am using ol3 functions to set the mouse click
map.on('singleclick', function (evt) {
position = evt.coordinate;
....
})
and I have a function to return position but it takes a while to position to change. Is there a way to create something like a callback that when a function in javascript is done it will call a function on java so it can update my window?
Upvotes: 0
Views: 409
Reputation: 111142
You can define a function in your code that can be called from JavaScript by using a class derived from BrowserFunction
:
class MyFunction extends BrowserFunction {
MyFunction(Browser browser, String name) {
super (browser, name);
}
@Override
public Object function(Object[] arguments) {
// Your code
}
}
name
is the JavaScript name for the function.
More details here
Upvotes: 1