@nextgis/ngw-map 1.17.0 → 1.18.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/ngw-map.cjs.js +1 -1
- package/lib/ngw-map.esm-browser.js +635 -33
- package/lib/ngw-map.esm-browser.js.map +1 -1
- package/lib/ngw-map.esm-browser.prod.js +1 -1
- package/lib/ngw-map.esm-browser.prod.js.map +1 -1
- package/lib/ngw-map.esm-bundler.js +1 -1
- package/lib/ngw-map.global.js +657 -33
- package/lib/ngw-map.global.js.map +1 -1
- package/lib/ngw-map.global.prod.js +1 -1
- package/lib/ngw-map.global.prod.js.map +1 -1
- package/package.json +6 -6
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** Bundle of @nextgis/ngw-map; version: 1.
|
|
1
|
+
/** Bundle of @nextgis/ngw-map; version: 1.18.1; author: NextGIS */
|
|
2
2
|
var events = {exports: {}};
|
|
3
3
|
|
|
4
4
|
var R = typeof Reflect === 'object' ? Reflect : null;
|
|
@@ -1166,12 +1166,6 @@ function fixUrlStr(url) {
|
|
|
1166
1166
|
return url.replace(/([^:]\/)\/+/g, '$1');
|
|
1167
1167
|
}
|
|
1168
1168
|
|
|
1169
|
-
function isExpression(value) {
|
|
1170
|
-
if (Array.isArray(value)) {
|
|
1171
|
-
return true;
|
|
1172
|
-
}
|
|
1173
|
-
return false;
|
|
1174
|
-
}
|
|
1175
1169
|
function isPropertiesPaint(paint) {
|
|
1176
1170
|
if (Array.isArray(paint)) {
|
|
1177
1171
|
return true;
|
|
@@ -1191,41 +1185,622 @@ function isPaintCallback(paint) {
|
|
|
1191
1185
|
return false;
|
|
1192
1186
|
}
|
|
1193
1187
|
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1188
|
+
const tryConvert = (converter, arg, data) => {
|
|
1189
|
+
try {
|
|
1190
|
+
const result = converter(arg, data);
|
|
1191
|
+
if (result !== undefined) {
|
|
1192
|
+
return result;
|
|
1193
|
+
}
|
|
1194
|
+
}
|
|
1195
|
+
catch {
|
|
1196
|
+
// ignore errors
|
|
1197
|
+
}
|
|
1198
|
+
return undefined;
|
|
1199
|
+
};
|
|
1200
|
+
|
|
1201
|
+
function fallback(cb) {
|
|
1202
|
+
return (args, data) => {
|
|
1203
|
+
for (const arg of args) {
|
|
1204
|
+
const result = tryConvert(cb, arg, data);
|
|
1205
|
+
if (result !== undefined) {
|
|
1206
|
+
return result;
|
|
1207
|
+
}
|
|
1208
|
+
}
|
|
1209
|
+
throw new Error(`Received a mismatched type`);
|
|
1210
|
+
};
|
|
1197
1211
|
}
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1212
|
+
|
|
1213
|
+
const array = (args) => {
|
|
1214
|
+
const [firstArg, secondArg, thirdArg] = args;
|
|
1215
|
+
let requiredType = undefined;
|
|
1216
|
+
let requiredLength = undefined;
|
|
1217
|
+
let value;
|
|
1218
|
+
if (typeof firstArg === 'string' &&
|
|
1219
|
+
['string', 'number', 'boolean'].includes(firstArg)) {
|
|
1220
|
+
requiredType = firstArg;
|
|
1221
|
+
if (typeof secondArg === 'number') {
|
|
1222
|
+
requiredLength = secondArg;
|
|
1223
|
+
value = thirdArg;
|
|
1224
|
+
}
|
|
1225
|
+
else {
|
|
1226
|
+
value = secondArg;
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
else if (Array.isArray(firstArg)) {
|
|
1230
|
+
value = firstArg;
|
|
1231
|
+
}
|
|
1232
|
+
if (!Array.isArray(value)) {
|
|
1233
|
+
throw new Error('Expected an array');
|
|
1234
|
+
}
|
|
1235
|
+
if (requiredType && !value.every((item) => typeof item === requiredType)) {
|
|
1236
|
+
throw new Error(`Expected all items in array to be of type ${requiredType}`);
|
|
1237
|
+
}
|
|
1238
|
+
if (requiredLength && value.length !== requiredLength) {
|
|
1239
|
+
throw new Error(`Expected array of length ${requiredLength}`);
|
|
1240
|
+
}
|
|
1241
|
+
return value;
|
|
1242
|
+
};
|
|
1243
|
+
const typeExpressions = {
|
|
1244
|
+
array,
|
|
1245
|
+
boolean: fallback((arg) => (typeof arg === 'boolean' ? arg : undefined)),
|
|
1246
|
+
literal: ([arg]) => arg,
|
|
1247
|
+
number: fallback((arg) => (typeof arg === 'number' ? arg : undefined)),
|
|
1248
|
+
object: fallback((arg) => arg !== null && typeof arg === 'object' && !Array.isArray(arg)
|
|
1249
|
+
? arg
|
|
1250
|
+
: undefined),
|
|
1251
|
+
string: fallback((arg) => (typeof arg === 'string' ? arg : undefined)),
|
|
1252
|
+
'to-boolean': fallback(Boolean),
|
|
1253
|
+
'to-number': fallback(Number),
|
|
1254
|
+
'to-string': fallback(String),
|
|
1255
|
+
typeof: ([arg]) => typeof arg,
|
|
1256
|
+
};
|
|
1257
|
+
|
|
1258
|
+
const mathExpressions = {
|
|
1259
|
+
'+': (args) => args.reduce((a, b) => a + b, 0),
|
|
1260
|
+
'-': (args) => args.reduce((a, b) => a - b),
|
|
1261
|
+
'*': (args) => args.reduce((a, b) => a * b, 1),
|
|
1262
|
+
'/': (args) => args.reduce((a, b) => a / b),
|
|
1263
|
+
'%': (args) => args[0] % args[1],
|
|
1264
|
+
'^': (args) => Math.pow(args[0], args[1]),
|
|
1265
|
+
abs: (args) => Math.abs(args[0]),
|
|
1266
|
+
acos: (args) => Math.acos(args[0]),
|
|
1267
|
+
asin: (args) => Math.asin(args[0]),
|
|
1268
|
+
atan: (args) => Math.atan(args[0]),
|
|
1269
|
+
ceil: (args) => Math.ceil(args[0]),
|
|
1270
|
+
cos: (args) => Math.cos(args[0]),
|
|
1271
|
+
e: () => Math.E,
|
|
1272
|
+
floor: (args) => Math.floor(args[0]),
|
|
1273
|
+
ln: (args) => Math.log(args[0]),
|
|
1274
|
+
ln2: () => Math.LN2,
|
|
1275
|
+
log10: (args) => Math.log10(args[0]),
|
|
1276
|
+
log2: (args) => Math.log2(args[0]),
|
|
1277
|
+
max: (args) => Math.max(...args),
|
|
1278
|
+
min: (args) => Math.min(...args),
|
|
1279
|
+
pi: () => Math.PI,
|
|
1280
|
+
round: (args) => Math.round(args[0]),
|
|
1281
|
+
sin: (args) => Math.sin(args[0]),
|
|
1282
|
+
sqrt: (args) => Math.sqrt(args[0]),
|
|
1283
|
+
tan: (args) => Math.tan(args[0]),
|
|
1284
|
+
};
|
|
1285
|
+
|
|
1286
|
+
function get([key, objExp], data) {
|
|
1287
|
+
const target = objExp || data;
|
|
1288
|
+
if (target && typeof target === 'object' && key in target) {
|
|
1289
|
+
return target[key];
|
|
1290
|
+
}
|
|
1291
|
+
return null;
|
|
1292
|
+
}
|
|
1293
|
+
function has([key, objExp], data) {
|
|
1294
|
+
const target = objExp || data;
|
|
1295
|
+
return !!(target && typeof target === 'object' && key in target);
|
|
1296
|
+
}
|
|
1297
|
+
function at([index, array]) {
|
|
1298
|
+
return array[index];
|
|
1299
|
+
}
|
|
1300
|
+
function inFunc([keyword, input]) {
|
|
1301
|
+
if (typeof input === 'string') {
|
|
1302
|
+
return input.includes(String(keyword));
|
|
1203
1303
|
}
|
|
1304
|
+
else if (Array.isArray(input)) {
|
|
1305
|
+
return input.includes(keyword);
|
|
1306
|
+
}
|
|
1307
|
+
throw new Error(`Invalid input type for 'in'. Expected string or array, got ${typeof input}.`);
|
|
1308
|
+
}
|
|
1309
|
+
const length = ([item]) => {
|
|
1310
|
+
if (typeof item === 'string' || Array.isArray(item)) {
|
|
1311
|
+
return item.length;
|
|
1312
|
+
}
|
|
1313
|
+
return undefined;
|
|
1314
|
+
};
|
|
1315
|
+
function indexOf([keyword, input, startIndex]) {
|
|
1316
|
+
if (typeof input === 'string') {
|
|
1317
|
+
return input.indexOf(String(keyword), startIndex);
|
|
1318
|
+
}
|
|
1319
|
+
else if (Array.isArray(input)) {
|
|
1320
|
+
return input.indexOf(keyword, startIndex);
|
|
1321
|
+
}
|
|
1322
|
+
throw new Error(`Invalid input type for 'index-of'. Expected string or array, got ${typeof input}.`);
|
|
1323
|
+
}
|
|
1324
|
+
function slice(args) {
|
|
1325
|
+
const [input, startIndex, endIndex] = args;
|
|
1326
|
+
if (typeof input === 'string') {
|
|
1327
|
+
return input.slice(startIndex, endIndex);
|
|
1328
|
+
}
|
|
1329
|
+
else if (Array.isArray(input)) {
|
|
1330
|
+
return input.slice(startIndex, endIndex);
|
|
1331
|
+
}
|
|
1332
|
+
throw new Error(`Invalid input type for 'slice'. Expected string or array, got ${typeof input}.`);
|
|
1333
|
+
}
|
|
1334
|
+
const lookupExpressions = {
|
|
1335
|
+
get,
|
|
1336
|
+
length,
|
|
1337
|
+
at,
|
|
1338
|
+
has,
|
|
1339
|
+
in: inFunc,
|
|
1340
|
+
'index-of': indexOf,
|
|
1341
|
+
slice,
|
|
1342
|
+
};
|
|
1343
|
+
|
|
1344
|
+
const stringExpressions = {
|
|
1345
|
+
concat: (args) => args.reduce((a, b) => String(a) + String(b), ''),
|
|
1346
|
+
downcase: (args) => String(args[0]).toLowerCase(),
|
|
1347
|
+
upcase: (args) => String(args[0]).toUpperCase(),
|
|
1348
|
+
};
|
|
1349
|
+
|
|
1350
|
+
function not([expr]) {
|
|
1351
|
+
return !expr;
|
|
1352
|
+
}
|
|
1353
|
+
const checkCompareValues = ([a, b]) => {
|
|
1354
|
+
if (typeof a !== typeof b) {
|
|
1355
|
+
throw new Error('Values have different types.');
|
|
1356
|
+
}
|
|
1357
|
+
};
|
|
1358
|
+
function notEqual([a, b]) {
|
|
1359
|
+
checkCompareValues([a, b]);
|
|
1360
|
+
return a !== b;
|
|
1361
|
+
}
|
|
1362
|
+
function lessThan([left, right]) {
|
|
1363
|
+
checkCompareValues([left, right]);
|
|
1364
|
+
return left < right;
|
|
1365
|
+
}
|
|
1366
|
+
function lessThanOrEqual([left, right]) {
|
|
1367
|
+
checkCompareValues([left, right]);
|
|
1368
|
+
return left <= right;
|
|
1369
|
+
}
|
|
1370
|
+
function equal([left, right]) {
|
|
1371
|
+
checkCompareValues([left, right]);
|
|
1372
|
+
return left === right;
|
|
1373
|
+
}
|
|
1374
|
+
function greaterThan([left, right]) {
|
|
1375
|
+
checkCompareValues([left, right]);
|
|
1376
|
+
return left > right;
|
|
1377
|
+
}
|
|
1378
|
+
function greaterThanOrEqual([left, right]) {
|
|
1379
|
+
checkCompareValues([left, right]);
|
|
1380
|
+
return left >= right;
|
|
1381
|
+
}
|
|
1382
|
+
function all(args) {
|
|
1383
|
+
for (let i = 0; i < args.length; i++) {
|
|
1384
|
+
const arg = args[i];
|
|
1385
|
+
if (!arg) {
|
|
1386
|
+
return false;
|
|
1387
|
+
}
|
|
1388
|
+
}
|
|
1389
|
+
return true;
|
|
1390
|
+
}
|
|
1391
|
+
function any(args) {
|
|
1392
|
+
for (let i = 0; i < args.length; i++) {
|
|
1393
|
+
const arg = args[i];
|
|
1394
|
+
if (arg) {
|
|
1395
|
+
return true;
|
|
1396
|
+
}
|
|
1397
|
+
}
|
|
1398
|
+
return false;
|
|
1399
|
+
}
|
|
1400
|
+
function match(args) {
|
|
1401
|
+
const [lookup, ...cases] = args;
|
|
1204
1402
|
// remove last odd item from cases array
|
|
1205
1403
|
const defValue = cases.splice(-1, cases.length % 2)[0];
|
|
1206
1404
|
for (let fry = 0; fry < cases.length - 1; fry += 2) {
|
|
1207
1405
|
const key = cases[fry];
|
|
1208
|
-
if (key ===
|
|
1406
|
+
if (key === lookup) {
|
|
1209
1407
|
return cases[fry + 1];
|
|
1210
1408
|
}
|
|
1211
1409
|
}
|
|
1212
1410
|
return defValue;
|
|
1213
1411
|
}
|
|
1214
|
-
|
|
1215
|
-
|
|
1412
|
+
function caseFunc(args) {
|
|
1413
|
+
if (args.length < 2) {
|
|
1414
|
+
throw new Error('The "case" function requires at least a condition and a corresponding output.');
|
|
1415
|
+
}
|
|
1416
|
+
const fallback = args[args.length - 1];
|
|
1417
|
+
if (args.length % 2 === 0) {
|
|
1418
|
+
throw new Error('Missing a fallback value or unmatched condition-output pair.');
|
|
1419
|
+
}
|
|
1420
|
+
for (let i = 0; i < args.length - 1; i += 2) {
|
|
1421
|
+
const condition = args[i];
|
|
1422
|
+
const value = args[i + 1];
|
|
1423
|
+
if (condition) {
|
|
1424
|
+
return value;
|
|
1425
|
+
}
|
|
1426
|
+
}
|
|
1427
|
+
return fallback;
|
|
1428
|
+
}
|
|
1429
|
+
const decisionExpressions = {
|
|
1430
|
+
'!': not,
|
|
1431
|
+
'!=': notEqual,
|
|
1432
|
+
'<': lessThan,
|
|
1433
|
+
'<=': lessThanOrEqual,
|
|
1434
|
+
'==': equal,
|
|
1435
|
+
'>': greaterThan,
|
|
1436
|
+
'>=': greaterThanOrEqual,
|
|
1437
|
+
all: all,
|
|
1438
|
+
any: any,
|
|
1439
|
+
case: caseFunc,
|
|
1216
1440
|
match,
|
|
1217
1441
|
};
|
|
1218
|
-
|
|
1442
|
+
|
|
1443
|
+
function step(args) {
|
|
1444
|
+
const [input, defaultValue, ...stops] = args;
|
|
1445
|
+
if (typeof input !== 'number') {
|
|
1446
|
+
return defaultValue;
|
|
1447
|
+
}
|
|
1448
|
+
for (let i = 0; i < stops.length - 2; i += 2) {
|
|
1449
|
+
const stopInput = stops[i];
|
|
1450
|
+
const stopOutput = stops[i + 1];
|
|
1451
|
+
const nextStopInput = stops[i + 2];
|
|
1452
|
+
if (input >= stopInput && input < nextStopInput) {
|
|
1453
|
+
return stopOutput;
|
|
1454
|
+
}
|
|
1455
|
+
}
|
|
1456
|
+
if (input >= stops[stops.length - 2]) {
|
|
1457
|
+
return stops[stops.length - 1];
|
|
1458
|
+
}
|
|
1459
|
+
return defaultValue;
|
|
1460
|
+
}
|
|
1461
|
+
|
|
1462
|
+
const COLORS = {
|
|
1463
|
+
aliceblue: '#f0f8ff',
|
|
1464
|
+
antiquewhite: '#faebd7',
|
|
1465
|
+
aqua: '#00ffff',
|
|
1466
|
+
aquamarine: '#7fffd4',
|
|
1467
|
+
azure: '#f0ffff',
|
|
1468
|
+
beige: '#f5f5dc',
|
|
1469
|
+
bisque: '#ffe4c4',
|
|
1470
|
+
black: '#000000',
|
|
1471
|
+
blanchedalmond: '#ffebcd',
|
|
1472
|
+
blue: '#0000ff',
|
|
1473
|
+
blueviolet: '#8a2be2',
|
|
1474
|
+
brown: '#a52a2a',
|
|
1475
|
+
burlywood: '#deb887',
|
|
1476
|
+
cadetblue: '#5f9ea0',
|
|
1477
|
+
chartreuse: '#7fff00',
|
|
1478
|
+
chocolate: '#d2691e',
|
|
1479
|
+
coral: '#ff7f50',
|
|
1480
|
+
cornflowerblue: '#6495ed',
|
|
1481
|
+
cornsilk: '#fff8dc',
|
|
1482
|
+
crimson: '#dc143c',
|
|
1483
|
+
cyan: '#00ffff',
|
|
1484
|
+
darkblue: '#00008b',
|
|
1485
|
+
darkcyan: '#008b8b',
|
|
1486
|
+
darkgoldenrod: '#b8860b',
|
|
1487
|
+
darkgray: '#a9a9a9',
|
|
1488
|
+
darkgreen: '#006400',
|
|
1489
|
+
darkkhaki: '#bdb76b',
|
|
1490
|
+
darkmagenta: '#8b008b',
|
|
1491
|
+
darkolivegreen: '#556b2f',
|
|
1492
|
+
darkorange: '#ff8c00',
|
|
1493
|
+
darkorchid: '#9932cc',
|
|
1494
|
+
darkred: '#8b0000',
|
|
1495
|
+
darksalmon: '#e9967a',
|
|
1496
|
+
darkseagreen: '#8fbc8f',
|
|
1497
|
+
darkslateblue: '#483d8b',
|
|
1498
|
+
darkslategray: '#2f4f4f',
|
|
1499
|
+
darkturquoise: '#00ced1',
|
|
1500
|
+
darkviolet: '#9400d3',
|
|
1501
|
+
deeppink: '#ff1493',
|
|
1502
|
+
deepskyblue: '#00bfff',
|
|
1503
|
+
dimgray: '#696969',
|
|
1504
|
+
dodgerblue: '#1e90ff',
|
|
1505
|
+
firebrick: '#b22222',
|
|
1506
|
+
floralwhite: '#fffaf0',
|
|
1507
|
+
forestgreen: '#228b22',
|
|
1508
|
+
fuchsia: '#ff00ff',
|
|
1509
|
+
gainsboro: '#dcdcdc',
|
|
1510
|
+
ghostwhite: '#f8f8ff',
|
|
1511
|
+
gold: '#ffd700',
|
|
1512
|
+
goldenrod: '#daa520',
|
|
1513
|
+
gray: '#808080',
|
|
1514
|
+
green: '#008000',
|
|
1515
|
+
greenyellow: '#adff2f',
|
|
1516
|
+
honeydew: '#f0fff0',
|
|
1517
|
+
hotpink: '#ff69b4',
|
|
1518
|
+
'indianred ': '#cd5c5c',
|
|
1519
|
+
indigo: '#4b0082',
|
|
1520
|
+
ivory: '#fffff0',
|
|
1521
|
+
khaki: '#f0e68c',
|
|
1522
|
+
lavender: '#e6e6fa',
|
|
1523
|
+
lavenderblush: '#fff0f5',
|
|
1524
|
+
lawngreen: '#7cfc00',
|
|
1525
|
+
lemonchiffon: '#fffacd',
|
|
1526
|
+
lightblue: '#add8e6',
|
|
1527
|
+
lightcoral: '#f08080',
|
|
1528
|
+
lightcyan: '#e0ffff',
|
|
1529
|
+
lightgoldenrodyellow: '#fafad2',
|
|
1530
|
+
lightgrey: '#d3d3d3',
|
|
1531
|
+
lightgreen: '#90ee90',
|
|
1532
|
+
lightpink: '#ffb6c1',
|
|
1533
|
+
lightsalmon: '#ffa07a',
|
|
1534
|
+
lightseagreen: '#20b2aa',
|
|
1535
|
+
lightskyblue: '#87cefa',
|
|
1536
|
+
lightslategray: '#778899',
|
|
1537
|
+
lightsteelblue: '#b0c4de',
|
|
1538
|
+
lightyellow: '#ffffe0',
|
|
1539
|
+
lime: '#00ff00',
|
|
1540
|
+
limegreen: '#32cd32',
|
|
1541
|
+
linen: '#faf0e6',
|
|
1542
|
+
magenta: '#ff00ff',
|
|
1543
|
+
maroon: '#800000',
|
|
1544
|
+
mediumaquamarine: '#66cdaa',
|
|
1545
|
+
mediumblue: '#0000cd',
|
|
1546
|
+
mediumorchid: '#ba55d3',
|
|
1547
|
+
mediumpurple: '#9370d8',
|
|
1548
|
+
mediumseagreen: '#3cb371',
|
|
1549
|
+
mediumslateblue: '#7b68ee',
|
|
1550
|
+
mediumspringgreen: '#00fa9a',
|
|
1551
|
+
mediumturquoise: '#48d1cc',
|
|
1552
|
+
mediumvioletred: '#c71585',
|
|
1553
|
+
midnightblue: '#191970',
|
|
1554
|
+
mintcream: '#f5fffa',
|
|
1555
|
+
mistyrose: '#ffe4e1',
|
|
1556
|
+
moccasin: '#ffe4b5',
|
|
1557
|
+
navajowhite: '#ffdead',
|
|
1558
|
+
navy: '#000080',
|
|
1559
|
+
oldlace: '#fdf5e6',
|
|
1560
|
+
olive: '#808000',
|
|
1561
|
+
olivedrab: '#6b8e23',
|
|
1562
|
+
orange: '#ffa500',
|
|
1563
|
+
orangered: '#ff4500',
|
|
1564
|
+
orchid: '#da70d6',
|
|
1565
|
+
palegoldenrod: '#eee8aa',
|
|
1566
|
+
palegreen: '#98fb98',
|
|
1567
|
+
paleturquoise: '#afeeee',
|
|
1568
|
+
palevioletred: '#d87093',
|
|
1569
|
+
papayawhip: '#ffefd5',
|
|
1570
|
+
peachpuff: '#ffdab9',
|
|
1571
|
+
peru: '#cd853f',
|
|
1572
|
+
pink: '#ffc0cb',
|
|
1573
|
+
plum: '#dda0dd',
|
|
1574
|
+
powderblue: '#b0e0e6',
|
|
1575
|
+
purple: '#800080',
|
|
1576
|
+
rebeccapurple: '#663399',
|
|
1577
|
+
red: '#ff0000',
|
|
1578
|
+
rosybrown: '#bc8f8f',
|
|
1579
|
+
royalblue: '#4169e1',
|
|
1580
|
+
saddlebrown: '#8b4513',
|
|
1581
|
+
salmon: '#fa8072',
|
|
1582
|
+
sandybrown: '#f4a460',
|
|
1583
|
+
seagreen: '#2e8b57',
|
|
1584
|
+
seashell: '#fff5ee',
|
|
1585
|
+
sienna: '#a0522d',
|
|
1586
|
+
silver: '#c0c0c0',
|
|
1587
|
+
skyblue: '#87ceeb',
|
|
1588
|
+
slateblue: '#6a5acd',
|
|
1589
|
+
slategray: '#708090',
|
|
1590
|
+
snow: '#fffafa',
|
|
1591
|
+
springgreen: '#00ff7f',
|
|
1592
|
+
steelblue: '#4682b4',
|
|
1593
|
+
tan: '#d2b48c',
|
|
1594
|
+
teal: '#008080',
|
|
1595
|
+
thistle: '#d8bfd8',
|
|
1596
|
+
tomato: '#ff6347',
|
|
1597
|
+
turquoise: '#40e0d0',
|
|
1598
|
+
violet: '#ee82ee',
|
|
1599
|
+
wheat: '#f5deb3',
|
|
1600
|
+
white: '#ffffff',
|
|
1601
|
+
whitesmoke: '#f5f5f5',
|
|
1602
|
+
yellow: '#ffff00',
|
|
1603
|
+
yellowgreen: '#9acd32',
|
|
1604
|
+
};
|
|
1605
|
+
|
|
1606
|
+
function isHex(hex) {
|
|
1607
|
+
return typeof hex === 'string' && /^#([A-Fa-f0-9]{3}){1,2}$/.test(hex);
|
|
1608
|
+
}
|
|
1609
|
+
function isRgb(hex) {
|
|
1610
|
+
const r =
|
|
1611
|
+
// eslint-disable-next-line max-len
|
|
1612
|
+
/^rgb(a?)\(\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)(?:\s*,\s*([01](?:\.\d+)?))?\s*\)$/;
|
|
1613
|
+
return typeof hex === 'string' && r.test(hex);
|
|
1614
|
+
}
|
|
1615
|
+
function isColorObj(obj) {
|
|
1616
|
+
if (typeof obj === 'object' && obj !== null) {
|
|
1617
|
+
const hasRgb = 'r' in obj && 'g' in obj && 'b' in obj;
|
|
1618
|
+
const hasValidAlpha = !('a' in obj) || (typeof obj.a === 'number' && obj.a >= 0 && obj.a <= 1);
|
|
1619
|
+
return hasRgb && hasValidAlpha;
|
|
1620
|
+
}
|
|
1621
|
+
return false;
|
|
1622
|
+
}
|
|
1623
|
+
function isColorName(name) {
|
|
1624
|
+
if (typeof name === 'string' && name in COLORS) {
|
|
1625
|
+
return true;
|
|
1626
|
+
}
|
|
1627
|
+
return false;
|
|
1628
|
+
}
|
|
1629
|
+
function toColor(value) {
|
|
1630
|
+
if (isHex(value)) {
|
|
1631
|
+
return hexToColor(value);
|
|
1632
|
+
}
|
|
1633
|
+
else if (isColorName(value)) {
|
|
1634
|
+
return colorNameToColor(value);
|
|
1635
|
+
}
|
|
1636
|
+
else if (isRgb(value)) {
|
|
1637
|
+
return rgbToColor(value);
|
|
1638
|
+
}
|
|
1639
|
+
else if (isColorObj(value)) {
|
|
1640
|
+
return colorObjectToColor(value);
|
|
1641
|
+
}
|
|
1642
|
+
throw new Error(`The '${value}' cannot be converted to color`);
|
|
1643
|
+
}
|
|
1644
|
+
function colorNameToColor(name) {
|
|
1645
|
+
return hexToColor(COLORS[name]);
|
|
1646
|
+
}
|
|
1647
|
+
function hexToColor(hex) {
|
|
1648
|
+
const shortRGB = /^#([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])$/;
|
|
1649
|
+
const shortRGBA = /^#([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])$/;
|
|
1650
|
+
const longRGB = /^#([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/;
|
|
1651
|
+
const longRGBA = /^#([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/;
|
|
1652
|
+
let result;
|
|
1653
|
+
if ((result = shortRGB.exec(hex))) {
|
|
1654
|
+
return [
|
|
1655
|
+
parseInt(result[1] + result[1], 16),
|
|
1656
|
+
parseInt(result[2] + result[2], 16),
|
|
1657
|
+
parseInt(result[3] + result[3], 16),
|
|
1658
|
+
];
|
|
1659
|
+
}
|
|
1660
|
+
else if ((result = shortRGBA.exec(hex))) {
|
|
1661
|
+
return [
|
|
1662
|
+
parseInt(result[1] + result[1], 16),
|
|
1663
|
+
parseInt(result[2] + result[2], 16),
|
|
1664
|
+
parseInt(result[3] + result[3], 16),
|
|
1665
|
+
parseInt(result[4] + result[4], 16) / 255,
|
|
1666
|
+
];
|
|
1667
|
+
}
|
|
1668
|
+
else if ((result = longRGB.exec(hex))) {
|
|
1669
|
+
return [
|
|
1670
|
+
parseInt(result[1], 16),
|
|
1671
|
+
parseInt(result[2], 16),
|
|
1672
|
+
parseInt(result[3], 16),
|
|
1673
|
+
];
|
|
1674
|
+
}
|
|
1675
|
+
else if ((result = longRGBA.exec(hex))) {
|
|
1676
|
+
return [
|
|
1677
|
+
parseInt(result[1], 16),
|
|
1678
|
+
parseInt(result[2], 16),
|
|
1679
|
+
parseInt(result[3], 16),
|
|
1680
|
+
parseInt(result[4], 16) / 255,
|
|
1681
|
+
];
|
|
1682
|
+
}
|
|
1683
|
+
throw new Error(`The '${hex}' Is not valid hex`);
|
|
1684
|
+
}
|
|
1685
|
+
function rgbToColor(rgb) {
|
|
1686
|
+
const rgbPattern = /^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/;
|
|
1687
|
+
const rgbaPattern = /^rgba\((\d+),\s*(\d+),\s*(\d+),\s*([\d.]+)\)$/;
|
|
1688
|
+
let matches;
|
|
1689
|
+
if ((matches = rgb.match(rgbPattern))) {
|
|
1690
|
+
return [
|
|
1691
|
+
parseInt(matches[1], 10),
|
|
1692
|
+
parseInt(matches[2], 10),
|
|
1693
|
+
parseInt(matches[3], 10),
|
|
1694
|
+
];
|
|
1695
|
+
}
|
|
1696
|
+
else if ((matches = rgb.match(rgbaPattern))) {
|
|
1697
|
+
return [
|
|
1698
|
+
parseInt(matches[1], 10),
|
|
1699
|
+
parseInt(matches[2], 10),
|
|
1700
|
+
parseInt(matches[3], 10),
|
|
1701
|
+
parseFloat(matches[4]),
|
|
1702
|
+
];
|
|
1703
|
+
}
|
|
1704
|
+
throw new Error(`The '${rgb}' Is not valid rgb`);
|
|
1705
|
+
}
|
|
1706
|
+
function colorObjectToColor({ r, g, b, a }) {
|
|
1707
|
+
return [r, g, b, ...(a !== undefined ? [a] : [])];
|
|
1708
|
+
}
|
|
1709
|
+
function colorToRGB(array) {
|
|
1710
|
+
return `rgb(${array.join(',')})`;
|
|
1711
|
+
}
|
|
1712
|
+
|
|
1713
|
+
function linearInterpolation(input, input1, output1, input2, output2) {
|
|
1714
|
+
if (typeof output1 === 'number' && typeof output2 === 'number') {
|
|
1715
|
+
return (output1 + ((input - input1) / (input2 - input1)) * (output2 - output1));
|
|
1716
|
+
}
|
|
1717
|
+
try {
|
|
1718
|
+
const outputColor1 = toColor(output1);
|
|
1719
|
+
const outputColor2 = toColor(output2);
|
|
1720
|
+
return colorToRGB(outputColor1.map((val, index) => {
|
|
1721
|
+
return Math.ceil(linearInterpolation(input, input1, val, input2, outputColor2[index]));
|
|
1722
|
+
}));
|
|
1723
|
+
}
|
|
1724
|
+
catch (er) {
|
|
1725
|
+
console.log(er);
|
|
1726
|
+
}
|
|
1727
|
+
throw new Error('Unsupported output type for linear interpolation.');
|
|
1728
|
+
}
|
|
1729
|
+
function interpolate([interpolation, input, ...stops]) {
|
|
1730
|
+
if (stops.length < 2) {
|
|
1731
|
+
throw new Error('At least two stops are required');
|
|
1732
|
+
}
|
|
1733
|
+
if (typeof input !== 'number') {
|
|
1734
|
+
throw new Error('Input must be a number.');
|
|
1735
|
+
}
|
|
1736
|
+
if (stops.length < 2 || stops.length % 2 !== 0) {
|
|
1737
|
+
throw new Error('Invalid stops provided.');
|
|
1738
|
+
}
|
|
1739
|
+
for (let i = 0; i < stops.length - 2; i += 2) {
|
|
1740
|
+
const stopInput1 = stops[i];
|
|
1741
|
+
const stopOutput1 = stops[i + 1];
|
|
1742
|
+
const stopInput2 = stops[i + 2];
|
|
1743
|
+
const stopOutput2 = stops[i + 3];
|
|
1744
|
+
if (input >= stopInput1 && input <= stopInput2) {
|
|
1745
|
+
if (interpolation[0] === 'linear') {
|
|
1746
|
+
return linearInterpolation(input, stopInput1, stopOutput1, stopInput2, stopOutput2);
|
|
1747
|
+
}
|
|
1748
|
+
// else if (interpolation[0] === 'exponential') {
|
|
1749
|
+
// const base = interpolation[1];
|
|
1750
|
+
// return exponentialInterpolation(
|
|
1751
|
+
// input,
|
|
1752
|
+
// base,
|
|
1753
|
+
// stopInput1,
|
|
1754
|
+
// stopOutput1,
|
|
1755
|
+
// stopInput2,
|
|
1756
|
+
// stopOutput2,
|
|
1757
|
+
// );
|
|
1758
|
+
// }
|
|
1759
|
+
}
|
|
1760
|
+
}
|
|
1761
|
+
throw new Error('Invalid interpolation type.');
|
|
1762
|
+
}
|
|
1763
|
+
|
|
1764
|
+
const interpolationExpressions = {
|
|
1765
|
+
step,
|
|
1766
|
+
interpolate,
|
|
1767
|
+
};
|
|
1768
|
+
|
|
1769
|
+
function isExpression(value) {
|
|
1770
|
+
if (Array.isArray(value)) {
|
|
1771
|
+
const [lookup, ...cases] = value;
|
|
1772
|
+
const l = lookup;
|
|
1773
|
+
return (typeof l === 'string' &&
|
|
1774
|
+
l !== 'literal' &&
|
|
1775
|
+
l in expressions &&
|
|
1776
|
+
cases.length > 0);
|
|
1777
|
+
}
|
|
1778
|
+
return false;
|
|
1779
|
+
}
|
|
1780
|
+
const expressions = {
|
|
1781
|
+
...mathExpressions,
|
|
1782
|
+
...typeExpressions,
|
|
1783
|
+
...stringExpressions,
|
|
1784
|
+
...lookupExpressions,
|
|
1785
|
+
...decisionExpressions,
|
|
1786
|
+
...interpolationExpressions,
|
|
1787
|
+
};
|
|
1788
|
+
function evaluate(expression, data = {}) {
|
|
1219
1789
|
const [name, ...args] = expression;
|
|
1220
1790
|
const expressionFun = expressions[name];
|
|
1221
1791
|
if (expressionFun) {
|
|
1222
|
-
return expressionFun(
|
|
1792
|
+
return expressionFun(args.map((arg) => (isExpression(arg) ? evaluate(arg, data) : arg)), data);
|
|
1223
1793
|
}
|
|
1224
|
-
|
|
1794
|
+
throw new Error(`Expression "${name}" is not supported.`);
|
|
1225
1795
|
}
|
|
1796
|
+
|
|
1226
1797
|
function createPropertyExpressionCb(expression) {
|
|
1227
1798
|
return (feature) => {
|
|
1228
|
-
|
|
1799
|
+
const properties = feature.properties;
|
|
1800
|
+
if (properties) {
|
|
1801
|
+
return evaluate(expression, properties);
|
|
1802
|
+
}
|
|
1803
|
+
return false;
|
|
1229
1804
|
};
|
|
1230
1805
|
}
|
|
1231
1806
|
const excludeExpressionList = ['iconSize', 'iconAnchor'];
|
|
@@ -1372,32 +1947,43 @@ function createPropertiesPaint(propertiesPaint) {
|
|
|
1372
1947
|
return mask;
|
|
1373
1948
|
};
|
|
1374
1949
|
}
|
|
1375
|
-
function expressionCallback(paint, defaultPaint,
|
|
1950
|
+
function expressionCallback({ paint, defaultPaint, }) {
|
|
1376
1951
|
const expressionCallback = createExpressionCallback(paint);
|
|
1377
1952
|
if (expressionCallback) {
|
|
1378
1953
|
const expressionPaintCb = (feature) => {
|
|
1379
|
-
return preparePaint(
|
|
1954
|
+
return preparePaint({
|
|
1955
|
+
paint: expressionCallback(feature),
|
|
1956
|
+
defaultPaint,
|
|
1957
|
+
});
|
|
1380
1958
|
};
|
|
1381
|
-
expressionPaintCb.paint = paint;
|
|
1959
|
+
expressionPaintCb.paint = finalizePaint({ paint, defaultPaint });
|
|
1382
1960
|
return expressionPaintCb;
|
|
1383
1961
|
}
|
|
1962
|
+
return finalizePaint({ paint, defaultPaint });
|
|
1963
|
+
}
|
|
1964
|
+
function finalizePaint({ paint, defaultPaint }) {
|
|
1965
|
+
var _a;
|
|
1384
1966
|
let newPaint = { ...defaultPaint };
|
|
1385
1967
|
newPaint = { ...newPaint, ...paint };
|
|
1386
|
-
newPaint.fill = newPaint.fill !==
|
|
1968
|
+
newPaint.fill = (_a = newPaint.fill) !== null && _a !== void 0 ? _a : true;
|
|
1387
1969
|
newPaint.stroke =
|
|
1388
1970
|
newPaint.stroke !== undefined
|
|
1389
1971
|
? newPaint.stroke
|
|
1390
1972
|
: !newPaint.fill || !!(newPaint.strokeColor || newPaint.strokeOpacity);
|
|
1391
1973
|
return newPaint;
|
|
1392
1974
|
}
|
|
1393
|
-
function preparePaint(paint, defaultPaint, getPaintFunctions) {
|
|
1975
|
+
function preparePaint({ paint, defaultPaint, getPaintFunctions, }) {
|
|
1394
1976
|
if (!paint) {
|
|
1395
1977
|
throw new Error('paint is empty');
|
|
1396
1978
|
}
|
|
1397
1979
|
let newPaint = { ...defaultPaint };
|
|
1398
1980
|
if (isPaintCallback(paint)) {
|
|
1399
1981
|
const getPaintFunction = (feature) => {
|
|
1400
|
-
const getPaint = preparePaint(
|
|
1982
|
+
const getPaint = preparePaint({
|
|
1983
|
+
paint: paint(feature),
|
|
1984
|
+
defaultPaint,
|
|
1985
|
+
getPaintFunctions,
|
|
1986
|
+
});
|
|
1401
1987
|
getPaint.type = paint.type;
|
|
1402
1988
|
return getPaint;
|
|
1403
1989
|
};
|
|
@@ -1406,20 +1992,28 @@ function preparePaint(paint, defaultPaint, getPaintFunctions) {
|
|
|
1406
1992
|
}
|
|
1407
1993
|
else if (isPropertiesPaint(paint)) {
|
|
1408
1994
|
return (feature) => {
|
|
1409
|
-
return preparePaint(
|
|
1995
|
+
return preparePaint({
|
|
1996
|
+
paint: createPropertiesPaint(paint)(feature),
|
|
1997
|
+
defaultPaint,
|
|
1998
|
+
getPaintFunctions,
|
|
1999
|
+
});
|
|
1410
2000
|
};
|
|
1411
2001
|
}
|
|
1412
2002
|
else if (paint.type === 'get-paint') {
|
|
1413
2003
|
const getPaint = updatePaintOptionFromCallback(paint, getPaintFunctions);
|
|
1414
2004
|
if (getPaint) {
|
|
1415
|
-
newPaint = preparePaint(
|
|
2005
|
+
newPaint = preparePaint({
|
|
2006
|
+
paint: getPaint,
|
|
2007
|
+
defaultPaint,
|
|
2008
|
+
getPaintFunctions,
|
|
2009
|
+
});
|
|
1416
2010
|
}
|
|
1417
2011
|
}
|
|
1418
2012
|
else if (paint.type === 'icon') {
|
|
1419
2013
|
return paint;
|
|
1420
2014
|
}
|
|
1421
2015
|
else {
|
|
1422
|
-
newPaint = expressionCallback(paint, defaultPaint
|
|
2016
|
+
newPaint = expressionCallback({ paint, defaultPaint });
|
|
1423
2017
|
}
|
|
1424
2018
|
if (isPaintCallback(newPaint)) {
|
|
1425
2019
|
return newPaint;
|
|
@@ -3027,10 +3621,18 @@ class WebMapLayers extends WebMapMain {
|
|
|
3027
3621
|
};
|
|
3028
3622
|
if (!options.nativePaint) {
|
|
3029
3623
|
if (this.options.paint) {
|
|
3030
|
-
options.paint = preparePaint(
|
|
3624
|
+
options.paint = preparePaint({
|
|
3625
|
+
paint: options.paint || {},
|
|
3626
|
+
defaultPaint: this.options.paint,
|
|
3627
|
+
getPaintFunctions: this.getPaintFunctions,
|
|
3628
|
+
});
|
|
3031
3629
|
}
|
|
3032
3630
|
if (options.selectedPaint && this.options.selectedPaint) {
|
|
3033
|
-
options.selectedPaint = preparePaint(
|
|
3631
|
+
options.selectedPaint = preparePaint({
|
|
3632
|
+
paint: options.selectedPaint,
|
|
3633
|
+
defaultPaint: this.options.selectedPaint,
|
|
3634
|
+
getPaintFunctions: this.getPaintFunctions,
|
|
3635
|
+
});
|
|
3034
3636
|
}
|
|
3035
3637
|
}
|
|
3036
3638
|
}
|