Skip to content

Commit

Permalink
Remove lib ogc-parser
Browse files Browse the repository at this point in the history
While updating libs, I had issues with ogc-parser as it is using very outdated dependencies.
After checking the GitHub repo, I saw it was kind of staled, so I replaced it with OpenLayers function. I had to add some browser API equivalent to NodeJS in order to achieve this (see first lines of the file) as this is then used under the hood by OpenLayers to parse XMLs
  • Loading branch information
pakb committed Nov 14, 2023
1 parent eddd20a commit eced2fe
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 37 deletions.
30 changes: 0 additions & 30 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@
"jsdom": "^22.1.0",
"mime-types": "^2.1.35",
"mocha-junit-reporter": "^2.2.1",
"ogc-parser": "^1.5.0",
"prettier": "^3.0.3",
"prettier-plugin-jsdoc": "^1.1.1",
"rimraf": "^5.0.1",
Expand Down
21 changes: 15 additions & 6 deletions scripts/check-external-layers-providers.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,22 @@ import writeYamlFile from 'write-yaml-file'
import axiosRetry from 'axios-retry'
import yargs from 'yargs'
import { hideBin } from 'yargs/helpers'
import ogcParser from 'ogc-parser'
import { exit } from 'process'

import {
transformUrl,
isWmsGetCap,
isWmtsGetCap,
isKml,
isGpx,
} from '@/modules/infobox/utils/external-provider'
import { WMSCapabilities } from "ol/format";
import WMTSCapabilities from "ol/format/WMTSCapabilities";
import { JSDOM } from 'jsdom'

// faking browser support, so that OpenLayers has what it requires to parse XMLs
const dom = new JSDOM()
global.DOMParser = dom.window.DOMParser
global.Node = dom.window.Node

const options = yargs(hideBin(process.argv))
.usage('Usage: $0 [options]')
Expand Down Expand Up @@ -130,20 +136,23 @@ function checkProviderResponse(provider, url, response, result) {
}
}

const wmsCapParser = new WMSCapabilities()
const wmtsCapParser = new WMTSCapabilities()

function checkProviderResponseContent(provider, url, response, result) {
const content = response.data
let isValid = true

if (isWmsGetCap(content)) {
const capabilities = ogcParser.wms(content)
if (!capabilities || !capabilities.layer) {
const capabilities = wmsCapParser.read(content)
if (!capabilities?.Capability?.Layer?.Layer) {
isValid = false
console.error(`Invalid provider ${provider}, WMS get Cap parsing failed`)
result.invalid_wms.push({ provider: provider, url: url, content: content.slice(0, 50) })
}
} else if (isWmtsGetCap(content)) {
const capabilities = ogcParser.wmts(content)
if (!capabilities || !capabilities.layer) {
const capabilities = wmtsCapParser.read(content)
if (!capabilities?.Contents?.Layer) {
isValid = false
console.error(`Invalid provider ${provider}, WMTS get Cap parsing failed`)
result.invalid_wmts.push({
Expand Down

0 comments on commit eced2fe

Please sign in to comment.