javascript - 如何通过管道将文件传输到 eager.io

标签 javascript openstreetmap keen-io

我有这个程序:

var planetStream = require('../../');
var app = require('http').createServer(handler);
var io = require('socket.io')(app);
var fs = require('fs');

app.listen(8000);

function handler (req, res) {
  fs.readFile(__dirname + '/index.html',
  function (err, data) {
    if (err) {
      res.writeHead(500);
      return res.end('Error loading index.html');
    }

    res.writeHead(200);
    res.end(data);
  });
}

var diffs = planetStream();

var buildings = diffs
.map(JSON.parse)
.filter(function (x) {
  return x.action === 'create' && x.type === 'way' &&
    x.tags.building;
});

buildings.onValue(function (x) {
  console.log(x);
  io.emit('buildings', x);
});

对于数据监控,我需要在keen.io中进行管道传输。有人知道如何做到这一点或以前做过吗?

此致

安德烈

最佳答案

嗯,我找到了答案。 要将日期传输到 eager.io,我们需要在 HTML 文件中实现所有代码。就我而言,它是index.html。

首先我们需要将此代码放在 </head> 之前:

<script type="text/javascript">
  !function(a,b){a("Keen","https://d26b395fwzu5fz.cloudfront.net/3.4.0-rc/keen.min.js",b)}(function(a,b,c){var d,e,f;c["_"+a]={},c[a]=function(b){c["_"+a].clients=c["_"+a].clients||{},c["_"+a].clients[b.projectId]=this,this._config=b},c[a].ready=function(b){c["_"+a].ready=c["_"+a].ready||[],c["_"+a].ready.push(b)},d=["addEvent","setGlobalProperties","trackExternalLink","on"];for(var g=0;g<d.length;g++){var h=d[g],i=function(a){return function(){return this["_"+a]=this["_"+a]||[],this["_"+a].push(arguments),this}};c[a].prototype[h]=i(h)}e=document.createElement("script"),e.async=!0,e.src=b,f=document.getElementsByTagName("script")[0],f.parentNode.insertBefore(e,f)},this);
</script> 

我们需要在 <body></body> 中实现这段代码:

var client = new Keen({
  projectId: "YOUR_PROJECT_ID",
  writeKey: "YOUR_WRITE_KEY"
});

project_ID 和 Your_Write_key 可以在启动新项目后在 eager.io 中找到。 最后一步是实现这个功能:

client.addEvent("osm_20_01", { key: data.nodes });

osm_20_01 是您将在项目中找到的事件集合的名称。 键是值的名称。 “data.nodes”是值。

关于javascript - 如何通过管道将文件传输到 eager.io,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34872464/

相关文章:

keen-io - Keen IO 仪表板 JSON 导入/导出

node.js - 是否可以在 "keen"对象中添加除标准属性之外的其他用户定义属性?

javascript - 使用 html 日期的 jquery/javascript 显示链接

javascript - 从对象数组中,将两个属性的值提取到数组中

javascript - React-Native 嵌套平面列表

openstreetmap - 大面积启动OSRM服务器

keen-io - 如何使用Keen io扩展表行数据?

javascript - image.onload 函数 - 为什么它不起作用?

javascript - Openlayers 在 OpenStreetMaps 图层上圈出多边形

Java,JXMapKit : How to catch java.net.UnknownHostException