add spots to a map via html

  • HI,

    I am trying to add spots to a map via html, and have tried the following example https://krpano.com/forum/wbb/inde…ot%27#post17734

    but just cant get it to work for me, so I'd really appreciate if someone could offer any advice.

    My preferred route is by addVariable, like

    Code
    viewer.addVariable('set.plugin[map].addspot(spot1, 51.5055847, -0.0754774, 90, true);'); 
    viewer.addVariable('set.plugin[map].updatespots();');

    I can set map coord's this way but not addspot, e.g

    http://www.panoraks.co.uk/googlemaps-outside-pano/

    but of course am happy to use anything that works :)


    Thanks and best wishes,

    tom

  • Hi Kaus and all,

    I made another example code to try and add a mapspot via html based upon code found here https://krpano.com/forum/wbb/inde…ot%27#post17734


    http://www.panoraks.co.uk/googlemaps-outside-pano/index1.html</a>

    I'd be mega grateful to anyone who can advise me a way to do this, I've been tinkering and tinkering with this for over a month and just cant get it to work *cry*

    Dont suppose anyone has an idea *w00t* ?

    Best wishes,

    tom

  • You could try an onload javascript function

    or you could set a variable to true through html
    viewer.addVariable("plugin[map].var1", "1");

    and then in krpano an onloaded event

    Code
    <events onloaded="loadmap()" />
    <action name="loadmap">
    if(plugin[map].var1 EQ 1,
         plugin[map].addspot(spot1, 51.5055847, -0.0754774, 90, true);
        plugin[map].updatespots();
    );
    </action>
  • Hi,

    Thank you so much for your help Zephyr, really appreciate it, nice one *thumbsup* !!!

    I set up an example with your code and tried something else (commented out) but still no joy, it certainly is a tricky thing, I need to do it via html as it is part of a bigger thing that I am hoping will be helpful to pano photographers. This is the last thing that I need to do, so will show you and credit your help very soon.

    http://www.panoraks.co.uk/googlemaps-out…ano/index2.html

    I dont suppose a possible solution is to give the lat + long values in a function or declare with a variable that can then be returned in the googlemaps.xml

    function lat(){
    set('plugin[map].lat',"51.5055847");
    /* lat = 51.5055847
    document.write("51.5055847"); */
    }


    and then have this in my googlemaps.xml

    <spot name="spot1"
    lat="js(lat());" lng="js(long());" heading="js(head());"
    />

    and return a js value or a variable for the lat, long and heading?

    Just an idea, one of many *unsure*

    I'll keep pluggin away, but if anyone thinks of anything, please let me know.

    Thanks and best wishes,

    tom

  • try this:

    btw, don't think krpano can fetch returned values. But you can execute a js function and let js set a value (btw returning a value is done with return, not document.write).

    this is how I solved a cache problem

    in krpano xml:

    Code
    <events onloaded="js(getrandomvalue());" />

    in javascript:

    Code
    function getrandomvalue()
    {
    	krpano = document.getElementById('krpanoSWFObject');
    	var today = new Date();
    	var fivemin = 1000 * 60 * 5;
    	var randy = Math.ceil(today.getTime()/(fivemin));
    	krpano.set('timestamp', randy);
    }


    "timestamp" is a random name I made up. krpano executes getrandomvalue, then javascript sets a new variable in krpano with the randomvalue, which get read within another function by calling

    Code
    %$timestamp%

    example:

    Code
    <include url="include/settings.xml?%$timestamp%" />
  • Zephyr, BRILLIANT !!!!! it works your example, here :)


    http://www.panoraks.co.uk/googlemaps-out…ano/index3.html

    but only after clicking the map spot link,

    if I use just

    function krpano()
    {
    return document.getElementById("krpanoSWFObject");
    }

    document.onload = addMapspot();

    function addMapspot(){
    krpano().call("plugin[map].addspot(spot1, 51.5055847, -0.0754774, 90, true)");
    krpano().call("plugin[map].updatespots()");
    }

    should'nt this line document.onload = addMapspot(); load it automatically ?

    I also tried

    viewer.addVariable("events.onloadcomplete", "js( addMapspot() );");

    and

    <body onLoad="addMapspot();">

    to load it automatically.

    I dont suppose you can push my happiness beyond the stratisphere and help me to load this function automatically ?

    Thank you so much for your help again, *thumbup*

    best wishes,

    tom

  • yes, the problem lies in the fact that a document.ready is an event that gets trigger when the html page is loaded. This doesn't include krpano xml and plugins and images. What happens is that the function gets executed before krpano is loaded. Doing a onloaded or onmapready, ensures that the function gets executed when krpano is ready. :)

    What you could do is create a container function. You fire 1 function when krpano is done loading (onloaded="js(init())") then in that init you fire everything you want to krpano. If you don't need to do anything, the leave init() empty, this way stuff stays flexible for your html commands.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!