dotnetexpert
dotnetexpert

Reputation: 145

Can not read property 'position' undefined, get Coordinates - CustomTile - Openseadragon

I am trying to get the coordinates with below code : If i am clicking on the canvas to grab the X and Y position : showing me console error : Uncaught TypeError: Cannot read property 'position' of undefined

screenshot : http://screencast.com/t/0LHAae5AicRz

viewer.addHandler('canvas-click', function (target, info) {
            var viewportPoint = viewer.viewport.pointFromPixel(info.position);
            var imagePoint = viewer.viewport.viewportToImageCoordinates(viewportPoint.x, viewportPoint.y);
            console.log(imagePoint.x, imagePoint.y);
        });

Upvotes: 0

Views: 1254

Answers (2)

dotnetexpert
dotnetexpert

Reputation: 145

This way, I can remove the canvas-click related - position of undefined error : Take a look at here for the answer : https://github.com/openseadragon/openseadragon/issues/318

For the //! OpenSeadragon 1.1.1, please updated the code as per below.

viewer.addHandler('canvas-click', function (event)
        {
            console.log(event);
            var viewportPoint = viewer.viewport.pointFromPixel(event.position);
            var imagePoint = viewer.viewport.viewportToImageCoordinates(viewportPoint.x, viewportPoint.y);
            console.log(imagePoint.x, imagePoint.y);
        });

Upvotes: 0

Rupert
Rupert

Reputation: 1639

The info parameter is probably not what you think it is.

Do console.log(info) to see what the variable is in the console.

Perhaps the variable you are looking for is another parameter.

Also log all the arguments that get passed to the function. Write this inside the function:

console.log(arguments)

This way you will be able to inspect the variables and find the data you need.

Upvotes: 0

Related Questions