node.js 应用程序中的 openlayers-3?
openlayers-3 in node.js app?
我有兴趣在 node.js 应用程序中使用 ol3(例如,用于读取 GeoJSON 的 ol.format API)。这是受支持的用例吗?
我问是因为它似乎无法仅通过 运行 npm install openlayers
然后要求它来工作。 var ol3 = require('openlayers')
在寻找 window.navigation
对象的 geolocation
属性 的代码上失败,因为 window.navigation 在 node.js 环境中不存在
TypeError: 无法使用 'in' 运算符在未定义中搜索 'geolocation'
在 /home/me/src/ol3/node_modules/openlayers/dist/ol.js:144:823
在 OPENLAYERS(/home/me/src/ol3/node_modules/openlayers/dist/ol.js:9:22)
在对象。 (/home/me/src/ol3/node_modules/openlayers/dist/ol.js:13:2)
在 Module._compile (module.js:460:26)
在 Object.Module._extensions..js (module.js:478:10)
在 Module.load (module.js:355:32)
在 Function.Module._load (module.js:310:12)
在 Module.require (module.js:365:17)
在要求 (module.js:384:17)
您不能在纯 Node 上下文中使用 OpenLayers 3(但可以 Browserify/WebPack 用于客户端)
您始终可以在 Node 中存根 window
和其他对象,但存根用于测试...
运行 OpenLayers 3 与 PhantomJS(无头浏览器)也是可能的。
我不知道 OpenLayers 是为浏览器以外的其他用途而设计的。
为了获得更多见解,您应该 post 在 OpenLayers 3 dev list 上确认您的问题。
不要完全重复您的 Whosebug 问题!你最好问一些像 "Is openlayers3 designed to only be used in the browser?" 这样的问题,因为 OpenLayers 开发列表实际上是针对开发问题的,而不是关于经典库 usage/simple 如今的帮助。
我有兴趣在 node.js 应用程序中使用 ol3(例如,用于读取 GeoJSON 的 ol.format API)。这是受支持的用例吗?
我问是因为它似乎无法仅通过 运行 npm install openlayers
然后要求它来工作。 var ol3 = require('openlayers')
在寻找 window.navigation
对象的 geolocation
属性 的代码上失败,因为 window.navigation 在 node.js 环境中不存在
TypeError: 无法使用 'in' 运算符在未定义中搜索 'geolocation' 在 /home/me/src/ol3/node_modules/openlayers/dist/ol.js:144:823 在 OPENLAYERS(/home/me/src/ol3/node_modules/openlayers/dist/ol.js:9:22) 在对象。 (/home/me/src/ol3/node_modules/openlayers/dist/ol.js:13:2) 在 Module._compile (module.js:460:26) 在 Object.Module._extensions..js (module.js:478:10) 在 Module.load (module.js:355:32) 在 Function.Module._load (module.js:310:12) 在 Module.require (module.js:365:17) 在要求 (module.js:384:17)
您不能在纯 Node 上下文中使用 OpenLayers 3(但可以 Browserify/WebPack 用于客户端)
您始终可以在 Node 中存根 window
和其他对象,但存根用于测试...
运行 OpenLayers 3 与 PhantomJS(无头浏览器)也是可能的。
我不知道 OpenLayers 是为浏览器以外的其他用途而设计的。
为了获得更多见解,您应该 post 在 OpenLayers 3 dev list 上确认您的问题。
不要完全重复您的 Whosebug 问题!你最好问一些像 "Is openlayers3 designed to only be used in the browser?" 这样的问题,因为 OpenLayers 开发列表实际上是针对开发问题的,而不是关于经典库 usage/simple 如今的帮助。