Skip to content

Commit

Permalink
#399 Crashes if Layers are valid JSON but not valid GeoJSON (#400)
Browse files Browse the repository at this point in the history
* #399 Add geojson validater to map

* #399 allow overloaded coordinates in geojson for extended geojson
  • Loading branch information
tariqksoliman authored Jul 24, 2023
1 parent 48bcefb commit fec9c89
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 4 deletions.
14 changes: 14 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
"file-saver": "^2.0.2",
"flat": "^5.0.2",
"fs-extra": "^8.1.0",
"geojson-validation": "^1.0.2",
"hammerjs": "^2.0.8",
"helmet": "^4.1.1",
"html-webpack-plugin": "4.0.0-beta.11",
Expand Down
2 changes: 1 addition & 1 deletion src/essence/Basics/Layers_/LayerCapturer.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const captureVector = (layerObj, options, cb) => {
},
function (data) {
console.warn(
'ERROR! ' +
'ERROR: ' +
data.status +
' in ' +
layerUrl +
Expand Down
33 changes: 30 additions & 3 deletions src/essence/Basics/Map_/Map_.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import { Kinds } from '../../../pre/tools'
import DataShaders from '../../Ancillary/DataShaders'
import calls from '../../../pre/calls'
import TimeControl from '../../Ancillary/TimeControl'

import gjv from 'geojson-validation'

let L = window.L

let essenceFina = function () {}
Expand Down Expand Up @@ -796,7 +799,27 @@ async function makeLayer(layerObj, evenIfOff, forceGeoJSON) {
)

function add(data) {
if (data == null || data === 'off') {
let invalidGeoJSONTrace = gjv.valid(data, true)
const allowableErrors = [`position must only contain numbers`]
invalidGeoJSONTrace = invalidGeoJSONTrace.filter((t) => {
if (typeof t !== 'string') return false
for (let i = 0; i < allowableErrors.length; i++) {
if (t.toLowerCase().indexOf(allowableErrors[i]) != -1)
return false
}
return true
})
if (
data == null ||
data === 'off' ||
invalidGeoJSONTrace.length > 0
) {
if (data != null && data != 'off') {
data = null
console.warn(
`ERROR: ${layerObj.display_name} has invalid GeoJSON!`
)
}
L_._layersLoaded[
L_._layersOrdered.indexOf(layerObj.name)
] = true
Expand Down Expand Up @@ -1134,8 +1157,12 @@ function allLayersLoaded() {

// Turn on legend if displayOnStart is true
if ('LegendTool' in ToolController_.toolModules) {
if (ToolController_.toolModules['LegendTool'].displayOnStart == true) {
ToolController_.toolModules['LegendTool'].make('toolContentSeparated_Legend')
if (
ToolController_.toolModules['LegendTool'].displayOnStart == true
) {
ToolController_.toolModules['LegendTool'].make(
'toolContentSeparated_Legend'
)
let _event = new CustomEvent('toggleSeparatedTool', {
detail: {
toggledToolName: 'LegendTool',
Expand Down

0 comments on commit fec9c89

Please sign in to comment.