# HG changeset patch # User Sebastien Jodogne # Date 1762275837 -3600 # Node ID 6b8e1569ae3f074c713bf7fef778ee7e56e9b1b5 # Parent 8c481071e36d1b54cd8e3f35e3fcaa63d0f97b84 uniformization of the import of JavaScript libraries diff -r 8c481071e36d -r 6b8e1569ae3f ViewerPlugin/CMakeLists.txt --- 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 diff -r 8c481071e36d -r 6b8e1569ae3f ViewerPlugin/Plugin.cpp --- 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("/wsi/app/(ol.css)", true); - OrthancPlugins::RegisterRestCallback("/wsi/app/(dist/ol.js)", true); + OrthancPlugins::RegisterRestCallback("/wsi/libs/(.*)", true); OrthancPlugins::RegisterRestCallback("/wsi/app/(viewer.html)", true); OrthancPlugins::RegisterRestCallback("/wsi/app/(viewer.js)", true); OrthancPlugins::RegisterRestCallback("/wsi/pyramids/([0-9a-f-]+)", true); diff -r 8c481071e36d -r 6b8e1569ae3f ViewerPlugin/viewer.html --- 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 @@ - + + + Orthanc for Whole-Slide Imaging - +