介绍
node-red-web-worldmap-indoor 是一个非常好用的 npm 包,它提供了一个 Web 端的室内地图,可以方便的用于展示室内设备信息、人员位置等信息。
安装
使用 npm
命令进行安装:
npm install node-red-web-worldmap-indoor --save
使用
node-red-web-worldmap-indoor 是基于 Node-RED 的,开发者可以在 Node-RED 的流程编辑器中使用这个 npm 包。
1. 创建 Node-RED 项目
在终端中输入以下命令创建一个全新的 Node-RED 项目:
npm install -g node-red
创建成功后,在终端中输入以下命令启动 Node-RED:
node-red
在浏览器中打开 http://localhost:1880,就可以进入 Node-RED 的编辑器界面了。
2. 安装 node-red-web-worldmap-indoor
在 Node-RED 编辑器界面中,点击右上角的菜单,选择 "Manage palette",在 "Install" 标签页中输入 "node-red-web-worldmap-indoor",点击 "Install" 按钮进行安装。
如果安装不成功,可以在命令行中输入以下命令进行安装:
cd $HOME/.node-red npm install node-red-web-worldmap-indoor
3. 导入示例程序
把以下示例程序导入到 Node-RED 中:
[{"id":"3243043c.66f288","type":"tab","label":"Indoor Map","disabled":false,"info":""},{"id":"dde51e1f.2009d8","type":"inject","z":"3243043c.66f288","name":"","topic":"","payload":"","payloadType":"date","repeat":"2","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":80,"wires":[["ca422fa9.4a82"]]},{"id":"ca422fa9.4a82","type":"function","z":"3243043c.66f288","name":"Random Position","func":"var mapData = {};\nmapData[\"lat\"] = 35.7100625 + 0.005 * Math.random() - 0.0025;\nmapData[\"lon\"] = 139.8107005 + 0.01 * Math.random() - 0.005;\nmapData[\"name\"] = \"Device\" + (Math.floor(Math.random() * 200) + 1);\nmapData[\"status\"] = \"OK\";\n\nmsg.payload = {\n mapData: mapData\n};\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":290,"y":80,"wires":[["3eb136f8.ea2d7a","395b75cc.7a8ed8"]]},{"id":"3eb136f8.ea2d7a","type":"worldmap-indoor","z":"3243043c.66f288","name":"","layer":"","latField":"lat","lonField":"lon","zoom":"","clusterMaxZoom":"","clusterRadius":"","maxPoints":"","showAccuracyCircle":false,"x":480,"y":140,"wires":[["ac7e6bed.d91d28"]]},{"id":"ac7e6bed.d91d28","type":"debug","z":"3243043c.66f288","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":740,"y":140,"wires":[]},{"id":"395b75cc.7a8ed8","type":"debug","z":"3243043c.66f288","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":480,"y":80,"wires":[]}]
导入方法:点击右上角的菜单,选择 "Import", "Clipboard",将以上代码复制到输入框中,点击 "Import",即可导入到 Node-RED 中。
4. 运行示例程序
点击右上角的菜单,选择 "Deploy",点击 "Deploy" 按钮,示例程序即可运行。
在 Node-RED 编辑器的右侧边栏中,可以看到输出的日志信息,把鼠标移到 "Debug" 节点上可查看输出的结果。
结语
node-red-web-worldmap-indoor 是一个功能强大、易用的 npm 包,它提供了快捷的室内地图展示功能,方便企业快速构建内部系统,推广具有广泛的应用前景。
来源:JavaScript中文网 ,转载请注明来源 https://www.javascriptcn.com/post/60055cb581e8991b448da2dc