node.js应用程序中的openlayers-3? [英] openlayers-3 in node.js app?

查看:188
本文介绍了node.js应用程序中的openlayers-3?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对在node.js应用程序中使用ol3感兴趣(例如,用于读取GeoJSON的ol.format API).那是受支持的用例吗?

I'm interested in using ol3 in a node.js app (e.g. the ol.format APIs for reading GeoJSON). Is that a supported use case?

我问,因为仅仅运行npm install openlayers然后要求它似乎无法工作. var ol3 = require('openlayers')在正在寻找window.navigation对象的geolocation属性的代码上失败,因为window.navigation在node.js环境中不存在

I ask because it doesn't appear to work by just running npm install openlayers and then requiring it. var ol3 = require('openlayers') fails on code that's looking for the geolocation property of the window.navigation object since the window.navigation doesn't exist in a node.js environment

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)

TypeError: Cannot use 'in' operator to search for 'geolocation' in undefined at /home/me/src/ol3/node_modules/openlayers/dist/ol.js:144:823 at OPENLAYERS (/home/me/src/ol3/node_modules/openlayers/dist/ol.js:9:22) at Object. (/home/me/src/ol3/node_modules/openlayers/dist/ol.js:13:2) at Module._compile (module.js:460:26) at Object.Module._extensions..js (module.js:478:10) at Module.load (module.js:355:32) at Function.Module._load (module.js:310:12) at Module.require (module.js:365:17) at require (module.js:384:17)

推荐答案

您不能在纯Node上下文中使用OpenLayers 3(但可以通过Browserify/WebPack进行客户端使用)

You can't use OpenLayers 3 in purely Node context (but it's possible with Browserify/WebPack for client side use)

您始终可以在Node中对window和其他对象进行存根,但是存根用于测试... 也可以通过PhantomJS(无头浏览器)运行OpenLayers 3.

You can always stub window and other objects in Node but stub is for tests... It's also possible to run OpenLayers 3 with PhantomJS (headless browser).

我不知道OpenLayers是为浏览器以外的其他用途而设计的.

I'm not aware OpenLayers was designed for other uses than browser.

要获取更多见解,您应该在 OpenLayers 3开发人员列表上发布您的问题确认.

To get more insight, you should post your question on the OpenLayers 3 dev list to confirm.

请勿完全重复您的StackOverflow问题!您最好问一下"openlayers3是否设计为仅在浏览器中使用?"之类的问题.因为OpenLayers开发人员列表确实是针对开发人员的问题,而不是如今的经典库使用/简单帮助.

Do not duplicate exactly your StackOverflow question! You'd better ask something like "Is openlayers3 designed to only be used in the browser?" as the OpenLayers dev list is really for dev question and not about classic library usage/simple assistance nowadays.

这篇关于node.js应用程序中的openlayers-3?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆