@tencent-map/lbs-skills 0.0.1 → 0.0.2

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.
Files changed (2) hide show
  1. package/bin/cli.js +42 -16
  2. package/package.json +1 -1
package/bin/cli.js CHANGED
@@ -228,9 +228,7 @@ async function cmdConfig(positional) {
228
228
  case 'get-key': {
229
229
  const key = lib.getKey();
230
230
  if (key) {
231
- const masked = key.length > 8
232
- ? key.slice(0, 4) + '*'.repeat(key.length - 8) + key.slice(-4)
233
- : '****';
231
+ const masked = key.length > 8 ? key.slice(0, 4) + '*'.repeat(key.length - 8) + key.slice(-4) : '****';
234
232
  console.log(`当前 Key: ${masked}`);
235
233
  } else {
236
234
  console.log('未设置 API Key');
@@ -253,7 +251,10 @@ async function cmdConfig(positional) {
253
251
  }
254
252
 
255
253
  async function cmdSearch(args) {
256
- if (args.help) { console.log(HELP_SEARCH); return; }
254
+ if (args.help) {
255
+ console.log(HELP_SEARCH);
256
+ return;
257
+ }
257
258
  if (!args.keywords) fatal('缺少 --keywords 参数');
258
259
 
259
260
  const result = await lib.searchPOI({
@@ -285,7 +286,10 @@ async function cmdSearch(args) {
285
286
  }
286
287
 
287
288
  async function cmdGeocode(args) {
288
- if (args.help) { console.log(HELP_GEOCODE); return; }
289
+ if (args.help) {
290
+ console.log(HELP_GEOCODE);
291
+ return;
292
+ }
289
293
  if (!args.address) fatal('缺少 --address 参数');
290
294
 
291
295
  const result = await lib.geocode({ address: args.address });
@@ -302,19 +306,26 @@ async function cmdGeocode(args) {
302
306
  }
303
307
 
304
308
  async function cmdNearby(args) {
305
- if (args.help) { console.log(HELP_NEARBY); return; }
309
+ if (args.help) {
310
+ console.log(HELP_NEARBY);
311
+ return;
312
+ }
313
+
314
+ const key = lib.ensureKey();
306
315
 
307
316
  let keyword = args.keyword;
308
317
  if (!keyword) {
309
318
  // 组合 location + keywords 形成搜索关键词
310
319
  if (!args.location && !args.keywords) {
311
- fatal('缺少参数。用法: tmap-lbs nearby --location <位置> --keywords <类别>\n 或: tmap-lbs nearby --keyword <完整关键词>');
320
+ fatal(
321
+ '缺少参数。用法: tmap-lbs nearby --location <位置> --keywords <类别>\n 或: tmap-lbs nearby --keyword <完整关键词>'
322
+ );
312
323
  }
313
324
  keyword = (args.location || '') + (args.keywords || '');
314
325
  }
315
326
 
316
327
  const encoded = encodeURIComponent(keyword);
317
- const url = `https://mapapi.qq.com/web/claw/nearby-search.html?keyword=${encoded}`;
328
+ const url = `https://mapapi.qq.com/web/claw/nearby-search.html?keyword=${encoded}&key=${encodeURIComponent(key)}`;
318
329
 
319
330
  console.log(`\n🔍 已生成周边搜索链接:\n`);
320
331
  console.log(` ${url}\n`);
@@ -323,14 +334,20 @@ async function cmdNearby(args) {
323
334
  }
324
335
 
325
336
  async function cmdRoute(args) {
326
- if (args.help) { console.log(HELP_ROUTE); return; }
337
+ if (args.help) {
338
+ console.log(HELP_ROUTE);
339
+ return;
340
+ }
327
341
  if (!args.origin) fatal('缺少 --origin 参数');
328
342
  if (!args.destination) fatal('缺少 --destination 参数');
329
343
 
330
344
  const mode = args.mode || 'walk';
331
345
  const modeNames = {
332
- walk: '步行', drive: '驾车', cycle: '骑行',
333
- ecycle: '电动车', transit: '公交',
346
+ walk: '步行',
347
+ drive: '驾车',
348
+ cycle: '骑行',
349
+ ecycle: '电动车',
350
+ transit: '公交',
334
351
  };
335
352
 
336
353
  if (!modeNames[mode]) {
@@ -396,11 +413,17 @@ async function cmdRoute(args) {
396
413
  }
397
414
 
398
415
  async function cmdTravel(args) {
399
- if (args.help) { console.log(HELP_TRAVEL); return; }
416
+ if (args.help) {
417
+ console.log(HELP_TRAVEL);
418
+ return;
419
+ }
400
420
  if (!args.city) fatal('缺少 --city 参数');
401
421
  if (!args.interests) fatal('缺少 --interests 参数');
402
422
 
403
- const interests = args.interests.split(',').map((s) => s.trim()).filter(Boolean);
423
+ const interests = args.interests
424
+ .split(',')
425
+ .map((s) => s.trim())
426
+ .filter(Boolean);
404
427
  const recommend = args.recommend || '';
405
428
 
406
429
  console.log(`\n🗺 正在获取景点坐标...\n`);
@@ -424,12 +447,12 @@ async function cmdTravel(args) {
424
447
  if (spots.length === 0) fatal('没有成功获取任何景点的坐标');
425
448
 
426
449
  // 生成旅游规划可视化链接
427
- const key = lib.getKey() || '';
450
+ const key = lib.ensureKey();
428
451
  const spotsJSON = JSON.stringify(spots);
429
452
  const params = new URLSearchParams();
430
453
  params.set('spots', spotsJSON);
431
454
  if (recommend) params.set('recommend', recommend);
432
- if (key) params.set('key', key);
455
+ params.set('key', key);
433
456
 
434
457
  const url = `https://mapapi.qq.com/web/claw/travel.html?${params.toString()}`;
435
458
 
@@ -444,7 +467,10 @@ async function cmdTravel(args) {
444
467
  }
445
468
 
446
469
  async function cmdTrail(args) {
447
- if (args.help) { console.log(HELP_TRAIL); return; }
470
+ if (args.help) {
471
+ console.log(HELP_TRAIL);
472
+ return;
473
+ }
448
474
  if (!args.data) fatal('缺少 --data 参数');
449
475
 
450
476
  const encoded = encodeURIComponent(args.data);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tencent-map/lbs-skills",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "腾讯地图位置服务命令行工具,支持 POI 搜索、地理编码、周边搜索、路径规划、旅游规划、轨迹可视化等功能",
5
5
  "bin": {
6
6
  "tmap-lbs": "./bin/cli.js"