<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Including socketNotificationReceived in getDom function]]></title><description><![CDATA[<p dir="auto">Hi! I’m trying to hack down the google maps modules. I made a node_helper.js to capture the latitude and longitude of desired location, using url.</p>
<p dir="auto">the code of main file looks like this</p>
<pre><code>getDom: function() {
       
       
		var wrapper = document.createElement("div");
        wrapper.setAttribute("id", "map");

        wrapper.style.height = this.config.height;
        wrapper.style.width = this.config.width;

        var script = document.createElement("script");
        script.type = "text/javascript";
        script.src = "https://maps.googleapis.com/maps/api/js?key=" + this.config.key;
        document.body.appendChild(script);
        script.onload = function () {
            var map = new google.maps.Map(document.getElementById("map"), {
            	zoom: 13,
            	center: {
            		lat: lat,
            		lng: lng
            	}
            });

            var trafficLayer = new google.maps.TrafficLayer();
            trafficLayer.setMap(map);
        };

		return wrapper;
	}

</code></pre>
<p dir="auto">The latitude and longitude is stored in payload. All I require is ho to use socketNotificationReceived to parse both values as “lat” and “long” in script??</p>
]]></description><link>https://forum.magicmirror.builders/topic/5394/including-socketnotificationreceived-in-getdom-function</link><generator>RSS for Node</generator><lastBuildDate>Sat, 18 Apr 2026 11:05:05 GMT</lastBuildDate><atom:link href="https://forum.magicmirror.builders/topic/5394.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 30 Oct 2017 20:45:19 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Including socketNotificationReceived in getDom function on Wed, 01 Nov 2017 10:44:15 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/yours.mukul" aria-label="Profile: yours.mukul">@<bdi>yours.mukul</bdi></a><br />
I think it is not good to put the noti into <code>start()</code> of <code>node_helper.js</code>.<br />
Because after finishing module loaded and DOM created, <code>updateDOM()</code> would be working properly, but your code tried too early.<br />
As you’ve said, you had your code in <code>node_helper.js</code> to get REAL latitude &amp; longitude, isn’t it? My code was just an example. Send your REAL lat &amp; lng to main module when your node_helper code gathers real target values.</p>
]]></description><link>https://forum.magicmirror.builders/post/30487</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/30487</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Wed, 01 Nov 2017 10:44:15 GMT</pubDate></item><item><title><![CDATA[Reply to Including socketNotificationReceived in getDom function on Wed, 01 Nov 2017 10:09:51 GMT]]></title><description><![CDATA[<p dir="auto">@Sean<br />
node_helper.js</p>
<pre><code>var NodeHelper = require("node_helper");
module.exports = NodeHelper.create({
start: function() {

var geo = {
  lat: 12.34567,
  lng: 23.45678
}
this.sendSocketNotification("REFRESH_GEO", geo);
}
}
);
</code></pre>
<p dir="auto">main.js</p>
<pre><code>/* global Module */

/* Magic Mirror
 * Module: MMM-GoogleMapsTraffic
 *
 * By Victor Mora
 * MIT Licensed.
 */

Module.register("MMM-GoogleMapsTraffic", {
       start: function(){
  this.geo = {
    lat: 0, //default latitude
    lng: 0 //default longitude
  }
     },
socketNotificationReceived: function(noti, payload) {
  console.log("NOTIFICATION IS FIRED:", noti)
  if (noti == "REFRESH_GEO") {
    console.log("PAYLOAD IS TREANFERED:", payload)
    this.geo.lat = payload.lat,
    this.geo.lng = payload.lng
    console.log("I'LL UPDATE DOM BY REFRESHED GEO")
    this.updateDom();
  }
},
	getDom: function() {
        var lat = this.geo.lat;
        var lng = this.geo.lng;

		var wrapper = document.createElement("div");
        wrapper.setAttribute("id", "map");

        wrapper.style.height = this.config.height;
        wrapper.style.width = this.config.width;

        var script = document.createElement("script");
        script.type = "text/javascript";
        script.src = "https://maps.googleapis.com/maps/api/js?key=" + this.config.key;
        document.body.appendChild(script);

        script.onload = function () {
            var map = new google.maps.Map(document.getElementById("map"), {
            	zoom: 13,
            	center: {
            		lat: lat,
            		lng: lng
            	}
            });

            var trafficLayer = new google.maps.TrafficLayer();
            trafficLayer.setMap(map);
        };

		return wrapper;
	}

});
</code></pre>
]]></description><link>https://forum.magicmirror.builders/post/30486</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/30486</guid><dc:creator><![CDATA[yours.mukul]]></dc:creator><pubDate>Wed, 01 Nov 2017 10:09:51 GMT</pubDate></item><item><title><![CDATA[Reply to Including socketNotificationReceived in getDom function on Wed, 01 Nov 2017 08:09:10 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/yours.mukul" aria-label="Profile: yours.mukul">@<bdi>yours.mukul</bdi></a> said in <a href="/post/30479">Including socketNotificationReceived in getDom function</a>:</p>
<blockquote>
<p dir="auto">@Sean said in <a href="/post/30435">Including socketNotificationReceived in getDom function</a>:</p>
<blockquote>
<p dir="auto">var lat = this.geo.lat<br />
var lng = this.geo.lng</p>
</blockquote>
<p dir="auto">not working, it always shows up 0,0 latitude and longitude…</p>
</blockquote>
<p dir="auto">It means, your <code>socketNotificationReceived()</code> in module is not working properly. Try this.</p>
<pre><code class="language-js">socketNotificationReceived: function(noti, payload) {
  console.log("NOTIFICATION IS FIRED:", noti)
  if (noti == "REFRESH_GEO") {
    console.log("PAYLOAD IS TREANFERED:", payload)
    this.geo.lat = payload.lat
    this.geo.lng = payload.lng
    console.log("I'LL UPDATE DOM BY REFRESHED GEO")
    this.updateDom()
  }
},
</code></pre>
<p dir="auto">See how the log says. Check correct Socket Notification is fired with correct payload. If not, check your <code>this.sendSocketNotification()</code> in <code>node_helper.js</code></p>
]]></description><link>https://forum.magicmirror.builders/post/30480</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/30480</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Wed, 01 Nov 2017 08:09:10 GMT</pubDate></item><item><title><![CDATA[Reply to Including socketNotificationReceived in getDom function on Wed, 01 Nov 2017 07:44:03 GMT]]></title><description><![CDATA[<p dir="auto">@Sean said in <a href="/post/30435">Including socketNotificationReceived in getDom function</a>:</p>
<blockquote>
<p dir="auto">var lat = this.geo.lat<br />
var lng = this.geo.lng</p>
</blockquote>
<p dir="auto">not working, it always shows up 0,0 latitude and longitude…</p>
]]></description><link>https://forum.magicmirror.builders/post/30479</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/30479</guid><dc:creator><![CDATA[yours.mukul]]></dc:creator><pubDate>Wed, 01 Nov 2017 07:44:03 GMT</pubDate></item><item><title><![CDATA[Reply to Including socketNotificationReceived in getDom function on Tue, 31 Oct 2017 09:14:23 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/yours.mukul" aria-label="Profile: yours.mukul">@<bdi>yours.mukul</bdi></a><br />
try this</p>
<p dir="auto">in your node_helper.js</p>
<pre><code>var geo = {
  lat: 12.34567
  lng: 23.45678
}
this.sendSocketNotification("REFRESH_GEO", geo)
</code></pre>
<p dir="auto">in your Main Module</p>
<pre><code>start: function(){
  this.geo = {
    lat: 0, //default latitude
    lng: 0, //default longitude
  }
},

socketNotificationReceived: function(noti, payload) {
  if (noti == "REFRESH_GEO") {
    this.geo.lat = payload.lat
    this.geo.lng = payload.lng
    this.updateDom()
  }
},

getDom: function() {
  var lat = this.geo.lat
  var lng = this.geo.lng

  var wrapper = ...
},
</code></pre>
]]></description><link>https://forum.magicmirror.builders/post/30435</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/30435</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Tue, 31 Oct 2017 09:14:23 GMT</pubDate></item><item><title><![CDATA[Reply to Including socketNotificationReceived in getDom function on Tue, 31 Oct 2017 01:58:02 GMT]]></title><description><![CDATA[<p dir="auto">@Sean getDom() in Maps.js</p>
]]></description><link>https://forum.magicmirror.builders/post/30425</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/30425</guid><dc:creator><![CDATA[yours.mukul]]></dc:creator><pubDate>Tue, 31 Oct 2017 01:58:02 GMT</pubDate></item><item><title><![CDATA[Reply to Including socketNotificationReceived in getDom function on Mon, 30 Oct 2017 23:46:49 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/yours.mukul" aria-label="Profile: yours.mukul">@<bdi>yours.mukul</bdi></a><br />
<code>getDom()</code> in <code>node_helper.js</code>?</p>
]]></description><link>https://forum.magicmirror.builders/post/30419</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/30419</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Mon, 30 Oct 2017 23:46:49 GMT</pubDate></item></channel></rss>