How to move GEvent.callbackArgs over to V3 - javascript

I have the following code which works under V2 and I am trying to move it over to V3.
The issue seems to be the access to the "this" object which holder the polyline to which the event is being added. (there are many such instantiations on the map so I don't necessary know which one is making the call when I receive the event, I can object the necessary information by passing this through the callbackArgs interface provided in V2)
I have read up on closures but I can't seem to see how I might apply them
GEvent.addListener(this.intLineObj , "click",
GEvent.callbackArgs(this, this.loadComments, null));

I was never able to find an answer to this one. I had to rewrite my code to access everything via an indexed global array. (not really what I wanted to do)

Related

can't pass bound/curried/closure functions from node to browser with puppeteer

I was recently playing with node and puppeteer.
I am facing the issue that if I need to partially apply a function I can't pass it to the the browser because it needs to be serialized, problem is that the arguments bound are lost in the process.
This is something similar to my issue but this only works for very specific case of arrow functions.
How to correctly serialize Javascript curried arrow functions?
EDIT: it works for normal functions as well as pointed in the comment. but trying to serialize a already bound function did not work.
Anybody knows how to get around this problem? What I have been doing is loading a object with the arguments and passing it all with an array of functions with the order.

Why does the Google Maps Map() constructor have side effects?

I've been working a personal Vue project that includes a simple Google map.
While implementing the Maps JS API, I annoyingly kept encountering the ESLint error 'map' is assigned a value but never used. I understand why I'm getting this error—The Map() constructor returns a value that I don't need to do anything with:
const map = new google.maps.Map(el, options)
So I eventually just implemented the solution described in this Stack Overflow answer to bypass the lint rule.
If you're using a poorly designed library where the class constructor has side effects (which it isn't supposed to), and you don't need to do anything with the returned value from the class, I would disable that specific eslint rule for those lines.
However, my question is, why is Google's Map() constructor designed in this way? I have a hard time believing this library would be "poorly designed" but can't see a reason for this implementation.
It not side effect. It's returning instance of it. So you can call further methods on it

How can I get a drawn Object from a map leaflet draw using angular?

I am using angular leaflet, leaflet-draw and I am trying to get a circle (or other drawn object) object to see if a point on the map appears within it overtime. I need to use it in a separate service. How can I access the data for an object already drawn somewhere else in my angular code?
Found the answer. To access a drawn object in the way I was attempting, I had persisted the L.FeatureGroup object in my service. Inside this object is a layersDrawnItems sub-object. This object has a _layers array which contains the list of drawn objects.
They can then be accessed using the leaflet API. I still don't know how I was supposed to find this with the given documentation (unless I missed something completely obvious, which I am assuming I did, given that this would seem to be basic functionality) but if anyone else needs to know, here it is.

Setting s object variables in Tealium

Relatively basic question but I can't find an answer. I've emailed Tealium as well, but thought I'd ask the masses here.
I want to explicitly set something within the s object, in this case s.referrer. When I set it in an extension, it doesn't take. Referrer isn't one of the things I can map directly to, so that's not an option.
I thought I could simply call out an s object assignment statement since I did it once before with s.linkTrackVars and it looked like it worked based on results in the reporting, but now, I decided to go check and the Tealium Web Companion claims there's nothing set there either.
How do I call out, in plain JS, setting something in the s object in Tealium?
This is possibly because since you're running your s-code within a Tealium SiteCatalyst tag, and it's not globally setting s on the window to anything anymore, by default.
If you want to change a particular value, do the following:
Create a new data layer value within the Tealium UI that'll be used to store your value (and generally aid in the graphical mapping)
In your extension, scoped to the tag, set the the value of that data layer value (b.[variable_name])
Create a new mapping within the SiteCatalyst tag and select the SiteCatalyst value to want to map to (referrer in your case). On the other side of the mapping, specify that data layer value you made a couple of steps ago

Find Leaflet map objects present on page, without a variable reference

I have an idea for a browser plugin which would manipulate Leaflet maps on third-party sites. But I'm stuck on a simple thing: I'm not sure how to discover Leaflet map DOM elements on a page, and then access the associated Leaflet map object.
Is $('.leaflet-container') a reliable way to find all map objects?
How to actually access the map object from that object, so I can do something like: $('.leaflet-container').eachLayer(...), which doesn't work.
This question is essentially the same as How can I get a leaflet.js instance using only a DOM object?, but the answer there was a workaround which doesn't help.
Yes, that should be sufficient, although it's not a documented behavior and could at least theoretically change in future versions of Leaflet
There's no way to do this. The reference to the map is owned by the code creating the map, and it could have discarded it or might be storing it in a location you do not have access to. Leaflet itself does not store a reference to the map anywhere where you can access it
On a side note, it is my opinion that you should rather let users of your code explicitly pass references to you, rather than you trying to automatically find references. See for example the inversion of control principle, where the caller supplies dependencies; Law of Demeter is also somewhat applicable - don't pry into other codes internals (unless you really, really have to).
OK, so this is a solution that could work, but it is brittle and limited. If you have a way to more directly find the reference, that's ideal.
I wanted to get a map reference where I do not want to modify upstream code; it's a one-off where brittleness is OK.
I know my map is going to be defined on the window.FOO scope (i.e. it's a global reference) and that it will be in the format map0000 where 0000 is a random number. So I constructed a quick function to scan the global window object's properties for variables matching this pattern.
window[Object.keys(window).find(key => key.substr(0,3) === "map")];
This returns a Leaflet map reference but could break if there is more than one map on the page. You could also add a validation that it's a real Leaflet map by testing it's properties.
Again, this is not ideal, but, if your use case is limited enough, it is one way to achieve this. Thanks!

Categories

Resources