[solved] worldmap - button - redirect using window.location.foo

Wondering if there is a way to send a

window.location.replace

or a

window.location.href

using a button in worldmap

I can create buttons in the map and register the click event to the worldmap in node and receive the action but now what.... care to point me in the right direction ?

Why not just add the action to the button itself ? No need to send to the backend ?

Why not just add the action to the button itself ? No need to send to the backend ?

Oh I thought about doing that using onclick and doing that but I have other logic outside of the map I want to forward the user to a url.

This all comes back to the camera system I created using worldmap. That way I can trigger the action as well.
I just wanted to make sure I was not missing a easy solution before diggin in the innards.
If its not possible I'll pull up your github repo and start reading and maybe code it in.

I figure it could work like i did with the dashboard https://discourse.nodered.org/t/howto-dashboard-button-link-to-url-with-no-ui-template-for-only-the-current-user-on-the-page/33210

The camera map

Ohhhhhh......... just found the code for the 3d view. Looks like I can build on this to do what I want.

document.addEventListener ("keydown", function (ev) {
    // Set Ctl-Alt-3 to switch to 3d view
    if (ev.ctrlKey && ev.altKey && ev.code === "Digit3") {
        ws.close();
        window.location.href = "index3d.html";
    }
    // Set Esc key to close all open popups
    if (ev.keyCode === 27) {
        map.eachLayer(function (layer) {
            layer.closePopup();
        });
    }
});

now I just need to tie it into the button or .........better create a new command object for Controlling the map. hmmmm what to call it?

1 Like

@dceejay well that was not too hard

if (cmd.hasOwnProperty("redirect")) {
      if (typeof cmd.redirect === "string")  {
          ws.close();
          window.location.href = cmd.redirect;
      }
    }

trigger it using

msg.payload = {"command":{ "redirect": "https://google.com" }};

Tested working as triggered or with a button tied to a msg._sessionid with multiple sessions open to make sure it did not redirect all sessions :slight_smile:

I'd be happy to write up the documentation and submit a PR if you want the addition like i did for the weblink *array of objects addition I did.

Thanks for working with me m8

PS: or no documentation and just PR to sneak it in so every time I update worldmap I dont have to ftp in and edit the worldmap.js file :stuck_out_tongue:

Got bored, Pull request submitted.

1 Like

Also the main benefit for all of this is to keep local network users from loading the map from a saved url. I need them to login because ive had some bad actors..... Who would have thought that a user would just keep loading cameras and leaving them open :expressionless: boggin down the camera server to all hell.

Fake names used:
So Jenny needs access to the cameras to check on theft. But then one day she decides she wants to have the parking lot camera streaming in her borwser so she can watch in on her new car. Well Jeff from accounting see the camera on her screen and asks, "hey how you get that? "

Well 2 weeks later I have a server bogged down with about 20 people all with cameras streaming all sorts of things. I ask Paul from the warehouse " why do you need to stream the cafeteria? and he says "don't want no one messing with my lunch."

Oh the hell that is my life.

2 Likes

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.