gmaps experiment + earthquake experiment

http://flows.nodered.org/flow/1aab1d44e387da96b3fe and http://flows.nodered.org/flow/edca3ef3e88a00e7e082

[{"id":"54651cc0.ab9ae4","type":"websocket-listener","path":"/ws/location","wholemsg":"false"},{"id":"8f5e4376.70a1c","type":"http request","name":"","method":"GET","url":"http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_day.csv","x":133,"y":138.00003051757812,"z":"2b17111e.d4e8ee","wires":[["acf090cf.530f7"]]},{"id":"755e9773.8aa168","type":"inject","name":"","topic":"","payload":"","payloadType":"date","repeat":"10","crontab":"","once":false,"x":131,"y":215.00003051757812,"z":"2b17111e.d4e8ee","wires":[["8f5e4376.70a1c"]]},{"id":"b297f439.4d6808","type":"debug","name":"","active":true,"console":"false","complete":"false","x":633,"y":109,"z":"2b17111e.d4e8ee","wires":[]},{"id":"acf090cf.530f7","type":"function","name":"","func":"var _csv = msg\n  .payload\n  .replace('latitude','lat').replace('longitude','lng')\n  .split(\"\\n\");\nvar _columns = _csv[0].split(',');\nvar _l1 = _csv.length-1;\nvar _l2 = _columns.length;\nvar _payload = [];\n\nfor(var i1 = 1; i1<_l1;i1++){\n  var _o = {};\n  var _match = _csv[i1].match(/(\\\"[^\\\"]+\\\")/ig)[0];\n  if(_match)\n    _csv[i1] = _csv[i1].replace(/(\\\"[^\\\"]+\\\")/ig,_match.replace(',','&sbquo;'));\n\n  var __csv = _csv[i1].split(',');\n\n  for(var i2 = 1; i2<_l2;i2++){\n    _o[_columns[i2]] = __csv[i2];\n  }\n  _payload.push(_o);\n}\nmsg.payload = _payload;\nreturn msg;","outputs":1,"x":283,"y":374.0000305175781,"z":"2b17111e.d4e8ee","wires":[["b297f439.4d6808","9c1355d3.63eca8"]]},{"id":"48bb5eab.b744a","type":"websocket out","name":"","server":"54651cc0.ab9ae4","x":685,"y":403.0000305175781,"z":"2b17111e.d4e8ee","wires":[]},{"id":"9c1355d3.63eca8","type":"function","name":"","func":"// The received message is stored in 'msg'\n// It will have at least a 'payload' property:\n//   console.log(msg.payload);\n// The 'context' object is available to store state\n// between invocations of the function\n//   context = {};\ncontext.global.location = msg.payload;\n\nreturn msg;","outputs":1,"x":446,"y":377.0000305175781,"z":"2b17111e.d4e8ee","wires":[["48bb5eab.b744a"]]},{"id":"7c7a18f2.8385e8","type":"websocket in","name":"","server":"54651cc0.ab9ae4","x":275,"y":437.0000305175781,"z":"2b17111e.d4e8ee","wires":[["2bbe8bac.d44174"]]},{"id":"2bbe8bac.d44174","type":"function","name":"","func":"// The received message is stored in 'msg'\n// It will have at least a 'payload' property:\n//   console.log(msg.payload);\n// The 'context' object is available to store state\n// between invocations of the function\n//   context = {};\n\nmsg.payload = context.global.location;\nreturn msg;","outputs":1,"x":448,"y":443.0000305175781,"z":"2b17111e.d4e8ee","wires":[["48bb5eab.b744a"]]},{"id":"67b3179e.984ce8","type":"template","name":"","field":"","template":"<!DOCTYPE html>\n<html>\n<head>\n  <title>Owntracks & Node-Red Live Map</title>\n  <script type=\"text/javascript\" src=\"http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js\"></script>\n  <script type=\"text/javascript\" src=\"http://maps.google.com/maps/api/js?sensor=true\"></script>\n  <script type=\"text/javascript\" src=\"http://yourjavascript.com/4594301102/gmaps.js\"></script>\n \n  <style type=\"text/css\" media=\"screen\">\n    #map {\n      position:absolute;\n      top: 0; bottom: 0; left: 0; right: 0;\n    }\n  </style>\n</head>\n<body>\n \n  <div id=\"map\"></div>\n  <script type=\"text/javascript\">\n  var socketaddy = \"ws://\"+window.location.host+\"/ws/location\";\n    var map;\n    var sock;\n    $(document).ready(function(){\n      \n      map = new GMaps({\n        div: '#map',\n        lat: -12.043333,\n        lng: -77.028333\n      });\n      \n      \n      sock = new WebSocket(socketaddy);\n      sock.onopen = function(){ console.log(\"Connected websocket\");\n          console.log(\"Sending ping..\");\n          sock.send(\"Ping!\");\n          console.log(\"Ping sent..\");\n      };\n      sock.onerror = function(){ console.log(\"Websocket error\"); };\n      sock.onmessage = function(evt){\n        var latlng = JSON.parse(evt.data);\n        var lastQ = latlng.length-1;\n        var array = $.map(latlng, function(el) {\n            return [[el.lat, el.lng]];\n        });\n        \n        map.removeMarkers();\n        map.removePolylines();\n        // console.log(\"Got marker at \" + latlng[0].lat + \", \" + latlng[0].lng, latlng);\n        map.setZoom(4);\n        map.setCenter(latlng[lastQ].lat, latlng[lastQ].lng);\n        var markers = [];\n        // map.addMarkers(latlng);\n        jQuery.each(latlng,function(k,v){\n            var position = new google.maps.LatLng(v.lat,v.lng);\n            var _marker = new google.maps.Marker({\n                position: position,\n                icon: 'http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld='+((k+1).toString())+'|FF0000|000000',\n                title:'mag:'+v.mag+v.magType+';depth:'+v.depth+';updated:'+v.updated\n            });\n\n            markers.push(_marker);\n        });\n        map.addMarkers(markers);\n        map.drawPolyline({\n          path: array,\n          strokeColor: '#131540',\n          strokeOpacity: 0.6,\n          strokeWeight: 2\n        });\n      }\n    });\n  </script>\n</body>\n</html>","x":477,"y":515.0000305175781,"z":"2b17111e.d4e8ee","wires":[["fc05de98.03fa2"]]},{"id":"fc05de98.03fa2","type":"http response","name":"","x":662,"y":514.0000305175781,"z":"2b17111e.d4e8ee","wires":[]},{"id":"fdced9aa.023128","type":"http in","name":"","url":"/map","method":"get","x":257,"y":519.0000305175781,"z":"2b17111e.d4e8ee","wires":[["67b3179e.984ce8"]]}]
zetxx

Flow Info

created 2 years, 10 months ago

Node Types

Core
  • debug (x1)
  • function (x3)
  • http in (x1)
  • http request (x1)
  • http response (x1)
  • inject (x1)
  • template (x1)
  • websocket in (x1)
  • websocket out (x1)
  • websocket-listener (x1)

Tags

  • google
  • maps
  • earthquake
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option