[英]Running leaflet on nodejs server side
I tried to run leaflet on a nodejs server side without success. 我试图在nodejs服务器端运行传单但没有成功。 I build it with jake as described in the download section, but then, when I require leaflet on a server file, if I start my node server, it crash with this error :
我使用jake构建它,如下载部分所述,但是,当我在服务器文件上需要传单时,如果我启动我的节点服务器,它会崩溃并出现此错误:
ReferenceError: window is not defined
Thanks node, I know it. 谢谢节点,我知道。 But Is there a way to use leaflet on server side ?
但有没有办法在服务器端使用传单? I need it for some operation on a L.geojson ( https://github.com/mapbox/leaflet-pip ) and I can't manage to do it without the "L" reference.
我需要在L.geojson( https://github.com/mapbox/leaflet-pip )上执行某些操作,如果没有“L”参考,我无法做到这一点。
I'll appreciate any help. 我会感激任何帮助。 Thanks.
谢谢。
You can load leaflet in node.js by simulating the browser: 您可以通过模拟浏览器在node.js中加载传单:
// Create globals so leaflet can load
global.window = {
screen: {
devicePixelRatio: 1
}
};
global.document = {
documentElement: {
style: {}
},
getElementsByTagName: function() { return []; },
createElement: function() { return {}; }
};
global.navigator = {
userAgent: 'nodejs',
platform: 'nodejs'
};
global.L = require('leaflet');
I used this in conjunction with Point in Polygon for Leaflet . 我将它与Point in Polygon for Leaflet结合使用。
Vanilla Leaflet does not work in node. 香草单张在节点中不起作用。 I've made a wrapper here: https://github.com/jieter/leaflet-headless
我在这里做了一个包装: https : //github.com/jieter/leaflet-headless
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.