function handleFormSubmit(event) {
let form_el = event.target;
let val = form_el.querySelector('input[type=edit]').value.trim();
- let type_and_id_match = val.match(/^\s*([NWR])(\d+)\s*$/i)
- || val.match(/\/(relation|way|node)\/(\d+)\s*$/);
+ let type_and_id_match = val.match(/^\s*([NWR])(-?\d+)\s*$/i)
+ || val.match(/\/(relation|way|node)\/(-?\d+)\s*$/);
var params = new URLSearchParams();
if (type_and_id_match) {
<!-- eslint-disable-next-line max-len -->
<input type="edit"
class="form-control form-control-sm me-1"
- pattern="^[NWRnwr]?[0-9]+$|.*openstreetmap.*"
+ pattern="^[1-9][0-9]*$|^[NWRnwr]-?[1-9][0-9]*$|.*openstreetmap.*"
value="{
(api_request_params.osmtype || '')
+ (api_request_params.osmid || '')
// w123 => ['W', 123]
export function identifyLinkInQuery(query) {
if (!query) return undefined;
- const m = query.match(/\/(relation|way|node)\/(\d+)/) || query.match(/^([nwr])(\d+)$/i);
+ const m = query.match(/\/(relation|way|node)\/(-?\d+)/) || query.match(/^([nwr])(-?\d+)$/i);
if (!m) return undefined;
return [m[1][0].toUpperCase(), Number(m[2])];
}
assert.deepStrictEqual(identifyLinkInQuery('https://www.openstreetmap.org/relation/1234#map=11/41.2388/-8.3867'), ['R', 1234]);
assert.deepStrictEqual(identifyLinkInQuery('n1234'), ['N', 1234]);
assert.deepStrictEqual(identifyLinkInQuery('W1234'), ['W', 1234]);
+ assert.deepStrictEqual(identifyLinkInQuery('R-123'), ['R', -123]);
});
it('.formatLabel', function () {