Running NPM mapbox-map-image-export

只谈情不闲聊 提交于 2019-12-11 16:49:52

问题


Im new to NPM/Node and am trying to run a seeingly simple command but am having trouble.

Im using VS Code and have used the terminal to clone the GIT repo. Then 'npm install'.

I am trying to run the command in the documentation 'export MAPBOX_TOKEN=YOUR_MAPBOX_API_PUBLIC_TOKEN'

Based on the instructions on the NPM page https://www.npmjs.com/package/mapbox-map-image-export

To do this I type in 'node' then the command above. However I just get three dots appear?


回答1:


In Unix systems, export is a Shell built-in command used to mark a variable for automatic export to the environment of subsequently executed commands. The Windows (MS-DOS) equivalent command is set.

So, to set the Mapbox token in Windows, just open a command prompt and execute:

set MAPBOX_TOKEN=YOUR_MAPBOX_API_PUBLIC_TOKEN

You can then run mapbox-map-image-export in the same command prompt session, like this:

export-map mapbox://styles/mapbox/streets-v9 -w=11in -h=8.5in -b=-7.1354,57.9095,-6.1357,58.516 -t=%MAPBOX_TOKEN% -o=lewis.png

Note that in Windows, %NAME% is used to get a variable value, so it's %MAPBOX_TOKEN% (and not $MAPBOX_TOKEN).

You can also specify the Mapbox token directly in the export-map command, without setting an environment variable, e.g.:

export-map mapbox://styles/mapbox/streets-v9 -w=11in -h=8.5in -b=-7.1354,57.9095,-6.1357,58.516 -t=YOUR_MAPBOX_API_PUBLIC_TOKEN -o=lewis.png



回答2:


The command (export MAPBOX_TOKEN=YOUR_MAPBOX_API_PUBLIC_TOKEN) you saw in the documentation aims at being run in a shell, not the node REPL.

Its job is to configure the token which can then be used by this package CLI. Technically it means:

Define an environment variable accessible to all the upcoming processes named MAPBOX_TOKEN with the value YOUR_MAPBOX_API_PUBLIC_TOKEN.

Executing it in a shell will enable the export-map command to grab it through process.env.



来源:https://stackoverflow.com/questions/45758253/running-npm-mapbox-map-image-export

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!