我当前的脚本/代码流是 index.js-> doutes.js-> main.ejs
我需要加载与Geotiff相关的模块,并在我的 main中使用其绘图功能。 EJS
。但是,我发现 ejs
不支持代码中的加载模块,因此我需要将geotiff模块加载到我的 index.js.js
或 routes.js 并将功能渲染到 main.ejs
。
我从Google找到了一些示例,并遵循了他们的方法,但不幸的是我无法使其起作用。错误信息不断显示 Geotiff相关的功能Main.ejs未定义
。
我尝试使用的模块的github网站在这里:
您在用法示例中可以看到,它直接需要
georaster,然后在相同的JS代码中构成绘图函数,而在我的情况下,我的绘图代码将在我的 main.ejs
中,其中我不能直接直接直接georaster。
遵循此页面中的方法:
我在 routes.js
中尝试了以下代码
var parse_georaster = require("georaster");
var GeoRasterLayer = require("georaster-layer-for-leaflet");
var getMain = function (req, res) {
res.render('main',{parse_georaster: parse_georaster,GeoRasterLayer: GeoRasterLayer});
};
,但似乎不起作用。我仍然无法在我的 parse_georaster
和 georasterlayer
的功能中使用我的 main.ejs
。
My current scripts/codes flow is index.js->routes.js->main.ejs
I need to load a GeoTiff-related module and use its plotting functions in my main.ejs
. However I find that ejs
does not support loading modules within the code, so I need to load the GeoTiff modules in my index.js
or routes.js
and render the functions to main.ejs
.
I found some examples from Google and followed their methods but unfortunately I couldn't make it work. The error information keeps showing that the GeoTiff-related functions in main.ejs are not defined
.
The github website of the module I try to use is here:
As you can see in the Usage Example it directly require
the georaster and then compose the plot functions in the same js code, whereas in my case my plot codes will be in my main.ejs
where I can not require
the georaster directly.
Following the method in this page:
https://rajuthapa-13222.medium.com/how-to-use-node-packages-on-ejs-html-templating-engine-d51885e91deb
I tried the following codes in my routes.js
var parse_georaster = require("georaster");
var GeoRasterLayer = require("georaster-layer-for-leaflet");
var getMain = function (req, res) {
res.render('main',{parse_georaster: parse_georaster,GeoRasterLayer: GeoRasterLayer});
};
But it seems not working. I still can not use the function of parse_georaster
and GeoRasterLayer
in my main.ejs
.
发布评论