Mercurial > hg > orthanc-wsi
changeset 397:6b8e1569ae3f
uniformization of the import of JavaScript libraries
| author | Sebastien Jodogne <s.jodogne@gmail.com> |
|---|---|
| date | Tue, 04 Nov 2025 18:03:57 +0100 |
| parents | 8c481071e36d |
| children | b0f4843da0fa |
| files | ViewerPlugin/CMakeLists.txt ViewerPlugin/Plugin.cpp ViewerPlugin/viewer.html |
| diffstat | 3 files changed, 38 insertions(+), 49 deletions(-) [+] |
line wrap: on
line diff
--- a/ViewerPlugin/CMakeLists.txt Tue Nov 04 17:30:14 2025 +0100 +++ b/ViewerPlugin/CMakeLists.txt Tue Nov 04 18:03:57 2025 +0100 @@ -37,11 +37,6 @@ SET(USE_SYSTEM_OPENJPEG ON CACHE BOOL "Use the system version of OpenJpeg") SET(USE_SYSTEM_ORTHANC_SDK ON CACHE BOOL "Use the system version of the Orthanc plugin SDK") -# Parameters related to OpenLayers -SET(USE_SYSTEM_OPENLAYERS OFF CACHE BOOL "Use the system version of OpenLayers") -SET(OPENLAYERS_CSS "" CACHE FILEPATH "Path to the system version of OpenLayers CSS") -SET(OPENLAYERS_JS "" CACHE FILEPATH "Path to the system version of OpenLayers JavaScript") - ##################################################################### ## Configure mandatory third-party components @@ -146,37 +141,13 @@ ##################################################################### -## Prepare OpenLayers +## Prepare JavaScript libraries ##################################################################### -if (STATIC_BUILD OR NOT USE_SYSTEM_OPENLAYERS) - DownloadPackage( - "b7de8bba890ccc3858920bd66dd79d2d" - "https://orthanc.uclouvain.be/downloads/third-party-downloads/WSI/openlayers-10.6.1-package.tar.gz" - "openlayers-10.6.1-package") - - set(OPENLAYERS_RESOURCES - OPENLAYERS_CSS ${CMAKE_CURRENT_BINARY_DIR}/openlayers-10.6.1-package/ol.css - OPENLAYERS_JS ${CMAKE_CURRENT_BINARY_DIR}/openlayers-10.6.1-package/dist/ol.js - ) - -else() - if (OPENLAYERS_CSS STREQUAL "") - message(FATAL_ERROR "The option OPENLAYERS_CSS is not set") - endif() - - if (OPENLAYERS_JS STREQUAL "") - message(FATAL_ERROR "The option OPENLAYERS_JS is not set") - endif() - - set(OPENLAYERS_RESOURCES - OPENLAYERS_CSS ${OPENLAYERS_CSS} - OPENLAYERS_JS ${OPENLAYERS_JS} - ) -endif() +include(${CMAKE_SOURCE_DIR}/../Resources/CMake/JavaScriptLibraries.cmake) EmbedResources( - ${OPENLAYERS_RESOURCES} + JAVASCRIPT_LIBS ${JAVASCRIPT_LIBS_DIR} ORTHANC_EXPLORER ${CMAKE_SOURCE_DIR}/OrthancExplorer.js VIEWER_HTML ${CMAKE_SOURCE_DIR}/viewer.html VIEWER_JS ${CMAKE_SOURCE_DIR}/viewer.js
--- a/ViewerPlugin/Plugin.cpp Tue Nov 04 17:30:14 2025 +0100 +++ b/ViewerPlugin/Plugin.cpp Tue Nov 04 18:03:57 2025 +0100 @@ -362,6 +362,35 @@ } +void ServeJavaScriptLibraries(OrthancPluginRestOutput* output, + const char* url, + const OrthancPluginHttpRequest* request) +{ + OrthancPluginContext* context = OrthancPlugins::GetGlobalContext(); + + if (request->method != OrthancPluginHttpMethod_Get) + { + OrthancPluginSendMethodNotAllowed(context, output, "GET"); + } + else + { + const std::string path = "/" + std::string(request->groups[0]); + const char* mime = Orthanc::EnumerationToString(Orthanc::SystemToolbox::AutodetectMimeType(path)); + + if (path == "/js/ol.js") + { + // Adding "charset" is mandatory with OpenLayers 10.4.0, check out "zoomOutLabel" in the source code + mime = "application/javascript; charset=utf-8"; + } + + std::string s; + Orthanc::EmbeddedResources::GetDirectoryResource(s, Orthanc::EmbeddedResources::JAVASCRIPT_LIBS, path.c_str()); + + const char* resource = s.size() ? s.c_str() : NULL; + OrthancPluginAnswerBuffer(context, output, resource, s.size(), mime); + } +} + void ServeFile(OrthancPluginRestOutput* output, const char* url, @@ -382,18 +411,6 @@ resource = Orthanc::EmbeddedResources::VIEWER_JS; mime = "application/javascript"; } - else if (f == "dist/ol.js") - { - resource = Orthanc::EmbeddedResources::OPENLAYERS_JS; - - // Adding "charset" is mandatory with OpenLayers 10.4.0, check out "zoomOutLabel" in the source code - mime = "application/javascript; charset=utf-8"; - } - else if (f == "ol.css") - { - resource = Orthanc::EmbeddedResources::OPENLAYERS_CSS; - mime = "text/css"; - } else if (f == "mirador.html") { resource = Orthanc::EmbeddedResources::MIRADOR_HTML; @@ -520,8 +537,7 @@ OrthancPluginRegisterOnChangeCallback(OrthancPlugins::GetGlobalContext(), OnChangeCallback); - OrthancPlugins::RegisterRestCallback<ServeFile>("/wsi/app/(ol.css)", true); - OrthancPlugins::RegisterRestCallback<ServeFile>("/wsi/app/(dist/ol.js)", true); + OrthancPlugins::RegisterRestCallback<ServeJavaScriptLibraries>("/wsi/libs/(.*)", true); OrthancPlugins::RegisterRestCallback<ServeFile>("/wsi/app/(viewer.html)", true); OrthancPlugins::RegisterRestCallback<ServeFile>("/wsi/app/(viewer.js)", true); OrthancPlugins::RegisterRestCallback<ServePyramid>("/wsi/pyramids/([0-9a-f-]+)", true);
--- a/ViewerPlugin/viewer.html Tue Nov 04 17:30:14 2025 +0100 +++ b/ViewerPlugin/viewer.html Tue Nov 04 18:03:57 2025 +0100 @@ -1,10 +1,12 @@ <!DOCTYPE html> -<html> +<html lang="en"> <head> + <meta charset="UTF-8"> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Orthanc for Whole-Slide Imaging</title> - <link rel="stylesheet" href="ol.css" type="text/css"> + <link rel="stylesheet" href="../libs/css/ol.css" type="text/css"> <style> html, @@ -28,7 +30,7 @@ <!-- This is the version of jQuery that is used by Orthanc Explorer --> <script src="../../app/libs/jquery.min.js"></script> - <script src="dist/ol.js"></script> + <script src="../libs/js/ol.js"></script> <script src="viewer.js"></script> </body> </html>
