Switch to curly style for if/else statements

This commit is contained in:
David Larlet 2023-09-25 11:42:03 -04:00
parent 27e8fd0cac
commit f2a25d3c91
No known key found for this signature in database
GPG key ID: 3E2953A359E7E7BD
17 changed files with 1682 additions and 369 deletions

View file

@ -1,6 +1,8 @@
trailingComma: "es5" trailingComma: 'es5'
tabWidth: 2 tabWidth: 2
semi: false semi: false
singleQuote: true singleQuote: true
printWidth: 88 printWidth: 88
quoteProps: "consistent" quoteProps: 'consistent'
plugins:
- prettier-plugin-curly

724
package-lock.json generated
View file

@ -41,10 +41,368 @@
"mocha": "^10.2.0", "mocha": "^10.2.0",
"optimist": "~0.4.0", "optimist": "~0.4.0",
"prettier": "^2.8.8", "prettier": "^2.8.8",
"prettier-plugin-curly": "^0.1.3",
"sinon": "^15.1.0", "sinon": "^15.1.0",
"uglify-js": "~3.17.4" "uglify-js": "~3.17.4"
} }
}, },
"node_modules/@babel/code-frame": {
"version": "7.22.13",
"resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.22.13.tgz",
"integrity": "sha512-XktuhWlJ5g+3TJXc5upd9Ks1HutSArik6jf2eAjYFyIOf4ej3RN+184cZbzDvbPnuTJIUhPKKJE3cIsYTiAT3w==",
"dev": true,
"dependencies": {
"@babel/highlight": "^7.22.13",
"chalk": "^2.4.2"
},
"engines": {
"node": ">=6.9.0"
}
},
"node_modules/@babel/code-frame/node_modules/ansi-styles": {
"version": "3.2.1",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz",
"integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==",
"dev": true,
"dependencies": {
"color-convert": "^1.9.0"
},
"engines": {
"node": ">=4"
}
},
"node_modules/@babel/code-frame/node_modules/chalk": {
"version": "2.4.2",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz",
"integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==",
"dev": true,
"dependencies": {
"ansi-styles": "^3.2.1",
"escape-string-regexp": "^1.0.5",
"supports-color": "^5.3.0"
},
"engines": {
"node": ">=4"
}
},
"node_modules/@babel/code-frame/node_modules/color-convert": {
"version": "1.9.3",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz",
"integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==",
"dev": true,
"dependencies": {
"color-name": "1.1.3"
}
},
"node_modules/@babel/code-frame/node_modules/color-name": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz",
"integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==",
"dev": true
},
"node_modules/@babel/code-frame/node_modules/escape-string-regexp": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz",
"integrity": "sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg==",
"dev": true,
"engines": {
"node": ">=0.8.0"
}
},
"node_modules/@babel/code-frame/node_modules/has-flag": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz",
"integrity": "sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==",
"dev": true,
"engines": {
"node": ">=4"
}
},
"node_modules/@babel/code-frame/node_modules/supports-color": {
"version": "5.5.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz",
"integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==",
"dev": true,
"dependencies": {
"has-flag": "^3.0.0"
},
"engines": {
"node": ">=4"
}
},
"node_modules/@babel/generator": {
"version": "7.23.0",
"resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.23.0.tgz",
"integrity": "sha512-lN85QRR+5IbYrMWM6Y4pE/noaQtg4pNiqeNGX60eqOfo6gtEj6uw/JagelB8vVztSd7R6M5n1+PQkDbHbBRU4g==",
"dev": true,
"dependencies": {
"@babel/types": "^7.23.0",
"@jridgewell/gen-mapping": "^0.3.2",
"@jridgewell/trace-mapping": "^0.3.17",
"jsesc": "^2.5.1"
},
"engines": {
"node": ">=6.9.0"
}
},
"node_modules/@babel/helper-environment-visitor": {
"version": "7.22.20",
"resolved": "https://registry.npmjs.org/@babel/helper-environment-visitor/-/helper-environment-visitor-7.22.20.tgz",
"integrity": "sha512-zfedSIzFhat/gFhWfHtgWvlec0nqB9YEIVrpuwjruLlXfUSnA8cJB0miHKwqDnQ7d32aKo2xt88/xZptwxbfhA==",
"dev": true,
"engines": {
"node": ">=6.9.0"
}
},
"node_modules/@babel/helper-function-name": {
"version": "7.23.0",
"resolved": "https://registry.npmjs.org/@babel/helper-function-name/-/helper-function-name-7.23.0.tgz",
"integrity": "sha512-OErEqsrxjZTJciZ4Oo+eoZqeW9UIiOcuYKRJA4ZAgV9myA+pOXhhmpfNCKjEH/auVfEYVFJ6y1Tc4r0eIApqiw==",
"dev": true,
"dependencies": {
"@babel/template": "^7.22.15",
"@babel/types": "^7.23.0"
},
"engines": {
"node": ">=6.9.0"
}
},
"node_modules/@babel/helper-hoist-variables": {
"version": "7.22.5",
"resolved": "https://registry.npmjs.org/@babel/helper-hoist-variables/-/helper-hoist-variables-7.22.5.tgz",
"integrity": "sha512-wGjk9QZVzvknA6yKIUURb8zY3grXCcOZt+/7Wcy8O2uctxhplmUPkOdlgoNhmdVee2c92JXbf1xpMtVNbfoxRw==",
"dev": true,
"dependencies": {
"@babel/types": "^7.22.5"
},
"engines": {
"node": ">=6.9.0"
}
},
"node_modules/@babel/helper-split-export-declaration": {
"version": "7.22.6",
"resolved": "https://registry.npmjs.org/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.22.6.tgz",
"integrity": "sha512-AsUnxuLhRYsisFiaJwvp1QF+I3KjD5FOxut14q/GzovUe6orHLesW2C7d754kRm53h5gqrz6sFl6sxc4BVtE/g==",
"dev": true,
"dependencies": {
"@babel/types": "^7.22.5"
},
"engines": {
"node": ">=6.9.0"
}
},
"node_modules/@babel/helper-string-parser": {
"version": "7.22.5",
"resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.22.5.tgz",
"integrity": "sha512-mM4COjgZox8U+JcXQwPijIZLElkgEpO5rsERVDJTc2qfCDfERyob6k5WegS14SX18IIjv+XD+GrqNumY5JRCDw==",
"dev": true,
"engines": {
"node": ">=6.9.0"
}
},
"node_modules/@babel/helper-validator-identifier": {
"version": "7.22.20",
"resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.22.20.tgz",
"integrity": "sha512-Y4OZ+ytlatR8AI+8KZfKuL5urKp7qey08ha31L8b3BwewJAoJamTzyvxPR/5D+KkdJCGPq/+8TukHBlY10FX9A==",
"dev": true,
"engines": {
"node": ">=6.9.0"
}
},
"node_modules/@babel/highlight": {
"version": "7.22.20",
"resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.22.20.tgz",
"integrity": "sha512-dkdMCN3py0+ksCgYmGG8jKeGA/8Tk+gJwSYYlFGxG5lmhfKNoAy004YpLxpS1W2J8m/EK2Ew+yOs9pVRwO89mg==",
"dev": true,
"dependencies": {
"@babel/helper-validator-identifier": "^7.22.20",
"chalk": "^2.4.2",
"js-tokens": "^4.0.0"
},
"engines": {
"node": ">=6.9.0"
}
},
"node_modules/@babel/highlight/node_modules/ansi-styles": {
"version": "3.2.1",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz",
"integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==",
"dev": true,
"dependencies": {
"color-convert": "^1.9.0"
},
"engines": {
"node": ">=4"
}
},
"node_modules/@babel/highlight/node_modules/chalk": {
"version": "2.4.2",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz",
"integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==",
"dev": true,
"dependencies": {
"ansi-styles": "^3.2.1",
"escape-string-regexp": "^1.0.5",
"supports-color": "^5.3.0"
},
"engines": {
"node": ">=4"
}
},
"node_modules/@babel/highlight/node_modules/color-convert": {
"version": "1.9.3",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz",
"integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==",
"dev": true,
"dependencies": {
"color-name": "1.1.3"
}
},
"node_modules/@babel/highlight/node_modules/color-name": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz",
"integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==",
"dev": true
},
"node_modules/@babel/highlight/node_modules/escape-string-regexp": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz",
"integrity": "sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg==",
"dev": true,
"engines": {
"node": ">=0.8.0"
}
},
"node_modules/@babel/highlight/node_modules/has-flag": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz",
"integrity": "sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==",
"dev": true,
"engines": {
"node": ">=4"
}
},
"node_modules/@babel/highlight/node_modules/supports-color": {
"version": "5.5.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz",
"integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==",
"dev": true,
"dependencies": {
"has-flag": "^3.0.0"
},
"engines": {
"node": ">=4"
}
},
"node_modules/@babel/parser": {
"version": "7.23.0",
"resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.23.0.tgz",
"integrity": "sha512-vvPKKdMemU85V9WE/l5wZEmImpCtLqbnTvqDS2U1fJ96KrxoW7KrXhNsNCblQlg8Ck4b85yxdTyelsMUgFUXiw==",
"dev": true,
"bin": {
"parser": "bin/babel-parser.js"
},
"engines": {
"node": ">=6.0.0"
}
},
"node_modules/@babel/template": {
"version": "7.22.15",
"resolved": "https://registry.npmjs.org/@babel/template/-/template-7.22.15.tgz",
"integrity": "sha512-QPErUVm4uyJa60rkI73qneDacvdvzxshT3kksGqlGWYdOTIUOwJ7RDUL8sGqslY1uXWSL6xMFKEXDS3ox2uF0w==",
"dev": true,
"dependencies": {
"@babel/code-frame": "^7.22.13",
"@babel/parser": "^7.22.15",
"@babel/types": "^7.22.15"
},
"engines": {
"node": ">=6.9.0"
}
},
"node_modules/@babel/traverse": {
"version": "7.23.0",
"resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.23.0.tgz",
"integrity": "sha512-t/QaEvyIoIkwzpiZ7aoSKK8kObQYeF7T2v+dazAYCb8SXtp58zEVkWW7zAnju8FNKNdr4ScAOEDmMItbyOmEYw==",
"dev": true,
"dependencies": {
"@babel/code-frame": "^7.22.13",
"@babel/generator": "^7.23.0",
"@babel/helper-environment-visitor": "^7.22.20",
"@babel/helper-function-name": "^7.23.0",
"@babel/helper-hoist-variables": "^7.22.5",
"@babel/helper-split-export-declaration": "^7.22.6",
"@babel/parser": "^7.23.0",
"@babel/types": "^7.23.0",
"debug": "^4.1.0",
"globals": "^11.1.0"
},
"engines": {
"node": ">=6.9.0"
}
},
"node_modules/@babel/types": {
"version": "7.23.0",
"resolved": "https://registry.npmjs.org/@babel/types/-/types-7.23.0.tgz",
"integrity": "sha512-0oIyUfKoI3mSqMvsxBdclDwxXKXAUA8v/apZbc+iSyARYou1o8ZGDxbUYyLFoW2arqS2jDGqJuZvv1d/io1axg==",
"dev": true,
"dependencies": {
"@babel/helper-string-parser": "^7.22.5",
"@babel/helper-validator-identifier": "^7.22.20",
"to-fast-properties": "^2.0.0"
},
"engines": {
"node": ">=6.9.0"
}
},
"node_modules/@jridgewell/gen-mapping": {
"version": "0.3.3",
"resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.3.tgz",
"integrity": "sha512-HLhSWOLRi875zjjMG/r+Nv0oCW8umGb0BgEhyX3dDX3egwZtB8PqLnjz3yedt8R5StBrzcg4aBpnh8UA9D1BoQ==",
"dev": true,
"dependencies": {
"@jridgewell/set-array": "^1.0.1",
"@jridgewell/sourcemap-codec": "^1.4.10",
"@jridgewell/trace-mapping": "^0.3.9"
},
"engines": {
"node": ">=6.0.0"
}
},
"node_modules/@jridgewell/resolve-uri": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.1.tgz",
"integrity": "sha512-dSYZh7HhCDtCKm4QakX0xFpsRDqjjtZf/kjI/v3T3Nwt5r8/qz/M19F9ySyOqU94SXBmeG9ttTul+YnR4LOxFA==",
"dev": true,
"engines": {
"node": ">=6.0.0"
}
},
"node_modules/@jridgewell/set-array": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/@jridgewell/set-array/-/set-array-1.1.2.tgz",
"integrity": "sha512-xnkseuNADM0gt2bs+BvhO0p78Mk762YnZdsuzFV018NoG1Sj1SCQvpSqa7XUaTam5vAGasABV9qXASMKnFMwMw==",
"dev": true,
"engines": {
"node": ">=6.0.0"
}
},
"node_modules/@jridgewell/sourcemap-codec": {
"version": "1.4.15",
"resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.15.tgz",
"integrity": "sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg==",
"dev": true
},
"node_modules/@jridgewell/trace-mapping": {
"version": "0.3.19",
"resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.19.tgz",
"integrity": "sha512-kf37QtfW+Hwx/buWGMPcR60iF9ziHa6r/CZJIHbmcm4+0qrXiVdxegAH0F6yddEVQ7zdkjcGCgCzUu+BcbhQxw==",
"dev": true,
"dependencies": {
"@jridgewell/resolve-uri": "^3.1.0",
"@jridgewell/sourcemap-codec": "^1.4.14"
}
},
"node_modules/@mapbox/sexagesimal": { "node_modules/@mapbox/sexagesimal": {
"version": "1.1.0", "version": "1.1.0",
"resolved": "https://registry.npmjs.org/@mapbox/sexagesimal/-/sexagesimal-1.1.0.tgz", "resolved": "https://registry.npmjs.org/@mapbox/sexagesimal/-/sexagesimal-1.1.0.tgz",
@ -1021,6 +1379,15 @@
"node": ">= 6" "node": ">= 6"
} }
}, },
"node_modules/globals": {
"version": "11.12.0",
"resolved": "https://registry.npmjs.org/globals/-/globals-11.12.0.tgz",
"integrity": "sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA==",
"dev": true,
"engines": {
"node": ">=4"
}
},
"node_modules/gopd": { "node_modules/gopd": {
"version": "1.0.1", "version": "1.0.1",
"resolved": "https://registry.npmjs.org/gopd/-/gopd-1.0.1.tgz", "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.0.1.tgz",
@ -1310,6 +1677,12 @@
"resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
"integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=" "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE="
}, },
"node_modules/js-tokens": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz",
"integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==",
"dev": true
},
"node_modules/js-yaml": { "node_modules/js-yaml": {
"version": "4.1.0", "version": "4.1.0",
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz",
@ -1322,6 +1695,18 @@
"js-yaml": "bin/js-yaml.js" "js-yaml": "bin/js-yaml.js"
} }
}, },
"node_modules/jsesc": {
"version": "2.5.2",
"resolved": "https://registry.npmjs.org/jsesc/-/jsesc-2.5.2.tgz",
"integrity": "sha512-OYu7XEzjkCQ3C5Ps3QIZsQfNpqoJyZZA99wd9aWd05NCtC5pWOkShK2mkL6HXQR6/Cy2lbNdPlZBpuQHXE63gA==",
"dev": true,
"bin": {
"jsesc": "bin/jsesc"
},
"engines": {
"node": ">=4"
}
},
"node_modules/jsonparse": { "node_modules/jsonparse": {
"version": "0.0.5", "version": "0.0.5",
"resolved": "https://registry.npmjs.org/jsonparse/-/jsonparse-0.0.5.tgz", "resolved": "https://registry.npmjs.org/jsonparse/-/jsonparse-0.0.5.tgz",
@ -1995,6 +2380,22 @@
"url": "https://github.com/prettier/prettier?sponsor=1" "url": "https://github.com/prettier/prettier?sponsor=1"
} }
}, },
"node_modules/prettier-plugin-curly": {
"version": "0.1.3",
"resolved": "https://registry.npmjs.org/prettier-plugin-curly/-/prettier-plugin-curly-0.1.3.tgz",
"integrity": "sha512-NYr2BPex/0fFwDbiZZr91kfgBko1tmaorLOrVAkT5rN91mIYYJRiWabRxWGFqzRSO7J0eoEcxakY9NWvJWAh4w==",
"dev": true,
"dependencies": {
"@babel/parser": "^7.22.5",
"@babel/traverse": "^7.22.5"
},
"engines": {
"node": ">=18"
},
"peerDependencies": {
"prettier": "^2 || ^3"
}
},
"node_modules/process-nextick-args": { "node_modules/process-nextick-args": {
"version": "1.0.7", "version": "1.0.7",
"resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-1.0.7.tgz", "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-1.0.7.tgz",
@ -2286,6 +2687,15 @@
"tiny-inflate": "^1.0.2" "tiny-inflate": "^1.0.2"
} }
}, },
"node_modules/to-fast-properties": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-2.0.0.tgz",
"integrity": "sha512-/OaKK0xYrs3DmxRYqL/yDc+FxFUVYhDlXMhRmv3z915w2HF1tnN1omB354j8VUGO/hbRzyD6Y3sA7v7GS/ceog==",
"dev": true,
"engines": {
"node": ">=4"
}
},
"node_modules/to-regex-range": { "node_modules/to-regex-range": {
"version": "5.0.1", "version": "5.0.1",
"resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz",
@ -2555,6 +2965,286 @@
} }
}, },
"dependencies": { "dependencies": {
"@babel/code-frame": {
"version": "7.22.13",
"resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.22.13.tgz",
"integrity": "sha512-XktuhWlJ5g+3TJXc5upd9Ks1HutSArik6jf2eAjYFyIOf4ej3RN+184cZbzDvbPnuTJIUhPKKJE3cIsYTiAT3w==",
"dev": true,
"requires": {
"@babel/highlight": "^7.22.13",
"chalk": "^2.4.2"
},
"dependencies": {
"ansi-styles": {
"version": "3.2.1",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz",
"integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==",
"dev": true,
"requires": {
"color-convert": "^1.9.0"
}
},
"chalk": {
"version": "2.4.2",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz",
"integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==",
"dev": true,
"requires": {
"ansi-styles": "^3.2.1",
"escape-string-regexp": "^1.0.5",
"supports-color": "^5.3.0"
}
},
"color-convert": {
"version": "1.9.3",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz",
"integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==",
"dev": true,
"requires": {
"color-name": "1.1.3"
}
},
"color-name": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz",
"integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==",
"dev": true
},
"escape-string-regexp": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz",
"integrity": "sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg==",
"dev": true
},
"has-flag": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz",
"integrity": "sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==",
"dev": true
},
"supports-color": {
"version": "5.5.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz",
"integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==",
"dev": true,
"requires": {
"has-flag": "^3.0.0"
}
}
}
},
"@babel/generator": {
"version": "7.23.0",
"resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.23.0.tgz",
"integrity": "sha512-lN85QRR+5IbYrMWM6Y4pE/noaQtg4pNiqeNGX60eqOfo6gtEj6uw/JagelB8vVztSd7R6M5n1+PQkDbHbBRU4g==",
"dev": true,
"requires": {
"@babel/types": "^7.23.0",
"@jridgewell/gen-mapping": "^0.3.2",
"@jridgewell/trace-mapping": "^0.3.17",
"jsesc": "^2.5.1"
}
},
"@babel/helper-environment-visitor": {
"version": "7.22.20",
"resolved": "https://registry.npmjs.org/@babel/helper-environment-visitor/-/helper-environment-visitor-7.22.20.tgz",
"integrity": "sha512-zfedSIzFhat/gFhWfHtgWvlec0nqB9YEIVrpuwjruLlXfUSnA8cJB0miHKwqDnQ7d32aKo2xt88/xZptwxbfhA==",
"dev": true
},
"@babel/helper-function-name": {
"version": "7.23.0",
"resolved": "https://registry.npmjs.org/@babel/helper-function-name/-/helper-function-name-7.23.0.tgz",
"integrity": "sha512-OErEqsrxjZTJciZ4Oo+eoZqeW9UIiOcuYKRJA4ZAgV9myA+pOXhhmpfNCKjEH/auVfEYVFJ6y1Tc4r0eIApqiw==",
"dev": true,
"requires": {
"@babel/template": "^7.22.15",
"@babel/types": "^7.23.0"
}
},
"@babel/helper-hoist-variables": {
"version": "7.22.5",
"resolved": "https://registry.npmjs.org/@babel/helper-hoist-variables/-/helper-hoist-variables-7.22.5.tgz",
"integrity": "sha512-wGjk9QZVzvknA6yKIUURb8zY3grXCcOZt+/7Wcy8O2uctxhplmUPkOdlgoNhmdVee2c92JXbf1xpMtVNbfoxRw==",
"dev": true,
"requires": {
"@babel/types": "^7.22.5"
}
},
"@babel/helper-split-export-declaration": {
"version": "7.22.6",
"resolved": "https://registry.npmjs.org/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.22.6.tgz",
"integrity": "sha512-AsUnxuLhRYsisFiaJwvp1QF+I3KjD5FOxut14q/GzovUe6orHLesW2C7d754kRm53h5gqrz6sFl6sxc4BVtE/g==",
"dev": true,
"requires": {
"@babel/types": "^7.22.5"
}
},
"@babel/helper-string-parser": {
"version": "7.22.5",
"resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.22.5.tgz",
"integrity": "sha512-mM4COjgZox8U+JcXQwPijIZLElkgEpO5rsERVDJTc2qfCDfERyob6k5WegS14SX18IIjv+XD+GrqNumY5JRCDw==",
"dev": true
},
"@babel/helper-validator-identifier": {
"version": "7.22.20",
"resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.22.20.tgz",
"integrity": "sha512-Y4OZ+ytlatR8AI+8KZfKuL5urKp7qey08ha31L8b3BwewJAoJamTzyvxPR/5D+KkdJCGPq/+8TukHBlY10FX9A==",
"dev": true
},
"@babel/highlight": {
"version": "7.22.20",
"resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.22.20.tgz",
"integrity": "sha512-dkdMCN3py0+ksCgYmGG8jKeGA/8Tk+gJwSYYlFGxG5lmhfKNoAy004YpLxpS1W2J8m/EK2Ew+yOs9pVRwO89mg==",
"dev": true,
"requires": {
"@babel/helper-validator-identifier": "^7.22.20",
"chalk": "^2.4.2",
"js-tokens": "^4.0.0"
},
"dependencies": {
"ansi-styles": {
"version": "3.2.1",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz",
"integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==",
"dev": true,
"requires": {
"color-convert": "^1.9.0"
}
},
"chalk": {
"version": "2.4.2",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz",
"integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==",
"dev": true,
"requires": {
"ansi-styles": "^3.2.1",
"escape-string-regexp": "^1.0.5",
"supports-color": "^5.3.0"
}
},
"color-convert": {
"version": "1.9.3",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz",
"integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==",
"dev": true,
"requires": {
"color-name": "1.1.3"
}
},
"color-name": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz",
"integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==",
"dev": true
},
"escape-string-regexp": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz",
"integrity": "sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg==",
"dev": true
},
"has-flag": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz",
"integrity": "sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==",
"dev": true
},
"supports-color": {
"version": "5.5.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz",
"integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==",
"dev": true,
"requires": {
"has-flag": "^3.0.0"
}
}
}
},
"@babel/parser": {
"version": "7.23.0",
"resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.23.0.tgz",
"integrity": "sha512-vvPKKdMemU85V9WE/l5wZEmImpCtLqbnTvqDS2U1fJ96KrxoW7KrXhNsNCblQlg8Ck4b85yxdTyelsMUgFUXiw==",
"dev": true
},
"@babel/template": {
"version": "7.22.15",
"resolved": "https://registry.npmjs.org/@babel/template/-/template-7.22.15.tgz",
"integrity": "sha512-QPErUVm4uyJa60rkI73qneDacvdvzxshT3kksGqlGWYdOTIUOwJ7RDUL8sGqslY1uXWSL6xMFKEXDS3ox2uF0w==",
"dev": true,
"requires": {
"@babel/code-frame": "^7.22.13",
"@babel/parser": "^7.22.15",
"@babel/types": "^7.22.15"
}
},
"@babel/traverse": {
"version": "7.23.0",
"resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.23.0.tgz",
"integrity": "sha512-t/QaEvyIoIkwzpiZ7aoSKK8kObQYeF7T2v+dazAYCb8SXtp58zEVkWW7zAnju8FNKNdr4ScAOEDmMItbyOmEYw==",
"dev": true,
"requires": {
"@babel/code-frame": "^7.22.13",
"@babel/generator": "^7.23.0",
"@babel/helper-environment-visitor": "^7.22.20",
"@babel/helper-function-name": "^7.23.0",
"@babel/helper-hoist-variables": "^7.22.5",
"@babel/helper-split-export-declaration": "^7.22.6",
"@babel/parser": "^7.23.0",
"@babel/types": "^7.23.0",
"debug": "^4.1.0",
"globals": "^11.1.0"
}
},
"@babel/types": {
"version": "7.23.0",
"resolved": "https://registry.npmjs.org/@babel/types/-/types-7.23.0.tgz",
"integrity": "sha512-0oIyUfKoI3mSqMvsxBdclDwxXKXAUA8v/apZbc+iSyARYou1o8ZGDxbUYyLFoW2arqS2jDGqJuZvv1d/io1axg==",
"dev": true,
"requires": {
"@babel/helper-string-parser": "^7.22.5",
"@babel/helper-validator-identifier": "^7.22.20",
"to-fast-properties": "^2.0.0"
}
},
"@jridgewell/gen-mapping": {
"version": "0.3.3",
"resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.3.tgz",
"integrity": "sha512-HLhSWOLRi875zjjMG/r+Nv0oCW8umGb0BgEhyX3dDX3egwZtB8PqLnjz3yedt8R5StBrzcg4aBpnh8UA9D1BoQ==",
"dev": true,
"requires": {
"@jridgewell/set-array": "^1.0.1",
"@jridgewell/sourcemap-codec": "^1.4.10",
"@jridgewell/trace-mapping": "^0.3.9"
}
},
"@jridgewell/resolve-uri": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.1.tgz",
"integrity": "sha512-dSYZh7HhCDtCKm4QakX0xFpsRDqjjtZf/kjI/v3T3Nwt5r8/qz/M19F9ySyOqU94SXBmeG9ttTul+YnR4LOxFA==",
"dev": true
},
"@jridgewell/set-array": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/@jridgewell/set-array/-/set-array-1.1.2.tgz",
"integrity": "sha512-xnkseuNADM0gt2bs+BvhO0p78Mk762YnZdsuzFV018NoG1Sj1SCQvpSqa7XUaTam5vAGasABV9qXASMKnFMwMw==",
"dev": true
},
"@jridgewell/sourcemap-codec": {
"version": "1.4.15",
"resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.15.tgz",
"integrity": "sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg==",
"dev": true
},
"@jridgewell/trace-mapping": {
"version": "0.3.19",
"resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.19.tgz",
"integrity": "sha512-kf37QtfW+Hwx/buWGMPcR60iF9ziHa6r/CZJIHbmcm4+0qrXiVdxegAH0F6yddEVQ7zdkjcGCgCzUu+BcbhQxw==",
"dev": true,
"requires": {
"@jridgewell/resolve-uri": "^3.1.0",
"@jridgewell/sourcemap-codec": "^1.4.14"
}
},
"@mapbox/sexagesimal": { "@mapbox/sexagesimal": {
"version": "1.1.0", "version": "1.1.0",
"resolved": "https://registry.npmjs.org/@mapbox/sexagesimal/-/sexagesimal-1.1.0.tgz", "resolved": "https://registry.npmjs.org/@mapbox/sexagesimal/-/sexagesimal-1.1.0.tgz",
@ -3296,6 +3986,12 @@
"is-glob": "^4.0.1" "is-glob": "^4.0.1"
} }
}, },
"globals": {
"version": "11.12.0",
"resolved": "https://registry.npmjs.org/globals/-/globals-11.12.0.tgz",
"integrity": "sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA==",
"dev": true
},
"gopd": { "gopd": {
"version": "1.0.1", "version": "1.0.1",
"resolved": "https://registry.npmjs.org/gopd/-/gopd-1.0.1.tgz", "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.0.1.tgz",
@ -3506,6 +4202,12 @@
"resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
"integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=" "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE="
}, },
"js-tokens": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz",
"integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==",
"dev": true
},
"js-yaml": { "js-yaml": {
"version": "4.1.0", "version": "4.1.0",
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz",
@ -3515,6 +4217,12 @@
"argparse": "^2.0.1" "argparse": "^2.0.1"
} }
}, },
"jsesc": {
"version": "2.5.2",
"resolved": "https://registry.npmjs.org/jsesc/-/jsesc-2.5.2.tgz",
"integrity": "sha512-OYu7XEzjkCQ3C5Ps3QIZsQfNpqoJyZZA99wd9aWd05NCtC5pWOkShK2mkL6HXQR6/Cy2lbNdPlZBpuQHXE63gA==",
"dev": true
},
"jsonparse": { "jsonparse": {
"version": "0.0.5", "version": "0.0.5",
"resolved": "https://registry.npmjs.org/jsonparse/-/jsonparse-0.0.5.tgz", "resolved": "https://registry.npmjs.org/jsonparse/-/jsonparse-0.0.5.tgz",
@ -4042,6 +4750,16 @@
"integrity": "sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==", "integrity": "sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==",
"dev": true "dev": true
}, },
"prettier-plugin-curly": {
"version": "0.1.3",
"resolved": "https://registry.npmjs.org/prettier-plugin-curly/-/prettier-plugin-curly-0.1.3.tgz",
"integrity": "sha512-NYr2BPex/0fFwDbiZZr91kfgBko1tmaorLOrVAkT5rN91mIYYJRiWabRxWGFqzRSO7J0eoEcxakY9NWvJWAh4w==",
"dev": true,
"requires": {
"@babel/parser": "^7.22.5",
"@babel/traverse": "^7.22.5"
}
},
"process-nextick-args": { "process-nextick-args": {
"version": "1.0.7", "version": "1.0.7",
"resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-1.0.7.tgz", "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-1.0.7.tgz",
@ -4269,6 +4987,12 @@
"tiny-inflate": "^1.0.2" "tiny-inflate": "^1.0.2"
} }
}, },
"to-fast-properties": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-2.0.0.tgz",
"integrity": "sha512-/OaKK0xYrs3DmxRYqL/yDc+FxFUVYhDlXMhRmv3z915w2HF1tnN1omB354j8VUGO/hbRzyD6Y3sA7v7GS/ceog==",
"dev": true
},
"to-regex-range": { "to-regex-range": {
"version": "5.0.1", "version": "5.0.1",
"resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz",

View file

@ -12,6 +12,7 @@
"mocha": "^10.2.0", "mocha": "^10.2.0",
"optimist": "~0.4.0", "optimist": "~0.4.0",
"prettier": "^2.8.8", "prettier": "^2.8.8",
"prettier-plugin-curly": "^0.1.3",
"sinon": "^15.1.0", "sinon": "^15.1.0",
"uglify-js": "~3.17.4" "uglify-js": "~3.17.4"
}, },

View file

@ -70,7 +70,9 @@ L.U.AutoComplete = L.Class.extend({
onKeyDown: function (e) { onKeyDown: function (e) {
switch (e.keyCode) { switch (e.keyCode) {
case L.U.Keys.TAB: case L.U.Keys.TAB:
if (this.CURRENT !== null) this.setChoice() if (this.CURRENT !== null) {
this.setChoice()
}
L.DomEvent.stop(e) L.DomEvent.stop(e)
break break
case L.U.Keys.ENTER: case L.U.Keys.ENTER:
@ -164,8 +166,11 @@ L.U.AutoComplete = L.Class.extend({
this.clear() this.clear()
return return
} }
if (`${val}` === `${this.CACHE}`) return if (`${val}` === `${this.CACHE}`) {
else this.CACHE = val return
} else {
this.CACHE = val
}
this._do_search( this._do_search(
val, val,
function (data) { function (data) {
@ -227,8 +232,11 @@ L.U.AutoComplete = L.Class.extend({
highlight: function () { highlight: function () {
this.forEach(this.RESULTS, (result, index) => { this.forEach(this.RESULTS, (result, index) => {
if (index === this.CURRENT) L.DomUtil.addClass(result.el, 'on') if (index === this.CURRENT) {
else L.DomUtil.removeClass(result.el, 'on') L.DomUtil.addClass(result.el, 'on')
} else {
L.DomUtil.removeClass(result.el, 'on')
}
}) })
}, },
@ -260,7 +268,9 @@ L.U.AutoComplete = L.Class.extend({
L.U.AutoComplete.Ajax = L.U.AutoComplete.extend({ L.U.AutoComplete.Ajax = L.U.AutoComplete.extend({
initialize: function (el, options) { initialize: function (el, options) {
L.U.AutoComplete.prototype.initialize.call(this, el, options) L.U.AutoComplete.prototype.initialize.call(this, el, options)
if (!this.el) return this if (!this.el) {
return this
}
this.createInput() this.createInput()
this.createContainer() this.createContainer()
this.selected_container = this.initSelectedContainer() this.selected_container = this.initSelectedContainer()

View file

@ -6,8 +6,9 @@ L.U.BaseAction = L.ToolbarAction.extend({
tooltip: this.options.tooltip, tooltip: this.options.tooltip,
} }
L.ToolbarAction.prototype.initialize.call(this) L.ToolbarAction.prototype.initialize.call(this)
if (this.options.helpMenu && !this.map.helpMenuActions[this.options.className]) if (this.options.helpMenu && !this.map.helpMenuActions[this.options.className]) {
this.map.helpMenuActions[this.options.className] = this this.map.helpMenuActions[this.options.className] = this
}
}, },
}) })
@ -177,8 +178,11 @@ L.U.ToggleEditAction = L.U.BaseFeatureAction.extend({
}, },
onClick: function (e) { onClick: function (e) {
if (this.feature._toggleEditing) this.feature._toggleEditing(e) // Path if (this.feature._toggleEditing) {
else this.feature.edit(e) // Marker this.feature._toggleEditing(e)
} else {
this.feature.edit(e)
} // Marker
}, },
}) })
@ -191,8 +195,9 @@ L.U.DeleteFeatureAction = L.U.BaseFeatureAction.extend({
}, },
postInit: function () { postInit: function () {
if (!this.feature.isMulti()) if (!this.feature.isMulti()) {
this.options.toolbarIcon.className = 'umap-delete-one-of-one' this.options.toolbarIcon.className = 'umap-delete-one-of-one'
}
}, },
onClick: function (e) { onClick: function (e) {
@ -275,7 +280,9 @@ L.U.ContinueLineAction = L.U.BaseVertexAction.extend({
// Leaflet.Toolbar doesn't allow twice same toolbar class… // Leaflet.Toolbar doesn't allow twice same toolbar class…
L.U.SettingsToolbar = L.Toolbar.Control.extend({ L.U.SettingsToolbar = L.Toolbar.Control.extend({
addTo: function (map) { addTo: function (map) {
if (map.options.editMode !== 'advanced') return if (map.options.editMode !== 'advanced') {
return
}
L.Toolbar.Control.prototype.addTo.call(this, map) L.Toolbar.Control.prototype.addTo.call(this, map)
}, },
}) })
@ -382,8 +389,11 @@ L.U.MoreControls = L.Control.extend({
const pos = this.getPosition(), const pos = this.getPosition(),
corner = this._map._controlCorners[pos], corner = this._map._controlCorners[pos],
className = 'umap-more-controls' className = 'umap-more-controls'
if (L.DomUtil.hasClass(corner, className)) L.DomUtil.removeClass(corner, className) if (L.DomUtil.hasClass(corner, className)) {
else L.DomUtil.addClass(corner, className) L.DomUtil.removeClass(corner, className)
} else {
L.DomUtil.addClass(corner, className)
}
}, },
}) })
@ -502,8 +512,12 @@ L.U.DataLayersControl = L.Control.extend({
}, },
onAdd: function (map) { onAdd: function (map) {
if (!this._container) this._initLayout(map) if (!this._container) {
if (map.options.datalayersControl === 'expanded') this.expand() this._initLayout(map)
}
if (map.options.datalayersControl === 'expanded') {
this.expand()
}
return this._container return this._container
}, },
@ -525,18 +539,21 @@ L.U.DataLayersControl = L.Control.extend({
}, },
collapse: function () { collapse: function () {
if (this._map.options.datalayersControl === 'expanded') return if (this._map.options.datalayersControl === 'expanded') {
return
}
L.DomUtil.removeClass(this._container, 'expanded') L.DomUtil.removeClass(this._container, 'expanded')
}, },
addDataLayer: function (container, datalayer, draggable) { addDataLayer: function (container, datalayer, draggable) {
const datalayerLi = L.DomUtil.create('li', '', container) const datalayerLi = L.DomUtil.create('li', '', container)
if (draggable) if (draggable) {
L.DomUtil.element( L.DomUtil.element(
'i', 'i',
{ className: 'drag-handle', title: L._('Drag to reorder') }, { className: 'drag-handle', title: L._('Drag to reorder') },
datalayerLi datalayerLi
) )
}
datalayer.renderToolbox(datalayerLi) datalayer.renderToolbox(datalayerLi)
const title = L.DomUtil.add( const title = L.DomUtil.add(
'span', 'span',
@ -557,7 +574,9 @@ L.U.DataLayersControl = L.Control.extend({
}, },
openPanel: function () { openPanel: function () {
if (!this.map.editEnabled) return if (!this.map.editEnabled) {
return
}
const container = L.DomUtil.create('ul', 'umap-browse-datalayers') const container = L.DomUtil.create('ul', 'umap-browse-datalayers')
this.map.eachDataLayerReverse(function (datalayer) { this.map.eachDataLayerReverse(function (datalayer) {
this.addDataLayer(container, datalayer, true) this.addDataLayer(container, datalayer, true)
@ -569,11 +588,17 @@ L.U.DataLayersControl = L.Control.extend({
const layer = this.map.datalayers[e.src.dataset.id], const layer = this.map.datalayers[e.src.dataset.id],
other = this.map.datalayers[e.dst.dataset.id], other = this.map.datalayers[e.dst.dataset.id],
minIndex = Math.min(e.initialIndex, e.finalIndex) minIndex = Math.min(e.initialIndex, e.finalIndex)
if (e.finalIndex === 0) layer.bringToTop() if (e.finalIndex === 0) {
else if (e.finalIndex > e.initialIndex) layer.insertBefore(other) layer.bringToTop()
else layer.insertAfter(other) } else if (e.finalIndex > e.initialIndex) {
layer.insertBefore(other)
} else {
layer.insertAfter(other)
}
this.map.eachDataLayerReverse((datalayer) => { this.map.eachDataLayerReverse((datalayer) => {
if (datalayer.getRank() >= minIndex) datalayer.isDirty = true if (datalayer.getRank() >= minIndex) {
datalayer.isDirty = true
}
}) })
this.map.indexDatalayers() this.map.indexDatalayers()
}, },
@ -615,16 +640,19 @@ L.U.DataLayer.include({
remove.title = L._('Delete layer') remove.title = L._('Delete layer')
if (this.isReadOnly()) { if (this.isReadOnly()) {
L.DomUtil.addClass(container, 'readonly') L.DomUtil.addClass(container, 'readonly')
} } else {
else {
L.DomEvent.on(edit, 'click', this.edit, this) L.DomEvent.on(edit, 'click', this.edit, this)
L.DomEvent.on(table, 'click', this.tableEdit, this) L.DomEvent.on(table, 'click', this.tableEdit, this)
L.DomEvent.on( L.DomEvent.on(
remove, remove,
'click', 'click',
function () { function () {
if (!this.isVisible()) return if (!this.isVisible()) {
if (!confirm(L._('Are you sure you want to delete this layer?'))) return return
}
if (!confirm(L._('Are you sure you want to delete this layer?'))) {
return
}
this._delete() this._delete()
this.map.ui.closePanel() this.map.ui.closePanel()
}, },
@ -673,7 +701,9 @@ L.U.DataLayer.include({
L.U.DataLayer.addInitHook(function () { L.U.DataLayer.addInitHook(function () {
this.on('hide', this.propagateHide) this.on('hide', this.propagateHide)
this.on('show', this.propagateShow) this.on('show', this.propagateShow)
if (this.isVisible()) this.propagateShow() if (this.isVisible()) {
this.propagateShow()
}
}) })
L.U.Map.include({ L.U.Map.include({
@ -761,7 +791,9 @@ L.U.Map.include({
const build = () => { const build = () => {
ul.innerHTML = '' ul.innerHTML = ''
datalayer.eachFeature((feature) => { datalayer.eachFeature((feature) => {
if (filterValue && !feature.matchFilter(filterValue, filterKeys)) return if (filterValue && !feature.matchFilter(filterValue, filterKeys)) {
return
}
ul.appendChild(addFeature(feature)) ul.appendChild(addFeature(feature))
}) })
} }
@ -808,7 +840,9 @@ L.U.Map.include({
keys.forEach((key) => { keys.forEach((key) => {
knownValues[key] = [] knownValues[key] = []
if (!this.facets[key]) this.facets[key] = [] if (!this.facets[key]) {
this.facets[key] = []
}
}) })
this.eachBrowsableDataLayer((datalayer) => { this.eachBrowsableDataLayer((datalayer) => {
@ -826,11 +860,14 @@ L.U.Map.include({
let found = false let found = false
this.eachBrowsableDataLayer((datalayer) => { this.eachBrowsableDataLayer((datalayer) => {
datalayer.resetLayer(true) datalayer.resetLayer(true)
if (datalayer.hasDataVisible()) found = true if (datalayer.hasDataVisible()) {
found = true
}
}) })
// TODO: display a results counter in the panel instead. // TODO: display a results counter in the panel instead.
if (!found) if (!found) {
this.ui.alert({ content: L._('No results for these facets'), level: 'info' }) this.ui.alert({ content: L._('No results for these facets'), level: 'info' })
}
} }
const fields = keys.map((current) => [ const fields = keys.map((current) => [
@ -996,10 +1033,11 @@ L.U.Map.include({
const status = this.permissions.getShareStatusDisplay() const status = this.permissions.getShareStatusDisplay()
name.textContent = this.getDisplayName() name.textContent = this.getDisplayName()
// status is not set until map is saved once // status is not set until map is saved once
if (status) if (status) {
share_status.textContent = L._('Visibility: {status}', { share_status.textContent = L._('Visibility: {status}', {
status: status, status: status,
}) })
}
} }
update() update()
this.once('saved', L.bind(update, this)) this.once('saved', L.bind(update, this))
@ -1127,8 +1165,11 @@ L.U.Map.include({
) )
exportCaveat.id = 'export_caveat_text' exportCaveat.id = 'export_caveat_text'
const toggleCaveat = () => { const toggleCaveat = () => {
if (typeInput.value === 'umap') exportCaveat.style.display = 'none' if (typeInput.value === 'umap') {
else exportCaveat.style.display = 'inherit' exportCaveat.style.display = 'none'
} else {
exportCaveat.style.display = 'inherit'
}
} }
L.DomEvent.on(typeInput, 'change', toggleCaveat) L.DomEvent.on(typeInput, 'change', toggleCaveat)
for (const key in this.EXPORT_TYPES) { for (const key in this.EXPORT_TYPES) {
@ -1136,15 +1177,20 @@ L.U.Map.include({
option = L.DomUtil.create('option', '', typeInput) option = L.DomUtil.create('option', '', typeInput)
option.value = key option.value = key
option.textContent = this.EXPORT_TYPES[key].name || key option.textContent = this.EXPORT_TYPES[key].name || key
if (this.EXPORT_TYPES[key].selected) option.selected = true if (this.EXPORT_TYPES[key].selected) {
option.selected = true
}
} }
} }
toggleCaveat() toggleCaveat()
const download = L.DomUtil.create('a', 'button', container) const download = L.DomUtil.create('a', 'button', container)
download.textContent = L._('Download data') download.textContent = L._('Download data')
L.DomEvent.on(download, 'click', () => { L.DomEvent.on(download, 'click', () => {
if (typeInput.value === 'umap') this.fullDownload() if (typeInput.value === 'umap') {
else this.download(typeInput.value) this.fullDownload()
} else {
this.download(typeInput.value)
}
}) })
this.ui.openPanel({ data: { html: container } }) this.ui.openPanel({ data: { html: container } })
}, },
@ -1215,8 +1261,9 @@ L.U.TileLayerControl = L.Control.extend({
if ( if (
window.location.protocol === 'https:' && window.location.protocol === 'https:' &&
tilelayer.options.url_template.indexOf('http:') === 0 tilelayer.options.url_template.indexOf('http:') === 0
) ) {
return return
}
this.addTileLayerElement(tilelayer, options) this.addTileLayerElement(tilelayer, options)
}, this) }, this)
this.map.ui.openPanel({ this.map.ui.openPanel({
@ -1238,7 +1285,9 @@ L.U.TileLayerControl = L.Control.extend({
'click', 'click',
function () { function () {
this.map.selectTileLayer(tilelayer) this.map.selectTileLayer(tilelayer)
if (options && options.callback) options.callback(tilelayer) if (options && options.callback) {
options.callback(tilelayer)
}
}, },
this this
) )
@ -1309,7 +1358,9 @@ L.U.Search = L.PhotonSearch.extend({
initialize: function (map, input, options) { initialize: function (map, input, options) {
L.PhotonSearch.prototype.initialize.call(this, map, input, options) L.PhotonSearch.prototype.initialize.call(this, map, input, options)
this.options.url = map.options.urls.search this.options.url = map.options.urls.search
if (map.options.maxBounds) this.options.bbox = map.options.maxBounds.toBBoxString() if (map.options.maxBounds) {
this.options.bbox = map.options.maxBounds.toBBoxString()
}
}, },
onBlur: function (e) { onBlur: function (e) {
@ -1379,7 +1430,9 @@ L.U.SearchControl = L.Control.extend({
limit: 10, limit: 10,
noResultLabel: L._('No results'), noResultLabel: L._('No results'),
} }
if (map.options.photonUrl) options.url = map.options.photonUrl if (map.options.photonUrl) {
options.url = map.options.photonUrl
}
const container = L.DomUtil.create('div', '') const container = L.DomUtil.create('div', '')
const title = L.DomUtil.create('h3', '', container) const title = L.DomUtil.create('h3', '', container)
@ -1537,13 +1590,18 @@ L.U.Editable = L.Editable.extend({
this.on('editable:drawing:end', this.closeTooltip) this.on('editable:drawing:end', this.closeTooltip)
// Layer for items added by users // Layer for items added by users
this.on('editable:drawing:cancel', (e) => { this.on('editable:drawing:cancel', (e) => {
if (e.layer._latlngs && e.layer._latlngs.length < e.layer.editor.MIN_VERTEX) if (e.layer._latlngs && e.layer._latlngs.length < e.layer.editor.MIN_VERTEX) {
e.layer.del() e.layer.del()
if (e.layer instanceof L.U.Marker) e.layer.del() }
if (e.layer instanceof L.U.Marker) {
e.layer.del()
}
}) })
this.on('editable:drawing:commit', function (e) { this.on('editable:drawing:commit', function (e) {
e.layer.isDirty = true e.layer.isDirty = true
if (this.map.editedFeature !== e.layer) e.layer.edit(e) if (this.map.editedFeature !== e.layer) {
e.layer.edit(e)
}
}) })
this.on('editable:editing', (e) => { this.on('editable:editing', (e) => {
const layer = e.layer const layer = e.layer
@ -1555,11 +1613,14 @@ L.U.Editable = L.Editable.extend({
}) })
this.on('editable:vertex:ctrlclick', (e) => { this.on('editable:vertex:ctrlclick', (e) => {
const index = e.vertex.getIndex() const index = e.vertex.getIndex()
if (index === 0 || (index === e.vertex.getLastIndex() && e.vertex.continue)) if (index === 0 || (index === e.vertex.getLastIndex() && e.vertex.continue)) {
e.vertex.continue() e.vertex.continue()
}
}) })
this.on('editable:vertex:altclick', (e) => { this.on('editable:vertex:altclick', (e) => {
if (e.vertex.editor.vertexCanBeDeleted(e.vertex)) e.vertex.delete() if (e.vertex.editor.vertexCanBeDeleted(e.vertex)) {
e.vertex.delete()
}
}) })
this.on('editable:vertex:rawclick', this.onVertexRawClick) this.on('editable:vertex:rawclick', this.onVertexRawClick)
}, },
@ -1576,7 +1637,7 @@ L.U.Editable = L.Editable.extend({
return new L.U.Marker(this.map, latlng, this._getDefaultProperties()) return new L.U.Marker(this.map, latlng, this._getDefaultProperties())
}, },
_getDefaultProperties: function() { _getDefaultProperties: function () {
const result = {} const result = {}
if (this.map.options.featuresHaveOwner && this.map.options.hasOwnProperty('user')) { if (this.map.options.featuresHaveOwner && this.map.options.hasOwnProperty('user')) {
result.geojson = { properties: { owner: this.map.options.user.id } } result.geojson = { properties: { owner: this.map.options.user.id } }

View file

@ -13,7 +13,9 @@ L.Util.queryString = (name, fallback) => {
qa = {} qa = {}
for (const i in qs) { for (const i in qs) {
const key = qs[i].split('=') const key = qs[i].split('=')
if (!key) continue if (!key) {
continue
}
qa[decode(key[0])] = key[1] ? decode(key[1]) : 1 qa[decode(key[0])] = key[1] ? decode(key[1]) : 1
} }
return qa[name] || fallback return qa[name] || fallback
@ -26,19 +28,27 @@ L.Util.booleanFromQueryString = (name) => {
L.Util.setFromQueryString = (options, name) => { L.Util.setFromQueryString = (options, name) => {
const value = L.Util.queryString(name) const value = L.Util.queryString(name)
if (typeof value !== 'undefined') options[name] = value if (typeof value !== 'undefined') {
options[name] = value
}
} }
L.Util.setBooleanFromQueryString = (options, name) => { L.Util.setBooleanFromQueryString = (options, name) => {
const value = L.Util.queryString(name) const value = L.Util.queryString(name)
if (typeof value !== 'undefined') options[name] = value == '1' || value == 'true' if (typeof value !== 'undefined') {
options[name] = value == '1' || value == 'true'
}
} }
L.Util.setNullableBooleanFromQueryString = (options, name) => { L.Util.setNullableBooleanFromQueryString = (options, name) => {
let value = L.Util.queryString(name) let value = L.Util.queryString(name)
if (typeof value !== 'undefined') { if (typeof value !== 'undefined') {
if (value === 'null') value = null if (value === 'null') {
else if (value === '0' || value === 'false') value = false value = null
else value = true } else if (value === '0' || value === 'false') {
value = false
} else {
value = true
}
options[name] = value options[name] = value
} }
} }
@ -74,7 +84,9 @@ L.Util.escapeHTML = (s) => {
return s return s
} }
L.Util.toHTML = (r, options) => { L.Util.toHTML = (r, options) => {
if (!r) return '' if (!r) {
return ''
}
const target = (options && options.target) || 'blank' const target = (options && options.target) || 'blank'
let ii let ii
@ -94,8 +106,9 @@ L.Util.toHTML = (r, options) => {
// unordered lists // unordered lists
r = r.replace(/^\*\* (.*)/gm, '<ul><ul><li>$1</li></ul></ul>') r = r.replace(/^\*\* (.*)/gm, '<ul><ul><li>$1</li></ul></ul>')
r = r.replace(/^\* (.*)/gm, '<ul><li>$1</li></ul>') r = r.replace(/^\* (.*)/gm, '<ul><li>$1</li></ul>')
for (ii = 0; ii < 3; ii++) for (ii = 0; ii < 3; ii++) {
r = r.replace(new RegExp(`</ul>${newline}<ul>`, 'g'), newline) r = r.replace(new RegExp(`</ul>${newline}<ul>`, 'g'), newline)
}
// links // links
r = r.replace(/(\[\[http)/g, '[[h_t_t_p') // Escape for avoiding clash between [[http://xxx]] and http://xxx r = r.replace(/(\[\[http)/g, '[[h_t_t_p') // Escape for avoiding clash between [[http://xxx]] and http://xxx
@ -129,13 +142,18 @@ L.Util.toHTML = (r, options) => {
// images // images
r = r.replace(/{{([^\]|]*?)}}/g, '<img src="$1">') r = r.replace(/{{([^\]|]*?)}}/g, '<img src="$1">')
r = r.replace(/{{([^|]*?)\|(\d*?)(px)?}}/g, '<img src="$1" style="width:$2px;min-width:$2px;">') r = r.replace(
/{{([^|]*?)\|(\d*?)(px)?}}/g,
'<img src="$1" style="width:$2px;min-width:$2px;">'
)
//Unescape http //Unescape http
r = r.replace(/(h_t_t_p)/g, 'http') r = r.replace(/(h_t_t_p)/g, 'http')
// Preserver line breaks // Preserver line breaks
if (newline) r = r.replace(new RegExp(`${newline}(?=[^]+)`, 'g'), `<br>${newline}`) if (newline) {
r = r.replace(new RegExp(`${newline}(?=[^]+)`, 'g'), `<br>${newline}`)
}
r = L.Util.escapeHTML(r) r = L.Util.escapeHTML(r)
@ -151,13 +169,21 @@ L.Util.detectFileType = (f) => {
if (f.type === 'application/vnd.google-earth.kml+xml' || ext('.kml')) { if (f.type === 'application/vnd.google-earth.kml+xml' || ext('.kml')) {
return 'kml' return 'kml'
} }
if (ext('.gpx')) return 'gpx' if (ext('.gpx')) {
if (ext('.geojson') || ext('.json')) return 'geojson' return 'gpx'
}
if (ext('.geojson') || ext('.json')) {
return 'geojson'
}
if (f.type === 'text/csv' || ext('.csv') || ext('.tsv') || ext('.dsv')) { if (f.type === 'text/csv' || ext('.csv') || ext('.tsv') || ext('.dsv')) {
return 'csv' return 'csv'
} }
if (ext('.xml') || ext('.osm')) return 'osm' if (ext('.xml') || ext('.osm')) {
if (ext('.umap')) return 'umap' return 'osm'
}
if (ext('.umap')) {
return 'umap'
}
} }
L.Util.usableOption = (options, option) => L.Util.usableOption = (options, option) =>
@ -168,7 +194,9 @@ L.Util.greedyTemplate = (str, data, ignore) => {
let value = data let value = data
for (let i = 0; i < path.length; i++) { for (let i = 0; i < path.length; i++) {
value = value[path[i]] value = value[path[i]]
if (value === undefined) break if (value === undefined) {
break
}
} }
return value return value
} }
@ -184,14 +212,21 @@ L.Util.greedyTemplate = (str, data, ignore) => {
} }
for (let i = 0; i < vars.length; i++) { for (let i = 0; i < vars.length; i++) {
path = vars[i] path = vars[i]
if (path.startsWith('"') && path.endsWith('"')) if (path.startsWith('"') && path.endsWith('"')) {
value = path.substring(1, path.length - 1) // static default value. value = path.substring(1, path.length - 1)
else value = getValue(data, path.split('.')) } else {
if (value !== undefined) break value = getValue(data, path.split('.'))
}
if (value !== undefined) {
break
}
} }
if (value === undefined) { if (value === undefined) {
if (ignore) value = str if (ignore) {
else value = '' value = str
} else {
value = ''
}
} }
return value return value
} }
@ -224,7 +259,9 @@ L.Util.sortFeatures = (features, sortKey) => {
numeric: true, numeric: true,
}) })
} }
if (score === 0 && sortKeys[i + 1]) return sort(a, b, i + 1) if (score === 0 && sortKeys[i + 1]) {
return sort(a, b, i + 1)
}
return score * reverse return score * reverse
} }
@ -239,7 +276,9 @@ L.Util.sortFeatures = (features, sortKey) => {
} }
L.Util.flattenCoordinates = (coords) => { L.Util.flattenCoordinates = (coords) => {
while (coords[0] && typeof coords[0][0] !== 'number') coords = coords[0] while (coords[0] && typeof coords[0][0] !== 'number') {
coords = coords[0]
}
return coords return coords
} }
@ -258,32 +297,31 @@ L.Util.hasVar = (value) => {
} }
L.Util.copyToClipboard = function (textToCopy) { L.Util.copyToClipboard = function (textToCopy) {
// https://stackoverflow.com/a/65996386 // https://stackoverflow.com/a/65996386
// Navigator clipboard api needs a secure context (https) // Navigator clipboard api needs a secure context (https)
if (navigator.clipboard && window.isSecureContext) { if (navigator.clipboard && window.isSecureContext) {
navigator.clipboard.writeText(textToCopy) navigator.clipboard.writeText(textToCopy)
} else { } else {
// Use the 'out of viewport hidden text area' trick // Use the 'out of viewport hidden text area' trick
const textArea = document.createElement('textarea') const textArea = document.createElement('textarea')
textArea.value = textToCopy textArea.value = textToCopy
// Move textarea out of the viewport so it's not visible // Move textarea out of the viewport so it's not visible
textArea.style.position = 'absolute' textArea.style.position = 'absolute'
textArea.style.left = '-999999px' textArea.style.left = '-999999px'
document.body.prepend(textArea) document.body.prepend(textArea)
textArea.select() textArea.select()
try { try {
document.execCommand('copy') document.execCommand('copy')
} catch (error) { } catch (error) {
console.error(error) console.error(error)
} finally { } finally {
textArea.remove() textArea.remove()
}
}
} }
}
}
L.DomUtil.add = (tagName, className, container, content) => { L.DomUtil.add = (tagName, className, container, content) => {
const el = L.DomUtil.create(tagName, className, container) const el = L.DomUtil.create(tagName, className, container)
@ -307,7 +345,9 @@ L.DomUtil.createFieldset = (container, legend, options) => {
L.DomUtil.removeClass(fieldset, 'on') L.DomUtil.removeClass(fieldset, 'on')
} else { } else {
L.DomUtil.addClass(fieldset, 'on') L.DomUtil.addClass(fieldset, 'on')
if (options.callback) options.callback.call(options.context || this) if (options.callback) {
options.callback.call(options.context || this)
}
} }
}) })
return fieldsEl return fieldsEl
@ -323,8 +363,11 @@ L.DomUtil.createButton = (className, container, content, callback, context) => {
} }
L.DomUtil.classIf = (el, className, bool) => { L.DomUtil.classIf = (el, className, bool) => {
if (bool) L.DomUtil.addClass(el, className) if (bool) {
else L.DomUtil.removeClass(el, className) L.DomUtil.addClass(el, className)
} else {
L.DomUtil.removeClass(el, className)
}
} }
L.DomUtil.element = (what, attrs, parent) => { L.DomUtil.element = (what, attrs, parent) => {
@ -475,7 +518,7 @@ L.U.Help = L.Class.extend({
link: function (container, entries) { link: function (container, entries) {
const helpButton = this.button(container, entries, 'umap-help-link') const helpButton = this.button(container, entries, 'umap-help-link')
helpButton.textContent = L._("Help") helpButton.textContent = L._('Help')
return helpButton return helpButton
}, },
@ -635,7 +678,9 @@ L.U.Orderable = L.Evented.extend({
this.src = null this.src = null
this.dst = null this.dst = null
this.els = this.parent.querySelectorAll(this.options.selector) this.els = this.parent.querySelectorAll(this.options.selector)
for (let i = 0; i < this.els.length; i++) this.makeDraggable(this.els[i]) for (let i = 0; i < this.els.length; i++) {
this.makeDraggable(this.els[i])
}
}, },
makeDraggable: function (node) { makeDraggable: function (node) {
@ -654,7 +699,9 @@ L.U.Orderable = L.Evented.extend({
findTarget: function (node) { findTarget: function (node) {
while (node) { while (node) {
if (this.nodeIndex(node) !== -1) return node if (this.nodeIndex(node) !== -1) {
return node
}
node = node.parentNode node = node.parentNode
} }
}, },
@ -670,7 +717,9 @@ L.U.Orderable = L.Evented.extend({
}, },
onDragOver: function (e) { onDragOver: function (e) {
if (e.preventDefault) e.preventDefault() // Necessary. Allows us to drop. if (e.preventDefault) {
e.preventDefault()
} // Necessary. Allows us to drop.
e.dataTransfer.dropEffect = 'move' e.dataTransfer.dropEffect = 'move'
return false return false
}, },
@ -678,12 +727,17 @@ L.U.Orderable = L.Evented.extend({
onDragEnter: function (e) { onDragEnter: function (e) {
// e.target is the current hover target. // e.target is the current hover target.
const dst = this.findTarget(e.target) const dst = this.findTarget(e.target)
if (!dst || dst === this.src) return if (!dst || dst === this.src) {
return
}
this.dst = dst this.dst = dst
const targetIndex = this.nodeIndex(this.dst), const targetIndex = this.nodeIndex(this.dst),
srcIndex = this.nodeIndex(this.src) srcIndex = this.nodeIndex(this.src)
if (targetIndex > srcIndex) this.parent.insertBefore(this.dst, this.src) if (targetIndex > srcIndex) {
else this.parent.insertBefore(this.src, this.dst) this.parent.insertBefore(this.dst, this.src)
} else {
this.parent.insertBefore(this.src, this.dst)
}
}, },
onDragLeave: function (e) { onDragLeave: function (e) {
@ -692,8 +746,12 @@ L.U.Orderable = L.Evented.extend({
onDrop: function (e) { onDrop: function (e) {
// e.target is current target element. // e.target is current target element.
if (e.stopPropagation) e.stopPropagation() // Stops the browser from redirecting. if (e.stopPropagation) {
if (!this.dst) return e.stopPropagation()
} // Stops the browser from redirecting.
if (!this.dst) {
return
}
this.fire('drop', { this.fire('drop', {
src: this.src, src: this.src,
initialIndex: this.initialIndex, initialIndex: this.initialIndex,

View file

@ -15,7 +15,9 @@ L.U.DataLayerPermissions = L.Class.extend({
}, },
set: function (status) { set: function (status) {
isDirty = status isDirty = status
if (status) self.datalayer.isDirty = status if (status) {
self.datalayer.isDirty = status
}
}, },
}) })
} catch (e) { } catch (e) {
@ -38,7 +40,9 @@ L.U.DataLayerPermissions = L.Class.extend({
}, },
], ],
], ],
builder = new L.U.FormBuilder(this, fields, {className: 'umap-form datalayer-permissions'}), builder = new L.U.FormBuilder(this, fields, {
className: 'umap-form datalayer-permissions',
}),
form = builder.build() form = builder.build()
container.appendChild(form) container.appendChild(form)
}, },
@ -50,7 +54,9 @@ L.U.DataLayerPermissions = L.Class.extend({
}) })
}, },
save: function () { save: function () {
if (!this.isDirty) return this.datalayer.map.continueSaving() if (!this.isDirty) {
return this.datalayer.map.continueSaving()
}
const formData = new FormData() const formData = new FormData()
formData.append('edit_status', this.options.edit_status) formData.append('edit_status', this.options.edit_status)
this.datalayer.map.post(this.getUrl(), { this.datalayer.map.post(this.getUrl(), {

View file

@ -49,14 +49,17 @@ L.U.FeatureMixin = {
getPermalink: function () { getPermalink: function () {
const slug = this.getSlug() const slug = this.getSlug()
if (slug) if (slug) {
return `${L.Util.getBaseUrl()}?${L.Util.buildQueryString({ feature: slug })}${ return `${L.Util.getBaseUrl()}?${L.Util.buildQueryString({ feature: slug })}${
window.location.hash window.location.hash
}` }`
}
}, },
view: function (e) { view: function (e) {
if (this.map.editEnabled) return if (this.map.editEnabled) {
return
}
const outlink = this.getOption('outlink'), const outlink = this.getOption('outlink'),
target = this.getOption('outlinkTarget') target = this.getOption('outlinkTarget')
if (outlink) { if (outlink) {
@ -73,19 +76,25 @@ L.U.FeatureMixin = {
return return
} }
// TODO deal with an event instead? // TODO deal with an event instead?
if (this.map.slideshow) this.map.slideshow.current = this if (this.map.slideshow) {
this.map.slideshow.current = this
}
this.map.currentFeature = this this.map.currentFeature = this
this.attachPopup() this.attachPopup()
this.openPopup((e && e.latlng) || this.getCenter()) this.openPopup((e && e.latlng) || this.getCenter())
}, },
openPopup: function () { openPopup: function () {
if (this.map.editEnabled) return if (this.map.editEnabled) {
return
}
this.parentClass.prototype.openPopup.apply(this, arguments) this.parentClass.prototype.openPopup.apply(this, arguments)
}, },
edit: function (e) { edit: function (e) {
if (!this.map.editEnabled || this.isReadOnly()) return if (!this.map.editEnabled || this.isReadOnly()) {
return
}
const container = L.DomUtil.create('div', 'umap-feature-container') const container = L.DomUtil.create('div', 'umap-feature-container')
L.DomUtil.add( L.DomUtil.add(
'h3', 'h3',
@ -126,7 +135,9 @@ L.U.FeatureMixin = {
this.getAdvancedEditActions(advancedActions) this.getAdvancedEditActions(advancedActions)
this.map.ui.openPanel({ data: { html: container }, className: 'dark' }) this.map.ui.openPanel({ data: { html: container }, className: 'dark' })
this.map.editedFeature = this this.map.editedFeature = this
if (!this.isOnScreen()) this.zoomTo(e) if (!this.isOnScreen()) {
this.zoomTo(e)
}
}, },
getAdvancedEditActions: function (container) { getAdvancedEditActions: function (container) {
@ -138,7 +149,9 @@ L.U.FeatureMixin = {
'click', 'click',
function (e) { function (e) {
L.DomEvent.stop(e) L.DomEvent.stop(e)
if (this.confirmDelete()) this.map.ui.closePanel() if (this.confirmDelete()) {
this.map.ui.closePanel()
}
}, },
this this
) )
@ -190,18 +203,25 @@ L.U.FeatureMixin = {
endEdit: function () {}, endEdit: function () {},
getDisplayName: function (fallback) { getDisplayName: function (fallback) {
if (fallback === undefined) fallback = this.datalayer.options.name if (fallback === undefined) {
fallback = this.datalayer.options.name
}
const key = this.getOption('labelKey') || 'name' const key = this.getOption('labelKey') || 'name'
// Variables mode. // Variables mode.
if (L.Util.hasVar(key)) return L.Util.greedyTemplate(key, this.extendedProperties()) if (L.Util.hasVar(key)) {
return L.Util.greedyTemplate(key, this.extendedProperties())
}
// Simple mode. // Simple mode.
return this.properties[key] || this.properties.title || fallback return this.properties[key] || this.properties.title || fallback
}, },
hasPopupFooter: function () { hasPopupFooter: function () {
if (L.Browser.ielt9) return false if (L.Browser.ielt9) {
if (this.datalayer.isRemoteLayer() && this.datalayer.options.remoteData.dynamic)
return false return false
}
if (this.datalayer.isRemoteLayer() && this.datalayer.options.remoteData.dynamic) {
return false
}
return this.map.options.displayPopupFooter return this.map.options.displayPopupFooter
}, },
@ -295,7 +315,9 @@ L.U.FeatureMixin = {
// There is a variable inside. // There is a variable inside.
if (L.Util.hasVar(value)) { if (L.Util.hasVar(value)) {
value = L.Util.greedyTemplate(value, this.properties, true) value = L.Util.greedyTemplate(value, this.properties, true)
if (L.Util.hasVar(value)) value = this.map.getDefaultOption(option) if (L.Util.hasVar(value)) {
value = this.map.getDefaultOption(option)
}
} }
return value return value
}, },
@ -309,7 +331,9 @@ L.U.FeatureMixin = {
const latlng = e.latlng || this.getCenter() const latlng = e.latlng || this.getCenter()
this.map.setView(latlng, this.getBestZoom() || this.map.getZoom()) this.map.setView(latlng, this.getBestZoom() || this.map.getZoom())
} }
if (e.callback) e.callback.call(this) if (e.callback) {
e.callback.call(this)
}
}, },
getBestZoom: function () { getBestZoom: function () {
@ -356,7 +380,9 @@ L.U.FeatureMixin = {
}, },
_onClick: function (e) { _onClick: function (e) {
if (this.map.measureTools && this.map.measureTools.enabled()) return if (this.map.measureTools && this.map.measureTools.enabled()) {
return
}
this._popupHandlersAdded = true // Prevent leaflet from managing event this._popupHandlersAdded = true // Prevent leaflet from managing event
if (!this.map.editEnabled) { if (!this.map.editEnabled) {
this.view(e) this.view(e)
@ -365,8 +391,11 @@ L.U.FeatureMixin = {
if (e.originalEvent.ctrlKey || e.originalEvent.metaKey) { if (e.originalEvent.ctrlKey || e.originalEvent.metaKey) {
this.datalayer.edit(e) this.datalayer.edit(e)
} else { } else {
if (this._toggleEditing) this._toggleEditing(e) if (this._toggleEditing) {
else this.edit(e) this._toggleEditing(e)
} else {
this.edit(e)
}
} }
} else { } else {
new L.Toolbar.Popup(e.latlng, { new L.Toolbar.Popup(e.latlng, {
@ -405,13 +434,14 @@ L.U.FeatureMixin = {
getContextMenuItems: function (e) { getContextMenuItems: function (e) {
const permalink = this.getPermalink() const permalink = this.getPermalink()
let items = [] let items = []
if (permalink) if (permalink) {
items.push({ items.push({
text: L._('Permalink'), text: L._('Permalink'),
callback: function () { callback: function () {
window.open(permalink) window.open(permalink)
}, },
}) })
}
if (this.map.editEnabled && !this.isReadOnly()) { if (this.map.editEnabled && !this.isReadOnly()) {
items = items.concat(this.getContextMenuEditItems(e)) items = items.concat(this.getContextMenuEditItems(e))
} }
@ -459,7 +489,9 @@ L.U.FeatureMixin = {
}, },
resetTooltip: function () { resetTooltip: function () {
if (!this.hasGeom()) return if (!this.hasGeom()) {
return
}
const displayName = this.getDisplayName(null) const displayName = this.getDisplayName(null)
let showLabel = this.getOption('showLabel') let showLabel = this.getOption('showLabel')
const oldLabelHover = this.getOption('labelHover') const oldLabelHover = this.getOption('labelHover')
@ -469,18 +501,22 @@ L.U.FeatureMixin = {
interactive: this.getOption('labelInteractive'), interactive: this.getOption('labelInteractive'),
} }
if (oldLabelHover && showLabel) showLabel = null // Retrocompat. if (oldLabelHover && showLabel) {
showLabel = null
} // Retrocompat.
options.permanent = showLabel === true options.permanent = showLabel === true
this.unbindTooltip() this.unbindTooltip()
if ((showLabel === true || showLabel === null) && displayName) if ((showLabel === true || showLabel === null) && displayName) {
this.bindTooltip(L.Util.escapeHTML(displayName), options) this.bindTooltip(L.Util.escapeHTML(displayName), options)
}
}, },
matchFilter: function (filter, keys) { matchFilter: function (filter, keys) {
filter = filter.toLowerCase() filter = filter.toLowerCase()
for (let i = 0; i < keys.length; i++) { for (let i = 0; i < keys.length; i++) {
if ((this.properties[keys[i]] || '').toLowerCase().indexOf(filter) !== -1) if ((this.properties[keys[i]] || '').toLowerCase().indexOf(filter) !== -1) {
return true return true
}
} }
return false return false
}, },
@ -490,7 +526,9 @@ L.U.FeatureMixin = {
for (const [property, expected] of Object.entries(facets)) { for (const [property, expected] of Object.entries(facets)) {
if (expected.length) { if (expected.length) {
let value = this.properties[property] let value = this.properties[property]
if (!value || !expected.includes(value)) return false if (!value || !expected.includes(value)) {
return false
}
} }
} }
return true return true
@ -521,8 +559,12 @@ L.U.FeatureMixin = {
extendedProperties: function () { extendedProperties: function () {
// Include context properties // Include context properties
properties = this.map.getGeoContext() properties = this.map.getGeoContext()
if (L.locale) properties.locale = L.locale if (L.locale) {
if (L.lang) properties.lang = L.lang properties.locale = L.locale
}
if (L.lang) {
properties.lang = L.lang
}
properties.rank = this.getRank() + 1 properties.rank = this.getRank() + 1
if (this.hasGeom()) { if (this.hasGeom()) {
center = this.getCenter() center = this.getCenter()
@ -559,7 +601,9 @@ L.U.Marker = L.Marker.extend({
}, },
this this
) )
if (!this.isReadOnly()) this.on('mouseover', this._enableDragging) if (!this.isReadOnly()) {
this.on('mouseover', this._enableDragging)
}
this.on('mouseout', this._onMouseOut) this.on('mouseout', this._onMouseOut)
this._popupHandlersAdded = true // prevent Leaflet from binding event on bindPopup this._popupHandlersAdded = true // prevent Leaflet from binding event on bindPopup
}, },
@ -582,7 +626,9 @@ L.U.Marker = L.Marker.extend({
_enableDragging: function () { _enableDragging: function () {
// TODO: start dragging after 1 second on mouse down // TODO: start dragging after 1 second on mouse down
if (this.map.editEnabled) { if (this.map.editEnabled) {
if (!this.editEnabled()) this.enableEdit() if (!this.editEnabled()) {
this.enableEdit()
}
// Enabling dragging on the marker override the Draggable._OnDown // Enabling dragging on the marker override the Draggable._OnDown
// event, which, as it stopPropagation, refrain the call of // event, which, as it stopPropagation, refrain the call of
// _onDown with map-pane element, which is responsible to // _onDown with map-pane element, which is responsible to
@ -594,7 +640,9 @@ L.U.Marker = L.Marker.extend({
_disableDragging: function () { _disableDragging: function () {
if (this.map.editEnabled) { if (this.map.editEnabled) {
if (this.editor && this.editor.drawing) return // when creating a new marker, the mouse can trigger the mouseover/mouseout event if (this.editor && this.editor.drawing) {
return
} // when creating a new marker, the mouse can trigger the mouseover/mouseout event
// do not listen to them // do not listen to them
this.disableEdit() this.disableEdit()
} }
@ -633,7 +681,9 @@ L.U.Marker = L.Marker.extend({
}, },
_getIconUrl: function (name) { _getIconUrl: function (name) {
if (typeof name === 'undefined') name = 'icon' if (typeof name === 'undefined') {
name = 'icon'
}
return this.getOption(`${name}Url`) return this.getOption(`${name}Url`)
}, },
@ -724,7 +774,9 @@ L.U.PathMixin = {
edit: function (e) { edit: function (e) {
if (this.map.editEnabled) { if (this.map.editEnabled) {
if (!this.editEnabled()) this.enableEdit() if (!this.editEnabled()) {
this.enableEdit()
}
L.U.FeatureMixin.edit.call(this, e) L.U.FeatureMixin.edit.call(this, e)
} }
}, },
@ -778,8 +830,11 @@ L.U.PathMixin = {
option = this.styleOptions[idx] option = this.styleOptions[idx]
options[option] = this.getDynamicOption(option) options[option] = this.getDynamicOption(option)
} }
if (options.interactive) this.options.pointerEvents = 'visiblePainted' if (options.interactive) {
else this.options.pointerEvents = 'stroke' this.options.pointerEvents = 'visiblePainted'
} else {
this.options.pointerEvents = 'stroke'
}
this.parentClass.prototype.setStyle.call(this, options) this.parentClass.prototype.setStyle.call(this, options)
}, },
@ -796,14 +851,18 @@ L.U.PathMixin = {
// this.map.on('showmeasure', this.showMeasureTooltip, this); // this.map.on('showmeasure', this.showMeasureTooltip, this);
// this.map.on('hidemeasure', this.removeTooltip, this); // this.map.on('hidemeasure', this.removeTooltip, this);
this.parentClass.prototype.onAdd.call(this, map) this.parentClass.prototype.onAdd.call(this, map)
if (this.editing && this.editing.enabled()) this.editing.addHooks() if (this.editing && this.editing.enabled()) {
this.editing.addHooks()
}
this.resetTooltip() this.resetTooltip()
}, },
onRemove: function (map) { onRemove: function (map) {
// this.map.off('showmeasure', this.showMeasureTooltip, this); // this.map.off('showmeasure', this.showMeasureTooltip, this);
// this.map.off('hidemeasure', this.removeTooltip, this); // this.map.off('hidemeasure', this.removeTooltip, this);
if (this.editing && this.editing.enabled()) this.editing.removeHooks() if (this.editing && this.editing.enabled()) {
this.editing.removeHooks()
}
L.U.FeatureMixin.onRemove.call(this, map) L.U.FeatureMixin.onRemove.call(this, map)
}, },
@ -832,22 +891,32 @@ L.U.PathMixin = {
}, },
_onDrag: function () { _onDrag: function () {
if (this._tooltip) this._tooltip.setLatLng(this.getCenter()) if (this._tooltip) {
this._tooltip.setLatLng(this.getCenter())
}
}, },
transferShape: function (at, to) { transferShape: function (at, to) {
const shape = this.enableEdit().deleteShapeAt(at) const shape = this.enableEdit().deleteShapeAt(at)
this.disableEdit() this.disableEdit()
if (!shape) return if (!shape) {
return
}
to.enableEdit().appendShape(shape) to.enableEdit().appendShape(shape)
if (!this._latlngs.length || !this._latlngs[0].length) this.del() if (!this._latlngs.length || !this._latlngs[0].length) {
this.del()
}
}, },
isolateShape: function (at) { isolateShape: function (at) {
if (!this.isMulti()) return if (!this.isMulti()) {
return
}
const shape = this.enableEdit().deleteShapeAt(at) const shape = this.enableEdit().deleteShapeAt(at)
this.disableEdit() this.disableEdit()
if (!shape) return if (!shape) {
return
}
const properties = this.cloneProperties() const properties = this.cloneProperties()
const other = new (this instanceof L.U.Polyline ? L.U.Polyline : L.U.Polygon)( const other = new (this instanceof L.U.Polyline ? L.U.Polyline : L.U.Polygon)(
this.map, this.map,
@ -1055,14 +1124,20 @@ L.U.Polyline = L.Polyline.extend({
}, },
mergeShapes: function () { mergeShapes: function () {
if (!this.isMulti()) return if (!this.isMulti()) {
return
}
const latlngs = this.getLatLngs() const latlngs = this.getLatLngs()
if (!latlngs.length) return if (!latlngs.length) {
return
}
while (latlngs.length > 1) { while (latlngs.length > 1) {
latlngs.splice(0, 2, this._mergeShapes(latlngs[1], latlngs[0])) latlngs.splice(0, 2, this._mergeShapes(latlngs[1], latlngs[0]))
} }
this.setLatLngs(latlngs[0]) this.setLatLngs(latlngs[0])
if (!this.editEnabled()) this.edit() if (!this.editEnabled()) {
this.edit()
}
this.editor.reset() this.editor.reset()
this.isDirty = true this.isDirty = true
}, },
@ -1074,9 +1149,11 @@ L.U.Polyline = L.Polyline.extend({
getVertexActions: function (e) { getVertexActions: function (e) {
const actions = L.U.FeatureMixin.getVertexActions.call(this, e), const actions = L.U.FeatureMixin.getVertexActions.call(this, e),
index = e.vertex.getIndex() index = e.vertex.getIndex()
if (index === 0 || index === e.vertex.getLastIndex()) if (index === 0 || index === e.vertex.getLastIndex()) {
actions.push(L.U.ContinueLineAction) actions.push(L.U.ContinueLineAction)
else actions.push(L.U.SplitLineAction) } else {
actions.push(L.U.SplitLineAction)
}
return actions return actions
}, },
}) })

View file

@ -16,22 +16,30 @@ L.U.Icon = L.DivIcon.extend({
_getIconUrl: function (name) { _getIconUrl: function (name) {
let url let url
if (this.feature && this.feature._getIconUrl(name)) if (this.feature && this.feature._getIconUrl(name)) {
url = this.feature._getIconUrl(name) url = this.feature._getIconUrl(name)
else url = this.options[`${name}Url`] } else {
url = this.options[`${name}Url`]
}
return this.formatUrl(url, this.feature) return this.formatUrl(url, this.feature)
}, },
_getColor: function () { _getColor: function () {
let color let color
if (this.feature) color = this.feature.getDynamicOption('color') if (this.feature) {
else if (this.options.color) color = this.options.color color = this.feature.getDynamicOption('color')
else color = this.map.getDefaultOption('color') } else if (this.options.color) {
color = this.options.color
} else {
color = this.map.getDefaultOption('color')
}
return color return color
}, },
_getOpacity: function () { _getOpacity: function () {
if (this.feature) return this.feature.getOption('iconOpacity') if (this.feature) {
return this.feature.getOption('iconOpacity')
}
return this.map.getDefaultOption('iconOpacity') return this.map.getDefaultOption('iconOpacity')
}, },

View file

@ -67,11 +67,15 @@ L.U.Map.include({
initialize: function (el, geojson) { initialize: function (el, geojson) {
// Locale name (pt_PT, en_US…) // Locale name (pt_PT, en_US…)
// To be used for Django localization // To be used for Django localization
if (geojson.properties.locale) L.setLocale(geojson.properties.locale) if (geojson.properties.locale) {
L.setLocale(geojson.properties.locale)
}
// Language code (pt-pt, en-us…) // Language code (pt-pt, en-us…)
// To be used in javascript APIs // To be used in javascript APIs
if (geojson.properties.lang) L.lang = geojson.properties.lang if (geojson.properties.lang) {
L.lang = geojson.properties.lang
}
// Don't let default autocreation of controls // Don't let default autocreation of controls
const zoomControl = const zoomControl =
@ -89,7 +93,9 @@ L.U.Map.include({
L.Map.prototype.initialize.call(this, el, geojson.properties) L.Map.prototype.initialize.call(this, el, geojson.properties)
// After calling parent initialize, as we are doing initCenter our-selves // After calling parent initialize, as we are doing initCenter our-selves
if (geojson.geometry) this.options.center = this.latLng(geojson.geometry) if (geojson.geometry) {
this.options.center = this.latLng(geojson.geometry)
}
this.ui = new L.U.UI(this._container) this.ui = new L.U.UI(this._container)
this.xhr = new L.U.Xhr(this.ui) this.xhr = new L.U.Xhr(this.ui)
@ -121,10 +127,13 @@ L.U.Map.include({
'onLoadPanel', 'onLoadPanel',
this.options.onLoadPanel this.options.onLoadPanel
) )
if (this.datalayersOnLoad) if (this.datalayersOnLoad) {
this.datalayersOnLoad = this.datalayersOnLoad.toString().split(',') this.datalayersOnLoad = this.datalayersOnLoad.toString().split(',')
}
if (L.Browser.ielt9) this.options.editMode = 'disabled' // TODO include ie9 if (L.Browser.ielt9) {
this.options.editMode = 'disabled'
} // TODO include ie9
let editedFeature = null let editedFeature = null
const self = this const self = this
@ -150,10 +159,12 @@ L.U.Map.include({
this.options.slideshow && this.options.slideshow &&
this.options.slideshow.delay && this.options.slideshow.delay &&
this.options.slideshow.active === undefined this.options.slideshow.active === undefined
) ) {
this.options.slideshow.active = true this.options.slideshow.active = true
if (this.options.advancedFilterKey) }
if (this.options.advancedFilterKey) {
this.options.facetKey = this.options.advancedFilterKey this.options.facetKey = this.options.advancedFilterKey
}
// Global storage for retrieving datalayers and features // Global storage for retrieving datalayers and features
this.datalayers = {} this.datalayers = {}
@ -162,7 +173,9 @@ L.U.Map.include({
this.features_index = {} this.features_index = {}
this.facets = {} this.facets = {}
if (this.options.hash) this.addHash() if (this.options.hash) {
this.addHash()
}
this.initTileLayers(this.options.tilelayers) this.initTileLayers(this.options.tilelayers)
// Needs tilelayer to exist for minimap // Needs tilelayer to exist for minimap
this.initControls() this.initControls()
@ -211,7 +224,9 @@ L.U.Map.include({
this.on( this.on(
'baselayerchange', 'baselayerchange',
function (e) { function (e) {
if (this._controls.miniMap) this._controls.miniMap.onMainMapBaseLayerChange(e) if (this._controls.miniMap) {
this._controls.miniMap.onMainMapBaseLayerChange(e)
}
}, },
this this
) )
@ -252,20 +267,30 @@ L.U.Map.include({
} }
this.initShortcuts() this.initShortcuts()
this.onceDatalayersLoaded(function () { this.onceDatalayersLoaded(function () {
if (L.Util.queryString('share')) this.renderShareBox() if (L.Util.queryString('share')) {
else if (this.options.onLoadPanel === 'databrowser') this.openBrowser() this.renderShareBox()
else if (this.options.onLoadPanel === 'caption') this.displayCaption() } else if (this.options.onLoadPanel === 'databrowser') {
else if ( this.openBrowser()
} else if (this.options.onLoadPanel === 'caption') {
this.displayCaption()
} else if (
this.options.onLoadPanel === 'facet' || this.options.onLoadPanel === 'facet' ||
this.options.onLoadPanel === 'datafilters' this.options.onLoadPanel === 'datafilters'
) ) {
this.openFacet() this.openFacet()
}
}) })
this.onceDataLoaded(function () { this.onceDataLoaded(function () {
const slug = L.Util.queryString('feature') const slug = L.Util.queryString('feature')
if (slug && this.features_index[slug]) this.features_index[slug].view() if (slug && this.features_index[slug]) {
if (L.Util.queryString('edit')) this.enableEdit() this.features_index[slug].view()
if (L.Util.queryString('download')) this.download() }
if (L.Util.queryString('edit')) {
this.enableEdit()
}
if (L.Util.queryString('download')) {
this.download()
}
}) })
window.onbeforeunload = () => this.isDirty || null window.onbeforeunload = () => this.isDirty || null
@ -330,8 +355,11 @@ L.U.Map.include({
this._controls.more = new L.U.MoreControls() this._controls.more = new L.U.MoreControls()
this._controls.scale = L.control.scale() this._controls.scale = L.control.scale()
this._controls.permanentCredit = new L.U.PermanentCreditsControl(this) this._controls.permanentCredit = new L.U.PermanentCreditsControl(this)
if (this.options.scrollWheelZoom) this.scrollWheelZoom.enable() if (this.options.scrollWheelZoom) {
else this.scrollWheelZoom.disable() this.scrollWheelZoom.enable()
} else {
this.scrollWheelZoom.disable()
}
this.renderControls() this.renderControls()
}, },
@ -350,7 +378,9 @@ L.U.Map.include({
for (const i in this._controls) { for (const i in this._controls) {
this.removeControl(this._controls[i]) this.removeControl(this._controls[i])
} }
if (this.options.noControl) return if (this.options.noControl) {
return
}
this._controls.attribution = new L.U.AttributionControl().addTo(this) this._controls.attribution = new L.U.AttributionControl().addTo(this)
if (this.options.miniMap && !this.options.noControl) { if (this.options.miniMap && !this.options.noControl) {
@ -367,16 +397,26 @@ L.U.Map.include({
for (let i = 0; i < this.HIDDABLE_CONTROLS.length; i++) { for (let i = 0; i < this.HIDDABLE_CONTROLS.length; i++) {
name = this.HIDDABLE_CONTROLS[i] name = this.HIDDABLE_CONTROLS[i]
status = this.options[`${name}Control`] status = this.options[`${name}Control`]
if (status === false) continue if (status === false) {
continue
}
control = this._controls[name] control = this._controls[name]
control.addTo(this) control.addTo(this)
if (status === undefined || status === null) if (status === undefined || status === null) {
L.DomUtil.addClass(control._container, 'display-on-more') L.DomUtil.addClass(control._container, 'display-on-more')
else L.DomUtil.removeClass(control._container, 'display-on-more') } else {
L.DomUtil.removeClass(control._container, 'display-on-more')
}
}
if (this.options.permanentCredit) {
this._controls.permanentCredit.addTo(this)
}
if (this.options.moreControl) {
this._controls.more.addTo(this)
}
if (this.options.scaleControl) {
this._controls.scale.addTo(this)
} }
if (this.options.permanentCredit) this._controls.permanentCredit.addTo(this)
if (this.options.moreControl) this._controls.more.addTo(this)
if (this.options.scaleControl) this._controls.scale.addTo(this)
}, },
initDatalayers: function () { initDatalayers: function () {
@ -396,7 +436,9 @@ L.U.Map.include({
} }
const decrementToLoad = () => { const decrementToLoad = () => {
toload-- toload--
if (toload === 0) loaded() if (toload === 0) {
loaded()
}
} }
const dataLoaded = () => { const dataLoaded = () => {
this.dataLoaded = true this.dataLoaded = true
@ -404,7 +446,9 @@ L.U.Map.include({
} }
const decrementDataToLoad = () => { const decrementDataToLoad = () => {
dataToload-- dataToload--
if (dataToload === 0) dataLoaded() if (dataToload === 0) {
dataLoaded()
}
} }
this.eachDataLayer(function (datalayer) { this.eachDataLayer(function (datalayer) {
if (force && !datalayer.hasDataLoaded()) { if (force && !datalayer.hasDataLoaded()) {
@ -434,7 +478,9 @@ L.U.Map.include({
this.datalayers_index = [] this.datalayers_index = []
for (let i = 0; i < panes.children.length; i++) { for (let i = 0; i < panes.children.length; i++) {
pane = panes.children[i] pane = panes.children[i]
if (!pane.dataset || !pane.dataset.id) continue if (!pane.dataset || !pane.dataset.id) {
continue
}
this.datalayers_index.push(this.datalayers[pane.dataset.id]) this.datalayers_index.push(this.datalayers[pane.dataset.id])
} }
this.updateDatalayersControl() this.updateDatalayersControl()
@ -467,7 +513,9 @@ L.U.Map.include({
}, },
updateDatalayersControl: function () { updateDatalayersControl: function () {
if (this._controls.datalayers) this._controls.datalayers.update() if (this._controls.datalayers) {
this._controls.datalayers.update()
}
}, },
backupOptions: function () { backupOptions: function () {
@ -493,11 +541,16 @@ L.U.Map.include({
L.DomEvent.stop(e) L.DomEvent.stop(e)
this.search() this.search()
} else if (e.keyCode === L.U.Keys.ESC) { } else if (e.keyCode === L.U.Keys.ESC) {
if (this.help.visible()) this.help.hide() if (this.help.visible()) {
else this.ui.closePanel() this.help.hide()
} else {
this.ui.closePanel()
}
} }
if (!this.hasEditMode()) return if (!this.hasEditMode()) {
return
}
/* Edit mode only shortcuts */ /* Edit mode only shortcuts */
if (key === L.U.Keys.E && modifierKey && !this.editEnabled) { if (key === L.U.Keys.E && modifierKey && !this.editEnabled) {
@ -544,8 +597,12 @@ L.U.Map.include({
this.help.show('edit') this.help.show('edit')
} }
if (e.keyCode === L.U.Keys.ESC) { if (e.keyCode === L.U.Keys.ESC) {
if (this.editEnabled) this.editTools.stopDrawing() if (this.editEnabled) {
if (this.measureTools.enabled()) this.measureTools.stopDrawing() this.editTools.stopDrawing()
}
if (this.measureTools.enabled()) {
this.measureTools.stopDrawing()
}
} }
} }
L.DomEvent.addListener(document, 'keydown', globalShortcuts, this) L.DomEvent.addListener(document, 'keydown', globalShortcuts, this)
@ -635,11 +692,15 @@ L.U.Map.include({
}, },
setOverlay: function () { setOverlay: function () {
if (!this.options.overlay || !this.options.overlay.url_template) return if (!this.options.overlay || !this.options.overlay.url_template) {
return
}
const overlay = this.createTileLayer(this.options.overlay) const overlay = this.createTileLayer(this.options.overlay)
try { try {
this.addLayer(overlay) this.addLayer(overlay)
if (this.overlay) this.removeLayer(this.overlay) if (this.overlay) {
this.removeLayer(this.overlay)
}
this.overlay = overlay this.overlay = overlay
} catch (e) { } catch (e) {
this.removeLayer(overlay) this.removeLayer(overlay)
@ -658,7 +719,9 @@ L.U.Map.include({
hasData: function () { hasData: function () {
for (const datalayer of this.datalayers_index) { for (const datalayer of this.datalayers_index) {
if (datalayer.hasData()) return true if (datalayer.hasData()) {
return true
}
} }
}, },
@ -685,7 +748,9 @@ L.U.Map.include({
} }
const datalayer = this.defaultDataLayer(), const datalayer = this.defaultDataLayer(),
feature = datalayer.getFeatureByIndex(-1) feature = datalayer.getFeatureByIndex(-1)
if (feature) feature.zoomTo() if (feature) {
feature.zoomTo()
}
}) })
} else { } else {
this._setDefaultCenter() this._setDefaultCenter()
@ -748,7 +813,9 @@ L.U.Map.include({
}, },
getOption: function (option) { getOption: function (option) {
if (L.Util.usableOption(this.options, option)) return this.options[option] if (L.Util.usableOption(this.options, option)) {
return this.options[option]
}
return this.getDefaultOption(option) return this.getDefaultOption(option)
}, },
@ -773,12 +840,15 @@ L.U.Map.include({
self.options.tilelayer = tilelayer.toJSON() self.options.tilelayer = tilelayer.toJSON()
self.isDirty = true self.isDirty = true
} }
if (this._controls.tilelayers) if (this._controls.tilelayers) {
this._controls.tilelayers.openSwitcher({ callback: callback, className: 'dark' }) this._controls.tilelayers.openSwitcher({ callback: callback, className: 'dark' })
}
}, },
manageDatalayers: function () { manageDatalayers: function () {
if (this._controls.datalayers) this._controls.datalayers.openPanel() if (this._controls.datalayers) {
this._controls.datalayers.openPanel()
}
}, },
toGeoJSON: function () { toGeoJSON: function () {
@ -874,8 +944,12 @@ L.U.Map.include({
this.setView(this.latLng(this.options.center), this.options.zoom) this.setView(this.latLng(this.options.center), this.options.zoom)
}) })
} }
if (layerId) layer = map.datalayers[layerId] if (layerId) {
if (layer && clearFlag.checked) layer.empty() layer = map.datalayers[layerId]
}
if (layer && clearFlag.checked) {
layer.empty()
}
if (fileInput.files.length) { if (fileInput.files.length) {
let file let file
for (let i = 0, file; (file = fileInput.files[i]); i++) { for (let i = 0, file; (file = fileInput.files[i]); i++) {
@ -893,16 +967,19 @@ L.U.Map.include({
this.importFromFile(file, 'umap') this.importFromFile(file, 'umap')
} else { } else {
let importLayer = layer let importLayer = layer
if (!layer) importLayer = this.createDataLayer({ name: file.name }) if (!layer) {
importLayer = this.createDataLayer({ name: file.name })
}
importLayer.importFromFile(file, type) importLayer.importFromFile(file, type)
} }
} }
} else { } else {
if (!type) if (!type) {
return this.ui.alert({ return this.ui.alert({
content: L._('Please choose a format'), content: L._('Please choose a format'),
level: 'error', level: 'error',
}) })
}
if (rawInput.value && type === 'umap') { if (rawInput.value && type === 'umap') {
try { try {
this.importRaw(rawInput.value, type) this.importRaw(rawInput.value, type)
@ -911,11 +988,16 @@ L.U.Map.include({
console.error(e) console.error(e)
} }
} else { } else {
if (!layer) layer = this.createDataLayer() if (!layer) {
if (rawInput.value) layer.importRaw(rawInput.value, type) layer = this.createDataLayer()
else if (urlInput.value) layer.importFromUrl(urlInput.value, type) }
else if (presetSelect.selectedIndex > 0) if (rawInput.value) {
layer.importRaw(rawInput.value, type)
} else if (urlInput.value) {
layer.importFromUrl(urlInput.value, type)
} else if (presetSelect.selectedIndex > 0) {
layer.importFromUrl(presetSelect[presetSelect.selectedIndex].value, type) layer.importFromUrl(presetSelect[presetSelect.selectedIndex].value, type)
}
} }
} }
} }
@ -928,7 +1010,9 @@ L.U.Map.include({
newType newType
for (let i = 0; i < e.target.files.length; i++) { for (let i = 0; i < e.target.files.length; i++) {
newType = L.Util.detectFileType(e.target.files[i]) newType = L.Util.detectFileType(e.target.files[i])
if (!type && newType) type = newType if (!type && newType) {
type = newType
}
if (type && newType !== type) { if (type && newType !== type) {
type = '' type = ''
break break
@ -950,11 +1034,15 @@ L.U.Map.include({
const option = this.editableOptions[i] const option = this.editableOptions[i]
if (typeof importedData.properties[option] !== 'undefined') { if (typeof importedData.properties[option] !== 'undefined') {
this.options[option] = importedData.properties[option] this.options[option] = importedData.properties[option]
if (option === 'sortKey') mustReindex = true if (option === 'sortKey') {
mustReindex = true
}
} }
} }
if (importedData.geometry) this.options.center = this.latLng(importedData.geometry) if (importedData.geometry) {
this.options.center = this.latLng(importedData.geometry)
}
const self = this const self = this
importedData.layers.forEach((geojson) => { importedData.layers.forEach((geojson) => {
delete geojson._umap_options['id'] // Never trust an id at this stage delete geojson._umap_options['id'] // Never trust an id at this stage
@ -966,7 +1054,9 @@ L.U.Map.include({
this.renderControls() this.renderControls()
this.handleLimitBounds() this.handleLimitBounds()
this.eachDataLayer((datalayer) => { this.eachDataLayer((datalayer) => {
if (mustReindex) datalayer.reindex() if (mustReindex) {
datalayer.reindex()
}
datalayer.redraw() datalayer.redraw()
}) })
this.fire('postsync') this.fire('postsync')
@ -1011,7 +1101,9 @@ L.U.Map.include({
eachDataLayerReverse: function (method, context, filter) { eachDataLayerReverse: function (method, context, filter) {
for (let i = this.datalayers_index.length - 1; i >= 0; i--) { for (let i = this.datalayers_index.length - 1; i >= 0; i--) {
if (filter && !filter.call(context, this.datalayers_index[i])) continue if (filter && !filter.call(context, this.datalayers_index[i])) {
continue
}
method.call(context, this.datalayers_index[i]) method.call(context, this.datalayers_index[i])
} }
}, },
@ -1026,8 +1118,9 @@ L.U.Map.include({
findDataLayer: function (method, context) { findDataLayer: function (method, context) {
for (let i = this.datalayers_index.length - 1; i >= 0; i--) { for (let i = this.datalayers_index.length - 1; i >= 0; i--) {
if (method.call(context, this.datalayers_index[i])) if (method.call(context, this.datalayers_index[i])) {
return this.datalayers_index[i] return this.datalayers_index[i]
}
} }
}, },
@ -1037,11 +1130,15 @@ L.U.Map.include({
}, },
reset: function () { reset: function () {
if (this.editTools) this.editTools.stopDrawing() if (this.editTools) {
this.editTools.stopDrawing()
}
this.resetOptions() this.resetOptions()
this.datalayers_index = [].concat(this._datalayers_index_bk) this.datalayers_index = [].concat(this._datalayers_index_bk)
this.dirty_datalayers.slice().forEach((datalayer) => { this.dirty_datalayers.slice().forEach((datalayer) => {
if (datalayer.isDeleted) datalayer.connectToMap() if (datalayer.isDeleted) {
datalayer.connectToMap()
}
datalayer.reset() datalayer.reset()
}) })
this.ensurePanesOrder() this.ensurePanesOrder()
@ -1070,8 +1167,11 @@ L.U.Map.include({
}, },
continueSaving: function () { continueSaving: function () {
if (this.dirty_datalayers.length) this.dirty_datalayers[0].save() if (this.dirty_datalayers.length) {
else this.fire('saved') this.dirty_datalayers[0].save()
} else {
this.fire('saved')
}
}, },
editableOptions: [ editableOptions: [
@ -1221,9 +1321,11 @@ L.U.Map.include({
this.permissions.commit() this.permissions.commit()
} }
// Update URL in case the name has changed. // Update URL in case the name has changed.
if (history && history.pushState) if (history && history.pushState) {
history.pushState({}, this.options.name, data.url) history.pushState({}, this.options.name, data.url)
else window.location = data.url } else {
window.location = data.url
}
alert.content = data.info || alert.content alert.content = data.info || alert.content
this.once('saved', () => this.ui.alert(alert)) this.once('saved', () => this.ui.alert(alert))
this.ui.closePanel() this.ui.closePanel()
@ -1233,8 +1335,12 @@ L.U.Map.include({
}, },
save: function () { save: function () {
if (!this.isDirty) return if (!this.isDirty) {
if (this._default_extent) this.updateExtent() return
}
if (this._default_extent) {
this.updateExtent()
}
this.backup() this.backup()
this.once('saved', () => { this.once('saved', () => {
this.isDirty = false this.isDirty = false
@ -1276,11 +1382,12 @@ L.U.Map.include({
}, },
star: function () { star: function () {
if (!this.options.umap_id) if (!this.options.umap_id) {
return this.ui.alert({ return this.ui.alert({
content: L._('Please save the map first'), content: L._('Please save the map first'),
level: 'error', level: 'error',
}) })
}
let url = L.Util.template(this.options.urls.map_star, { let url = L.Util.template(this.options.urls.map_star, {
map_id: this.options.umap_id, map_id: this.options.umap_id,
}) })
@ -1323,10 +1430,14 @@ L.U.Map.include({
datalayer = this.findDataLayer((datalayer) => { datalayer = this.findDataLayer((datalayer) => {
if (!datalayer.isDataReadOnly() && datalayer.canBrowse()) { if (!datalayer.isDataReadOnly() && datalayer.canBrowse()) {
fallback = datalayer fallback = datalayer
if (datalayer.isVisible()) return true if (datalayer.isVisible()) {
return true
}
} }
}) })
if (datalayer) return datalayer if (datalayer) {
return datalayer
}
if (fallback) { if (fallback) {
// No datalayer visible, let's force one // No datalayer visible, let's force one
this.addLayer(fallback.layer) this.addLayer(fallback.layer)
@ -1447,7 +1558,9 @@ L.U.Map.include({
callback: function (e) { callback: function (e) {
this.initCaptionBar() this.initCaptionBar()
this.eachDataLayer((datalayer) => { this.eachDataLayer((datalayer) => {
if (e.helper.field === 'options.sortKey') datalayer.reindex() if (e.helper.field === 'options.sortKey') {
datalayer.reindex()
}
datalayer.redraw() datalayer.redraw()
}) })
}, },
@ -1475,8 +1588,9 @@ L.U.Map.include({
e.helper.field === 'options.popupTemplate' || e.helper.field === 'options.popupTemplate' ||
e.helper.field === 'options.popupContentTemplate' || e.helper.field === 'options.popupContentTemplate' ||
e.helper.field === 'options.popupShape' e.helper.field === 'options.popupShape'
) ) {
return return
}
this.eachDataLayer((datalayer) => { this.eachDataLayer((datalayer) => {
datalayer.redraw() datalayer.redraw()
}) })
@ -1774,8 +1888,12 @@ L.U.Map.include({
}, },
edit: function () { edit: function () {
if (!this.editEnabled) return if (!this.editEnabled) {
if (this.options.editMode !== 'advanced') return return
}
if (this.options.editMode !== 'advanced') {
return
}
const container = L.DomUtil.create('div', 'umap-edit-container'), const container = L.DomUtil.create('div', 'umap-edit-container'),
metadataFields = ['options.name', 'options.description'], metadataFields = ['options.name', 'options.description'],
title = L.DomUtil.create('h3', '', container) title = L.DomUtil.create('h3', '', container)
@ -1804,7 +1922,9 @@ L.U.Map.include({
}, },
disableEdit: function () { disableEdit: function () {
if (this.isDirty) return if (this.isDirty) {
return
}
L.DomUtil.removeClass(document.body, 'umap-edit-enabled') L.DomUtil.removeClass(document.body, 'umap-edit-enabled')
this.editedFeature = null this.editedFeature = null
this.editEnabled = false this.editEnabled = false
@ -1877,7 +1997,9 @@ L.U.Map.include({
}, },
askForReset: function (e) { askForReset: function (e) {
if (!confirm(L._('Are you sure you want to cancel your changes?'))) return if (!confirm(L._('Are you sure you want to cancel your changes?'))) {
return
}
this.reset() this.reset()
this.disableEdit(e) this.disableEdit(e)
this.ui.closePanel() this.ui.closePanel()
@ -2096,11 +2218,15 @@ L.U.Map.include({
closeInplaceToolbar: function () { closeInplaceToolbar: function () {
const toolbar = this._toolbars[L.Toolbar.Popup._toolbar_class_id] const toolbar = this._toolbars[L.Toolbar.Popup._toolbar_class_id]
if (toolbar) toolbar.remove() if (toolbar) {
toolbar.remove()
}
}, },
search: function () { search: function () {
if (this._controls.search) this._controls.search.openPanel(this) if (this._controls.search) {
this._controls.search.openPanel(this)
}
}, },
getFilterKeys: function () { getFilterKeys: function () {
@ -2118,7 +2244,9 @@ L.U.Map.include({
getLayersBounds: function () { getLayersBounds: function () {
const bounds = new L.latLngBounds() const bounds = new L.latLngBounds()
this.eachBrowsableDataLayer((d) => { this.eachBrowsableDataLayer((d) => {
if (d.isVisible()) bounds.extend(d.layer.getBounds()) if (d.isVisible()) {
bounds.extend(d.layer.getBounds())
}
}) })
return bounds return bounds
}, },

View file

@ -141,7 +141,9 @@ L.U.Layer.Heat = L.HeatLayer.extend({
// setlalngs call _redraw through setAnimFrame, thus async, so this // setlalngs call _redraw through setAnimFrame, thus async, so this
// can ends with race condition if we remove the layer very faslty after. // can ends with race condition if we remove the layer very faslty after.
// Remove me when https://github.com/Leaflet/Leaflet.heat/pull/53 is released. // Remove me when https://github.com/Leaflet/Leaflet.heat/pull/53 is released.
if (!this._map) return if (!this._map) {
return
}
L.HeatLayer.prototype.redraw.call(this) L.HeatLayer.prototype.redraw.call(this)
}, },
@ -219,13 +221,17 @@ L.U.DataLayer = L.Evented.extend({
return isDirty return isDirty
}, },
set: function (status) { set: function (status) {
if (!isDirty && status) self.fire('dirty') if (!isDirty && status) {
self.fire('dirty')
}
isDirty = status isDirty = status
if (status) { if (status) {
self.map.addDirtyDatalayer(self) self.map.addDirtyDatalayer(self)
// A layer can be made dirty by indirect action (like dragging layers) // A layer can be made dirty by indirect action (like dragging layers)
// we need to have it loaded before saving it. // we need to have it loaded before saving it.
if (!self.isLoaded()) self.fetchData() if (!self.isLoaded()) {
self.fetchData()
}
} else { } else {
self.map.removeDirtyDatalayer(self) self.map.removeDirtyDatalayer(self)
self.isDeleted = false self.isDeleted = false
@ -241,9 +247,13 @@ L.U.DataLayer = L.Evented.extend({
return isDeleted return isDeleted
}, },
set: function (status) { set: function (status) {
if (!isDeleted && status) self.fire('deleted') if (!isDeleted && status) {
self.fire('deleted')
}
isDeleted = status isDeleted = status
if (status) self.isDirty = status if (status) {
self.isDirty = status
}
}, },
}) })
} catch (e) { } catch (e) {
@ -263,8 +273,12 @@ L.U.DataLayer = L.Evented.extend({
this.backupOptions() this.backupOptions()
this.connectToMap() this.connectToMap()
this.permissions = new L.U.DataLayerPermissions(this) this.permissions = new L.U.DataLayerPermissions(this)
if (this.showAtLoad()) this.show() if (this.showAtLoad()) {
if (!this.umap_id) this.isDirty = true this.show()
}
if (!this.umap_id) {
this.isDirty = true
}
this.onceLoaded(function () { this.onceLoaded(function () {
this.map.on('moveend', this.onMoveEnd, this) this.map.on('moveend', this.onMoveEnd, this)
@ -272,17 +286,27 @@ L.U.DataLayer = L.Evented.extend({
// Only layers that are displayed on load must be hidden/shown // Only layers that are displayed on load must be hidden/shown
// Automatically, others will be shown manually, and thus will // Automatically, others will be shown manually, and thus will
// be in the "forced visibility" mode // be in the "forced visibility" mode
if (this.autoLoaded()) this.map.on('zoomend', this.onZoomEnd, this) if (this.autoLoaded()) {
this.map.on('zoomend', this.onZoomEnd, this)
}
}, },
onMoveEnd: function (e) { onMoveEnd: function (e) {
if (this.isRemoteLayer() && this.showAtZoom()) this.fetchRemoteData() if (this.isRemoteLayer() && this.showAtZoom()) {
this.fetchRemoteData()
}
}, },
onZoomEnd: function (e) { onZoomEnd: function (e) {
if (this._forcedVisibility) return if (this._forcedVisibility) {
if (!this.showAtZoom() && this.isVisible()) this.hide() return
if (this.showAtZoom() && !this.isVisible()) this.show() }
if (!this.showAtZoom() && this.isVisible()) {
this.hide()
}
if (this.showAtZoom() && !this.isVisible()) {
this.show()
}
}, },
showAtLoad: function () { showAtLoad: function () {
@ -299,12 +323,16 @@ L.U.DataLayer = L.Evented.extend({
}, },
insertBefore: function (other) { insertBefore: function (other) {
if (!other) return if (!other) {
return
}
this.parentPane.insertBefore(this.pane, other.pane) this.parentPane.insertBefore(this.pane, other.pane)
}, },
insertAfter: function (other) { insertAfter: function (other) {
if (!other) return if (!other) {
return
}
this.parentPane.insertBefore(this.pane, other.pane.nextSibling) this.parentPane.insertBefore(this.pane, other.pane.nextSibling)
}, },
@ -318,15 +346,27 @@ L.U.DataLayer = L.Evented.extend({
resetLayer: function (force) { resetLayer: function (force) {
// Only reset if type is defined (undefined is the default) and different from current type // Only reset if type is defined (undefined is the default) and different from current type
if (this.layer && (!this.options.type || this.options.type === this.layer._type) && !force) return if (
this.layer &&
(!this.options.type || this.options.type === this.layer._type) &&
!force
) {
return
}
const visible = this.isVisible() const visible = this.isVisible()
if (this.layer) this.layer.clearLayers() if (this.layer) {
this.layer.clearLayers()
}
// delete this.layer? // delete this.layer?
if (visible) this.map.removeLayer(this.layer) if (visible) {
this.map.removeLayer(this.layer)
}
const Class = L.U.Layer[this.options.type] || L.U.Layer.Default const Class = L.U.Layer[this.options.type] || L.U.Layer.Default
this.layer = new Class(this) this.layer = new Class(this)
this.eachLayer((feature) => this.showFeature(feature)) this.eachLayer((feature) => this.showFeature(feature))
if (visible) this.show() if (visible) {
this.show()
}
this.propagateRemote() this.propagateRemote()
}, },
@ -347,8 +387,12 @@ L.U.DataLayer = L.Evented.extend({
}, },
fetchData: function () { fetchData: function () {
if (!this.umap_id) return if (!this.umap_id) {
if (this._loading) return return
}
if (this._loading) {
return
}
this._loading = true this._loading = true
this.map.get(this._dataUrl(), { this.map.get(this._dataUrl(), {
callback: function (geojson, response) { callback: function (geojson, response) {
@ -358,9 +402,13 @@ L.U.DataLayer = L.Evented.extend({
// So do not let all options to be reset // So do not let all options to be reset
// Fix is a proper migration so all datalayers settings are // Fix is a proper migration so all datalayers settings are
// in DB, and we remove it from geojson flat files. // in DB, and we remove it from geojson flat files.
if (geojson._umap_options) geojson._umap_options.editMode = this.options.editMode if (geojson._umap_options) {
geojson._umap_options.editMode = this.options.editMode
}
// In case of maps pre 1.0 still around // In case of maps pre 1.0 still around
if (geojson._storage) geojson._storage.editMode = this.options.editMode if (geojson._storage) {
geojson._storage.editMode = this.options.editMode
}
this.fromUmapGeoJSON(geojson) this.fromUmapGeoJSON(geojson)
this.backupOptions() this.backupOptions()
this.fire('loaded') this.fire('loaded')
@ -379,10 +427,17 @@ L.U.DataLayer = L.Evented.extend({
}, },
fromUmapGeoJSON: function (geojson) { fromUmapGeoJSON: function (geojson) {
if (geojson._storage) geojson._umap_options = geojson._storage // Retrocompat if (geojson._storage) {
if (geojson._umap_options) this.setOptions(geojson._umap_options) geojson._umap_options = geojson._storage
if (this.isRemoteLayer()) this.fetchRemoteData() } // Retrocompat
else this.fromGeoJSON(geojson) if (geojson._umap_options) {
this.setOptions(geojson._umap_options)
}
if (this.isRemoteLayer()) {
this.fetchRemoteData()
} else {
this.fromGeoJSON(geojson)
}
this._loaded = true this._loaded = true
}, },
@ -419,12 +474,19 @@ L.U.DataLayer = L.Evented.extend({
}, },
fetchRemoteData: function (force) { fetchRemoteData: function (force) {
if (!this.isRemoteLayer()) return if (!this.isRemoteLayer()) {
if (!this.options.remoteData.dynamic && this.hasDataLoaded() && !force) return return
if (!this.isVisible()) return }
if (!this.options.remoteData.dynamic && this.hasDataLoaded() && !force) {
return
}
if (!this.isVisible()) {
return
}
let url = this.map.localizeUrl(this.options.remoteData.url) let url = this.map.localizeUrl(this.options.remoteData.url)
if (this.options.remoteData.proxy) if (this.options.remoteData.proxy) {
url = this.map.proxyUrl(url, this.options.remoteData.ttl) url = this.map.proxyUrl(url, this.options.remoteData.ttl)
}
this.map.ajax({ this.map.ajax({
uri: url, uri: url,
verb: 'GET', verb: 'GET',
@ -439,14 +501,20 @@ L.U.DataLayer = L.Evented.extend({
}, },
onceLoaded: function (callback, context) { onceLoaded: function (callback, context) {
if (this.isLoaded()) callback.call(context || this, this) if (this.isLoaded()) {
else this.once('loaded', callback, context) callback.call(context || this, this)
} else {
this.once('loaded', callback, context)
}
return this return this
}, },
onceDataLoaded: function (callback, context) { onceDataLoaded: function (callback, context) {
if (this.hasDataLoaded()) callback.call(context || this, this) if (this.hasDataLoaded()) {
else this.once('dataloaded', callback, context) callback.call(context || this, this)
} else {
this.once('dataloaded', callback, context)
}
return this return this
}, },
@ -460,7 +528,9 @@ L.U.DataLayer = L.Evented.extend({
setUmapId: function (id) { setUmapId: function (id) {
// Datalayer is null when listening creation form // Datalayer is null when listening creation form
if (!this.umap_id && id) this.umap_id = id if (!this.umap_id && id) {
this.umap_id = id
}
}, },
backupOptions: function () { backupOptions: function () {
@ -485,8 +555,9 @@ L.U.DataLayer = L.Evented.extend({
const id = L.stamp(this) const id = L.stamp(this)
if (!this.map.datalayers[id]) { if (!this.map.datalayers[id]) {
this.map.datalayers[id] = this this.map.datalayers[id] = this
if (L.Util.indexOf(this.map.datalayers_index, this) === -1) if (L.Util.indexOf(this.map.datalayers_index, this) === -1) {
this.map.datalayers_index.push(this) this.map.datalayers_index.push(this)
}
} }
this.map.updateDatalayersControl() this.map.updateDatalayersControl()
}, },
@ -500,7 +571,9 @@ L.U.DataLayer = L.Evented.extend({
}) })
// No browser cache for owners/editors. // No browser cache for owners/editors.
if (this.map.hasEditMode()) url = `${url}?${Date.now()}` if (this.map.hasEditMode()) {
url = `${url}?${Date.now()}`
}
return url return url
}, },
@ -519,8 +592,12 @@ L.U.DataLayer = L.Evented.extend({
showFeature: function (feature) { showFeature: function (feature) {
const filterKeys = this.map.getFilterKeys(), const filterKeys = this.map.getFilterKeys(),
filter = this.map.options.filter filter = this.map.options.filter
if (filter && !feature.matchFilter(filter, filterKeys)) return if (filter && !feature.matchFilter(filter, filterKeys)) {
if (!feature.matchFacets()) return return
}
if (!feature.matchFacets()) {
return
}
this.layer.addLayer(feature) this.layer.addLayer(feature)
}, },
@ -532,7 +609,9 @@ L.U.DataLayer = L.Evented.extend({
this.indexProperties(feature) this.indexProperties(feature)
this.map.features_index[feature.getSlug()] = feature this.map.features_index[feature.getSlug()] = feature
this.showFeature(feature) this.showFeature(feature)
if (this.hasDataLoaded()) this.fire('datachanged') if (this.hasDataLoaded()) {
this.fire('datachanged')
}
}, },
removeLayer: function (feature) { removeLayer: function (feature) {
@ -542,24 +621,38 @@ L.U.DataLayer = L.Evented.extend({
delete this._layers[id] delete this._layers[id]
this.layer.removeLayer(feature) this.layer.removeLayer(feature)
delete this.map.features_index[feature.getSlug()] delete this.map.features_index[feature.getSlug()]
if (this.hasDataLoaded()) this.fire('datachanged') if (this.hasDataLoaded()) {
this.fire('datachanged')
}
}, },
indexProperties: function (feature) { indexProperties: function (feature) {
for (const i in feature.properties) for (const i in feature.properties) {
if (typeof feature.properties[i] !== 'object') this.indexProperty(i) if (typeof feature.properties[i] !== 'object') this.indexProperty(i)
}
if (typeof feature.properties[i] !== 'object') {
this.indexProperty(i)
}
}, },
indexProperty: function (name) { indexProperty: function (name) {
if (!name) return if (!name) {
if (name.indexOf('_') === 0) return return
if (L.Util.indexOf(this._propertiesIndex, name) !== -1) return }
if (name.indexOf('_') === 0) {
return
}
if (L.Util.indexOf(this._propertiesIndex, name) !== -1) {
return
}
this._propertiesIndex.push(name) this._propertiesIndex.push(name)
}, },
deindexProperty: function (name) { deindexProperty: function (name) {
const idx = this._propertiesIndex.indexOf(name) const idx = this._propertiesIndex.indexOf(name)
if (idx !== -1) this._propertiesIndex.splice(idx, 1) if (idx !== -1) {
this._propertiesIndex.splice(idx, 1)
}
}, },
addData: function (geojson) { addData: function (geojson) {
@ -633,7 +726,9 @@ L.U.DataLayer = L.Evented.extend({
}, },
geojsonToFeatures: function (geojson) { geojsonToFeatures: function (geojson) {
if (!geojson) return if (!geojson) {
return
}
const features = geojson instanceof Array ? geojson : geojson.features const features = geojson instanceof Array ? geojson : geojson.features
let i let i
let len let len
@ -649,7 +744,9 @@ L.U.DataLayer = L.Evented.extend({
} }
const geometry = geojson.type === 'Feature' ? geojson.geometry : geojson const geometry = geojson.type === 'Feature' ? geojson.geometry : geojson
if (!geometry) return // null geometry is valid geojson. if (!geometry) {
return
} // null geometry is valid geojson.
const coords = geometry.coordinates const coords = geometry.coordinates
let layer let layer
let tmp let tmp
@ -671,7 +768,9 @@ L.U.DataLayer = L.Evented.extend({
coords, coords,
geometry.type === 'LineString' ? 0 : 1 geometry.type === 'LineString' ? 0 : 1
) )
if (!latlngs.length) break if (!latlngs.length) {
break
}
layer = this._lineToLayer(geojson, latlngs) layer = this._lineToLayer(geojson, latlngs)
break break
@ -794,7 +893,9 @@ L.U.DataLayer = L.Evented.extend({
}, },
empty: function () { empty: function () {
if (this.isRemoteLayer()) return if (this.isRemoteLayer()) {
return
}
this.clear() this.clear()
this.isDirty = true this.isDirty = true
}, },
@ -824,7 +925,9 @@ L.U.DataLayer = L.Evented.extend({
}, },
reset: function () { reset: function () {
if (!this.umap_id) this.erase() if (!this.umap_id) {
this.erase()
}
this.resetOptions() this.resetOptions()
this.parentPane.appendChild(this.pane) this.parentPane.appendChild(this.pane)
@ -833,8 +936,11 @@ L.U.DataLayer = L.Evented.extend({
} }
this.clear() this.clear()
this.hide() this.hide()
if (this.isRemoteLayer()) this.fetchRemoteData() if (this.isRemoteLayer()) {
else if (this._geojson_bk) this.fromGeoJSON(this._geojson_bk) this.fetchRemoteData()
} else if (this._geojson_bk) {
this.fromGeoJSON(this._geojson_bk)
}
this._loaded = true this._loaded = true
this.show() this.show()
this.isDirty = false this.isDirty = false
@ -990,7 +1096,9 @@ L.U.DataLayer = L.Evented.extend({
this this
) )
if (this.map.options.urls.datalayer_versions) this.buildVersionsFieldset(container) if (this.map.options.urls.datalayer_versions) {
this.buildVersionsFieldset(container)
}
const advancedActions = L.DomUtil.createFieldset(container, L._('Advanced actions')) const advancedActions = L.DomUtil.createFieldset(container, L._('Advanced actions'))
const advancedButtons = L.DomUtil.create('div', 'button-bar half', advancedActions) const advancedButtons = L.DomUtil.create('div', 'button-bar half', advancedActions)
@ -1043,8 +1151,11 @@ L.U.DataLayer = L.Evented.extend({
}, },
getOption: function (option) { getOption: function (option) {
if (L.Util.usableOption(this.options, option)) return this.options[option] if (L.Util.usableOption(this.options, option)) {
else return this.map.getOption(option) return this.options[option]
} else {
return this.map.getOption(option)
}
}, },
buildVersionsFieldset: function (container) { buildVersionsFieldset: function (container) {
@ -1080,15 +1191,26 @@ L.U.DataLayer = L.Evented.extend({
}, },
restore: function (version) { restore: function (version) {
if (!this.map.editEnabled) return if (!this.map.editEnabled) {
if (!confirm(L._('Are you sure you want to restore this version?'))) return return
}
if (!confirm(L._('Are you sure you want to restore this version?'))) {
return
}
this.map.xhr.get(this.getVersionUrl(version), { this.map.xhr.get(this.getVersionUrl(version), {
callback: function (geojson) { callback: function (geojson) {
if (geojson._storage) geojson._umap_options = geojson._storage // Retrocompat. if (geojson._storage) {
if (geojson._umap_options) this.setOptions(geojson._umap_options) geojson._umap_options = geojson._storage
} // Retrocompat.
if (geojson._umap_options) {
this.setOptions(geojson._umap_options)
}
this.empty() this.empty()
if (this.isRemoteLayer()) this.fetchRemoteData() if (this.isRemoteLayer()) {
else this.addData(geojson) this.fetchRemoteData()
} else {
this.addData(geojson)
}
this.isDirty = true this.isDirty = true
}, },
context: this, context: this,
@ -1102,7 +1224,9 @@ L.U.DataLayer = L.Evented.extend({
}, },
show: function () { show: function () {
if (!this.isLoaded()) this.fetchData() if (!this.isLoaded()) {
this.fetchData()
}
this.map.addLayer(this.layer) this.map.addLayer(this.layer)
this.fire('show') this.fire('show')
}, },
@ -1116,14 +1240,21 @@ L.U.DataLayer = L.Evented.extend({
// From now on, do not try to how/hide // From now on, do not try to how/hide
// automatically this layer. // automatically this layer.
this._forcedVisibility = true this._forcedVisibility = true
if (!this.isVisible()) this.show() if (!this.isVisible()) {
else this.hide() this.show()
} else {
this.hide()
}
}, },
zoomTo: function () { zoomTo: function () {
if (!this.isVisible()) return if (!this.isVisible()) {
return
}
const bounds = this.layer.getBounds() const bounds = this.layer.getBounds()
if (bounds.isValid()) this.map.fitBounds(bounds) if (bounds.isValid()) {
this.map.fitBounds(bounds)
}
}, },
allowBrowse: function () { allowBrowse: function () {
@ -1143,7 +1274,9 @@ L.U.DataLayer = L.Evented.extend({
}, },
getFeatureByIndex: function (index) { getFeatureByIndex: function (index) {
if (index === -1) index = this._index.length - 1 if (index === -1) {
index = this._index.length - 1
}
const id = this._index[index] const id = this._index[index]
return this._layers[id] return this._layers[id]
}, },
@ -1170,7 +1303,9 @@ L.U.DataLayer = L.Evented.extend({
let next let next
const index = this.map.datalayers_index const index = this.map.datalayers_index
while (((id = index[++id] ? id : 0), (next = index[id]))) { while (((id = index[++id] ? id : 0), (next = index[id]))) {
if (next === this || (next.allowBrowse() && next.hasData())) break if (next === this || (next.allowBrowse() && next.hasData())) {
break
}
} }
return next return next
}, },
@ -1180,7 +1315,9 @@ L.U.DataLayer = L.Evented.extend({
let prev let prev
const index = this.map.datalayers_index const index = this.map.datalayers_index
while (((id = index[--id] ? id : index.length - 1), (prev = index[id]))) { while (((id = index[--id] ? id : index.length - 1), (prev = index[id]))) {
if (prev === this || (prev.allowBrowse() && prev.hasData())) break if (prev === this || (prev.allowBrowse() && prev.hasData())) {
break
}
} }
return prev return prev
}, },
@ -1208,7 +1345,9 @@ L.U.DataLayer = L.Evented.extend({
}, },
save: function () { save: function () {
if (this.isDeleted) return this.saveDelete() if (this.isDeleted) {
return this.saveDelete()
}
if (!this.isLoaded()) { if (!this.isLoaded()) {
return return
} }
@ -1247,7 +1386,9 @@ L.U.DataLayer = L.Evented.extend({
this.isDirty = false this.isDirty = false
this.map.continueSaving() this.map.continueSaving()
} }
if (!this.umap_id) return callback.call(this) if (!this.umap_id) {
return callback.call(this)
}
this.map.xhr.post(this.getDeleteUrl(), { this.map.xhr.post(this.getDeleteUrl(), {
callback: callback, callback: callback,
context: this, context: this,
@ -1263,7 +1404,9 @@ L.U.DataLayer = L.Evented.extend({
}, },
tableEdit: function () { tableEdit: function () {
if (this.isRemoteLayer() || !this.isVisible()) return if (this.isRemoteLayer() || !this.isVisible()) {
return
}
const editor = new L.U.TableEditor(this) const editor = new L.U.TableEditor(this)
editor.edit() editor.edit()
}, },

View file

@ -51,12 +51,15 @@ L.U.MapPermissions = L.Class.extend({
}, },
edit: function () { edit: function () {
if (this.map.options.editMode !== 'advanced') return if (this.map.options.editMode !== 'advanced') {
if (!this.map.options.umap_id) return
}
if (!this.map.options.umap_id) {
return this.map.ui.alert({ return this.map.ui.alert({
content: L._('Please save the map first'), content: L._('Please save the map first'),
level: 'info', level: 'info',
}) })
}
const container = L.DomUtil.create('div', 'permissions-panel'), const container = L.DomUtil.create('div', 'permissions-panel'),
fields = [], fields = [],
title = L.DomUtil.create('h4', '', container) title = L.DomUtil.create('h4', '', container)
@ -148,15 +151,19 @@ L.U.MapPermissions = L.Class.extend({
}, },
save: function () { save: function () {
if (!this.isDirty) return this.map.continueSaving() if (!this.isDirty) {
return this.map.continueSaving()
}
const formData = new FormData() const formData = new FormData()
if (!this.isAnonymousMap() && this.options.editors) { if (!this.isAnonymousMap() && this.options.editors) {
const editors = this.options.editors.map((u) => u.id) const editors = this.options.editors.map((u) => u.id)
for (let i = 0; i < this.options.editors.length; i++) for (let i = 0; i < this.options.editors.length; i++) {
formData.append('editors', this.options.editors[i].id) formData.append('editors', this.options.editors[i].id)
}
} }
if (this.isOwner() || this.isAnonymousMap()) if (this.isOwner() || this.isAnonymousMap()) {
formData.append('edit_status', this.options.edit_status) formData.append('edit_status', this.options.edit_status)
}
if (this.isOwner()) { if (this.isOwner()) {
formData.append('owner', this.options.owner && this.options.owner.id) formData.append('owner', this.options.owner && this.options.owner.id)
formData.append('share_status', this.options.share_status) formData.append('share_status', this.options.share_status)

View file

@ -107,7 +107,7 @@ L.U.PopupTemplate.Default = L.Class.extend({
properties properties
) )
content = L.Util.greedyTemplate(template, properties) content = L.Util.greedyTemplate(template, properties)
content = L.Util.toHTML(content, {target: target}) content = L.Util.toHTML(content, { target: target })
container.innerHTML = content container.innerHTML = content
return container return container
}, },
@ -120,20 +120,26 @@ L.U.PopupTemplate.Default = L.Class.extend({
nextLi = L.DomUtil.create('li', 'next', footer), nextLi = L.DomUtil.create('li', 'next', footer),
next = this.feature.getNext(), next = this.feature.getNext(),
prev = this.feature.getPrevious() prev = this.feature.getPrevious()
if (next) if (next) {
nextLi.title = L._('Go to «{feature}»', { nextLi.title = L._('Go to «{feature}»', {
feature: next.properties.name || L._('next'), feature: next.properties.name || L._('next'),
}) })
if (prev) }
if (prev) {
previousLi.title = L._('Go to «{feature}»', { previousLi.title = L._('Go to «{feature}»', {
feature: prev.properties.name || L._('previous'), feature: prev.properties.name || L._('previous'),
}) })
}
zoomLi.title = L._('Zoom to this feature') zoomLi.title = L._('Zoom to this feature')
L.DomEvent.on(nextLi, 'click', () => { L.DomEvent.on(nextLi, 'click', () => {
if (next) next.zoomTo({ callback: next.view }) if (next) {
next.zoomTo({ callback: next.view })
}
}) })
L.DomEvent.on(previousLi, 'click', () => { L.DomEvent.on(previousLi, 'click', () => {
if (prev) prev.zoomTo({ callback: prev.view }) if (prev) {
prev.zoomTo({ callback: prev.view })
}
}) })
L.DomEvent.on( L.DomEvent.on(
zoomLi, zoomLi,
@ -148,9 +154,13 @@ L.U.PopupTemplate.Default = L.Class.extend({
render: function () { render: function () {
const title = this.renderTitle() const title = this.renderTitle()
if (title) this.container.appendChild(title) if (title) {
this.container.appendChild(title)
}
const body = this.renderBody() const body = this.renderBody()
if (body) L.DomUtil.add('div', 'umap-popup-content', this.container, body) if (body) {
L.DomUtil.add('div', 'umap-popup-content', this.container, body)
}
this.renderFooter() this.renderFooter()
}, },
}) })
@ -184,7 +194,9 @@ L.U.PopupTemplate.Table = L.U.PopupTemplate.BaseWithTitle.extend({
const table = L.DomUtil.create('table') const table = L.DomUtil.create('table')
for (const key in this.feature.properties) { for (const key in this.feature.properties) {
if (typeof this.feature.properties[key] === 'object' || key === 'name') continue if (typeof this.feature.properties[key] === 'object' || key === 'name') {
continue
}
// TODO, manage links (url, mailto, wikipedia...) // TODO, manage links (url, mailto, wikipedia...)
this.addRow(table, key, L.Util.escapeHTML(this.feature.properties[key]).trim()) this.addRow(table, key, L.Util.escapeHTML(this.feature.properties[key]).trim())
} }

View file

@ -22,7 +22,9 @@ L.U.Slideshow = L.Class.extend({
get: function () { get: function () {
if (!current) { if (!current) {
const datalayer = this.defaultDatalayer() const datalayer = this.defaultDatalayer()
if (datalayer) current = datalayer.getFeatureByIndex(0) if (datalayer) {
current = datalayer.getFeatureByIndex(0)
}
} }
return current return current
}, },
@ -70,7 +72,9 @@ L.U.Slideshow = L.Class.extend({
timeSpinner: function () { timeSpinner: function () {
const time = parseInt(this.options.delay, 10) const time = parseInt(this.options.delay, 10)
if (!time) return if (!time) {
return
}
const css = `rotation ${time / 1000}s infinite linear`, const css = `rotation ${time / 1000}s infinite linear`,
spinners = document.querySelectorAll('.umap-slideshow-toolbox .play .spinner') spinners = document.querySelectorAll('.umap-slideshow-toolbox .play .spinner')
for (let i = 0; i < spinners.length; i++) { for (let i = 0; i < spinners.length; i++) {
@ -95,8 +99,12 @@ L.U.Slideshow = L.Class.extend({
}, },
play: function () { play: function () {
if (this._id) return if (this._id) {
if (this.map.editEnabled || !this.map.options.slideshow.active) return return
}
if (this.map.editEnabled || !this.map.options.slideshow.active) {
return
}
L.DomUtil.addClass(document.body, L.U.Slideshow.CLASSNAME) L.DomUtil.addClass(document.body, L.U.Slideshow.CLASSNAME)
this._id = window.setInterval(L.bind(this.loop, this), this.options.delay) this._id = window.setInterval(L.bind(this.loop, this), this.options.delay)
this.resetSpinners() this.resetSpinners()
@ -129,12 +137,16 @@ L.U.Slideshow = L.Class.extend({
backward: function () { backward: function () {
this.pause() this.pause()
if (this.current) this.current = this.current.getPrevious() if (this.current) {
this.current = this.current.getPrevious()
}
this.step() this.step()
}, },
step: function () { step: function () {
if (!this.current) return this.stop() if (!this.current) {
return this.stop()
}
this.current.zoomTo({ easing: this.options.easing }) this.current.zoomTo({ easing: this.options.easing })
this.current.view() this.current.view()
}, },
@ -151,8 +163,11 @@ L.U.Slideshow = L.Class.extend({
next.title = L._('Zoom to the next') next.title = L._('Zoom to the next')
prev.title = L._('Zoom to the previous') prev.title = L._('Zoom to the previous')
const toggle = function () { const toggle = function () {
if (this._id) this.pause() if (this._id) {
else this.play() this.pause()
} else {
this.play()
}
} }
L.DomEvent.on(play, 'click', L.DomEvent.stop).on(play, 'click', toggle, this) L.DomEvent.on(play, 'click', L.DomEvent.stop).on(play, 'click', toggle, this)
L.DomEvent.on(stop, 'click', L.DomEvent.stop).on(stop, 'click', this.stop, this) L.DomEvent.on(stop, 'click', L.DomEvent.stop).on(stop, 'click', this.stop, this)

View file

@ -40,7 +40,9 @@ L.U.TableEditor = L.Class.extend({
L._('Please enter the new name of this property'), L._('Please enter the new name of this property'),
property property
) )
if (!newName || !this.validateName(newName)) return if (!newName || !this.validateName(newName)) {
return
}
this.datalayer.eachLayer((feature) => { this.datalayer.eachLayer((feature) => {
feature.renameProperty(property, newName) feature.renameProperty(property, newName)
}) })
@ -63,10 +65,13 @@ L.U.TableEditor = L.Class.extend({
}, },
compileProperties: function () { compileProperties: function () {
if (this.properties.length === 0) this.properties = ['name'] if (this.properties.length === 0) {
this.properties = ['name']
}
// description is a forced textarea, don't edit it in a text input, or you lose cariage returns // description is a forced textarea, don't edit it in a text input, or you lose cariage returns
if (this.properties.indexOf('description') !== -1) if (this.properties.indexOf('description') !== -1) {
this.properties.splice(this.properties.indexOf('description'), 1) this.properties.splice(this.properties.indexOf('description'), 1)
}
this.properties.sort() this.properties.sort()
this.field_properties = [] this.field_properties = []
for (let i = 0; i < this.properties.length; i++) { for (let i = 0; i < this.properties.length; i++) {
@ -105,7 +110,9 @@ L.U.TableEditor = L.Class.extend({
label.textContent = label.title = L._('Add a new property') label.textContent = label.title = L._('Add a new property')
const addProperty = function () { const addProperty = function () {
const newName = prompt(L._('Please enter the name of the property')) const newName = prompt(L._('Please enter the name of the property'))
if (!newName || !this.validateName(newName)) return if (!newName || !this.validateName(newName)) {
return
}
this.datalayer.indexProperty(newName) this.datalayer.indexProperty(newName)
this.edit() this.edit()
} }

View file

@ -33,9 +33,11 @@ L.U.UI = L.Evented.extend({
this._panel.innerHTML = '' this._panel.innerHTML = ''
const actionsContainer = L.DomUtil.create('ul', 'toolbox', this._panel) const actionsContainer = L.DomUtil.create('ul', 'toolbox', this._panel)
const body = L.DomUtil.create('div', 'body', this._panel) const body = L.DomUtil.create('div', 'body', this._panel)
if (e.data.html.nodeType && e.data.html.nodeType === 1) if (e.data.html.nodeType && e.data.html.nodeType === 1) {
body.appendChild(e.data.html) body.appendChild(e.data.html)
else body.innerHTML = e.data.html } else {
body.innerHTML = e.data.html
}
const closeLink = L.DomUtil.create('li', 'umap-close-link', actionsContainer) const closeLink = L.DomUtil.create('li', 'umap-close-link', actionsContainer)
L.DomUtil.add('i', 'umap-close-icon', closeLink) L.DomUtil.add('i', 'umap-close-icon', closeLink)
const label = L.DomUtil.create('span', '', closeLink) const label = L.DomUtil.create('span', '', closeLink)
@ -45,7 +47,9 @@ L.U.UI = L.Evented.extend({
actionsContainer.appendChild(e.actions[i]) actionsContainer.appendChild(e.actions[i])
} }
} }
if (e.className) L.DomUtil.addClass(this._panel, e.className) if (e.className) {
L.DomUtil.addClass(this._panel, e.className)
}
if (L.DomUtil.hasClass(this.parent, 'umap-ui')) { if (L.DomUtil.hasClass(this.parent, 'umap-ui')) {
// Already open. // Already open.
this.fire('panel:ready') this.fire('panel:ready')
@ -69,14 +73,20 @@ L.U.UI = L.Evented.extend({
}, },
alert: function (e) { alert: function (e) {
if (L.DomUtil.hasClass(this.parent, 'umap-alert')) this.ALERTS.push(e) if (L.DomUtil.hasClass(this.parent, 'umap-alert')) {
else this.popAlert(e) this.ALERTS.push(e)
} else {
this.popAlert(e)
}
}, },
popAlert: function (e) { popAlert: function (e) {
if (!e) { if (!e) {
if (this.ALERTS.length) e = this.ALERTS.pop() if (this.ALERTS.length) {
else return e = this.ALERTS.pop()
} else {
return
}
} }
let timeoutID let timeoutID
const level_class = e.level && e.level == 'info' ? 'info' : 'error' const level_class = e.level && e.level == 'info' ? 'info' : 'error'
@ -90,7 +100,9 @@ L.U.UI = L.Evented.extend({
this._alert.innerHTML = '' this._alert.innerHTML = ''
L.DomUtil.removeClass(this.parent, 'umap-alert') L.DomUtil.removeClass(this.parent, 'umap-alert')
L.DomUtil.removeClass(this._alert, level_class) L.DomUtil.removeClass(this._alert, level_class)
if (timeoutID) window.clearTimeout(timeoutID) if (timeoutID) {
window.clearTimeout(timeoutID)
}
this.popAlert() this.popAlert()
} }
const closeLink = L.DomUtil.create('a', 'umap-close-link', this._alert) const closeLink = L.DomUtil.create('a', 'umap-close-link', this._alert)
@ -143,16 +155,23 @@ L.U.UI = L.Evented.extend({
this.TOOLTIP_ID = Math.random() this.TOOLTIP_ID = Math.random()
const id = this.TOOLTIP_ID const id = this.TOOLTIP_ID
L.DomUtil.addClass(this.parent, 'umap-tooltip') L.DomUtil.addClass(this.parent, 'umap-tooltip')
if (e.anchor && e.position === 'top') this.anchorTooltipTop(e.anchor) if (e.anchor && e.position === 'top') {
else if (e.anchor && e.position === 'left') this.anchorTooltipLeft(e.anchor) this.anchorTooltipTop(e.anchor)
else this.anchorTooltipAbsolute() } else if (e.anchor && e.position === 'left') {
this.anchorTooltipLeft(e.anchor)
} else {
this.anchorTooltipAbsolute()
}
this._tooltip.innerHTML = e.content this._tooltip.innerHTML = e.content
function closeIt() { function closeIt() {
this.closeTooltip(id) this.closeTooltip(id)
} }
if (e.anchor) L.DomEvent.once(e.anchor, 'mouseout', closeIt, this) if (e.anchor) {
if (e.duration !== Infinity) L.DomEvent.once(e.anchor, 'mouseout', closeIt, this)
}
if (e.duration !== Infinity) {
window.setTimeout(L.bind(closeIt, this), e.duration || 3000) window.setTimeout(L.bind(closeIt, this), e.duration || 3000)
}
}, },
anchorTooltipAbsolute: function () { anchorTooltipAbsolute: function () {
@ -184,7 +203,9 @@ L.U.UI = L.Evented.extend({
}, },
closeTooltip: function (id) { closeTooltip: function (id) {
if (id && id !== this.TOOLTIP_ID) return if (id && id !== this.TOOLTIP_ID) {
return
}
this._tooltip.innerHTML = '' this._tooltip.innerHTML = ''
L.DomUtil.removeClass(this.parent, 'umap-tooltip') L.DomUtil.removeClass(this.parent, 'umap-tooltip')
}, },
@ -194,14 +215,26 @@ L.U.UI = L.Evented.extend({
}, },
setTooltipPosition: function (coords) { setTooltipPosition: function (coords) {
if (coords.left) this._tooltip.style.left = `${coords.left}px` if (coords.left) {
else this._tooltip.style.left = 'initial' this._tooltip.style.left = `${coords.left}px`
if (coords.right) this._tooltip.style.right = `${coords.right}px` } else {
else this._tooltip.style.right = 'initial' this._tooltip.style.left = 'initial'
if (coords.top) this._tooltip.style.top = `${coords.top}px` }
else this._tooltip.style.top = 'initial' if (coords.right) {
if (coords.bottom) this._tooltip.style.bottom = `${coords.bottom}px` this._tooltip.style.right = `${coords.right}px`
else this._tooltip.style.bottom = 'initial' } else {
this._tooltip.style.right = 'initial'
}
if (coords.top) {
this._tooltip.style.top = `${coords.top}px`
} else {
this._tooltip.style.top = 'initial'
}
if (coords.bottom) {
this._tooltip.style.bottom = `${coords.bottom}px`
} else {
this._tooltip.style.bottom = 'initial'
}
}, },
getDocHeight: function () { getDocHeight: function () {

View file

@ -159,12 +159,17 @@ L.U.Xhr = L.Evented.extend({
self.ui.alert({ content: L._('An error occured'), level: 'error' }) self.ui.alert({ content: L._('An error occured'), level: 'error' })
} else if (data.login_required) { } else if (data.login_required) {
// login_required should be an URL for the login form // login_required should be an URL for the login form
if (settings.login_callback) settings.login_callback(data) if (settings.login_callback) {
else self.login(data, args) settings.login_callback(data)
} else {
self.login(data, args)
}
} else { } else {
if (settings.callback) if (settings.callback) {
L.bind(settings.callback, settings.context || this)(data, response) L.bind(settings.callback, settings.context || this)(data, response)
else self.default_callback(data, settings, response) } else {
self.default_callback(data, settings, response)
}
} }
} }
@ -187,10 +192,14 @@ L.U.Xhr = L.Evented.extend({
}, },
submit_form: function (form_id, options) { submit_form: function (form_id, options) {
if (typeof options === 'undefined') options = {} if (typeof options === 'undefined') {
options = {}
}
const form = L.DomUtil.get(form_id) const form = L.DomUtil.get(form_id)
const formData = new FormData(form) const formData = new FormData(form)
if (options.extraFormData) formData.append(options.extraFormData) if (options.extraFormData) {
formData.append(options.extraFormData)
}
options.data = formData options.data = formData
this.post(form.action, options) this.post(form.action, options)
return false return false
@ -199,7 +208,9 @@ L.U.Xhr = L.Evented.extend({
listen_form: function (form_id, options) { listen_form: function (form_id, options) {
const form = L.DomUtil.get(form_id), const form = L.DomUtil.get(form_id),
self = this self = this
if (!form) return if (!form) {
return
}
L.DomEvent.on(form, 'submit', L.DomEvent.stopPropagation) L.DomEvent.on(form, 'submit', L.DomEvent.stopPropagation)
.on(form, 'submit', L.DomEvent.preventDefault) .on(form, 'submit', L.DomEvent.preventDefault)
.on(form, 'submit', () => { .on(form, 'submit', () => {
@ -224,9 +235,11 @@ L.U.Xhr = L.Evented.extend({
// default callback, to avoid boilerplate // default callback, to avoid boilerplate
if (data.redirect) { if (data.redirect) {
const newPath = data.redirect const newPath = data.redirect
if (window.location.pathname == newPath) if (window.location.pathname == newPath) {
window.location.reload() // Keep the hash, so the current view window.location.reload()
else window.location = newPath } else {
window.location = newPath
}
} else if (data.info) { } else if (data.info) {
this.ui.alert({ content: data.info, level: 'info' }) this.ui.alert({ content: data.info, level: 'info' })
this.ui.closePanel() this.ui.closePanel()
@ -235,7 +248,9 @@ L.U.Xhr = L.Evented.extend({
} else if (data.html) { } else if (data.html) {
const ui_options = { data: data } const ui_options = { data: data }
let listen_options let listen_options
if (options.className) ui_options.className = options.className if (options.className) {
ui_options.className = options.className
}
this.ui.openPanel(ui_options) this.ui.openPanel(ui_options)
// To low boilerplate, if there is a form, listen it // To low boilerplate, if there is a form, listen it
if (options.listen_form) { if (options.listen_form) {
@ -262,15 +277,21 @@ L.U.Xhr = L.Evented.extend({
const self = this const self = this
const proceed = () => { const proceed = () => {
self.ui.closePanel() self.ui.closePanel()
if (typeof args !== 'undefined') self._json.apply(self, args) if (typeof args !== 'undefined') {
else self.default_callback(data, {}) self._json.apply(self, args)
} else {
self.default_callback(data, {})
}
} }
const ask_for_login = (data) => { const ask_for_login = (data) => {
self.ui.openPanel({ data: data, className: 'login-panel' }) self.ui.openPanel({ data: data, className: 'login-panel' })
self.listen_form('login_form', { self.listen_form('login_form', {
callback: function (data) { callback: function (data) {
if (data.html) ask_for_login(data) // Problem in the login - ask again if (data.html) {
else proceed() ask_for_login(data)
} else {
proceed()
}
}, },
}) })
// Auth links // Auth links