Last active
August 29, 2015 14:20
-
-
Save Kvit/61561d4c2c2bf4d30370 to your computer and use it in GitHub Desktop.
JASON-RPC Example of Simagis Live Image Access API with compression
This file contains hidden or 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
| // Example of Json-RPC API for Simagis Live Server, learn more about Json-RPC at http://json-rpc.org/ | |
| // Json-RPC Library for JavaScript http://github.com/gimmi/jsonrpcjs/ | |
| // | |
| // 1. Create Json-RPC Object | |
| var rpc = new jsonrpc.JsonRpc('http://host.simagis.com/live-json-rpc/api'); | |
| var workspace = 'vk'; | |
| var projectId = '053e8d4d-ebfc-488a-bc2c-c826e41fe43d'; | |
| projectId = prompt('Enter Project ID', projectId ); | |
| rpc.call('openImage', workspace, projectId, { | |
| success: function (result) { | |
| showResult(result); | |
| }, | |
| failure: function (reason) { | |
| alert('Method call failed because of ' + reason); | |
| }, | |
| scope: window | |
| }); | |
| function showResult(result) { | |
| var outputElement = document.getElementById('output'); | |
| outputElement.innerHTML = 'Result of rpc.call method: <pre>' + JSON.stringify(result, null, ' ') | |
| + '</pre><hr>'; | |
| var centerX = Math.round(result.image.width / 2); | |
| var centerY = Math.round(result.image.height / 2); | |
| var fromX = 0; | |
| var fromY = 0; | |
| var toX = result.image.width; | |
| var toY = result.image.height; | |
| var targetWidth = prompt("Enter output Image width in pixels", "1000"); | |
| var compression = Math.round(result.image.width / targetWidth / 2) * 2; | |
| var imageURL = result.connection.url + '?image=' + result.image.id + '&' + | |
| 'region=' + fromX + ',' + fromY + ',' + toX + ',' + toY + '&compression=' + compression ; | |
| outputElement.innerHTML += 'Image Access URL:' | |
| + '<br><a href="' + imageURL + '" target="_blank">' + imageURL + '</a>' | |
| + '<br>Change region coordinates in Image Access URL to extract different region.' | |
| + ' Height, width and region coordinate values are in pixels.' | |
| + '<br><br><a href="/live/layers/view.jsp?name=Users/' + workspace + '/' + projectId | |
| + '" target="_blank">Open Live Image</a>'; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment