Simplifying repeated code

  • Having scenes like

    Code
    <scene ... >
       <layer name="alfa" attr1 ...  attr2...>
           <layer name="beta" attr3="%1" attr4="%2">
               <layer name="%3"  ...>
               </layer>
           </layer>
       </layer>
    </scene>

    where %1, %2 and %3 vary.
    I want to know how to group all layers in a 'function layers' containing layers code and simplify the code something like

    Code
    <scene ... >
       layers(A,B,C)
    </scene>

    Thanks

    Edited once, last by alfabeta (August 18, 2024 at 9:09 PM).

  • Good, thanks.

    Starting

    Code
    <layer name="mapcontainer" style="mapcontainer">
                <layer name="map" style="map"
    Code
    <action name="map_rads">
        addlayer('mapcontainer');
        set(layer['mapcontainer'].style,mapcontainer);
        addlayer(layer['mapcontainer'].'map');
        set(layer['mapcontainer'].layer['map'].style,map);

    or

    Code
    <action name="map_rads">
        addlayer('mapcontainer',mpc);
        set(mpc.style,mapcontainer);
        addlayer(mpc.'map', MP);
        set(MP.style,map);

    Is that so?

    How to check the 'output' of the action?

    Edited 5 times, last by alfabeta (August 19, 2024 at 12:06 AM).

  • Code
    <action name="map_rads"> 
        addlayer('mapcontainer'); 
        addlayer('map); 
        layer['map'].parent = 'mapcontainer';
        layer['mapcontainer'].loadstyle('mapcontainer'); 
        layer['map'].loadstyle('map'); 
    </action>

    or another example

    Code
    map_rads('mapcontainer', 'map', 'containerstyle', 'mapstyle');
    
    <action name="map_rads" scope="local" args="cname,mname,cstyle,mstyle"> 
       addlayer(*cname, local.clayer); 
       addlayer(*mname, local.mlayer); 
       mlayer.parent = *cname;
       clayer.loadstyle(*cstyle); 
       mlayer.loadstyle(*mstyle); 
    </action>
  • Thank you!

    I had edited my last post but the last add was not included.

    1) How to add a radar element <radar visible="true" size="350" alpha="0.33" fillcolor= ?

    2) Also <spot name="point1"  lat="...

    3) <layer name="map" style="map"
        lat="input 1" 
      lng="input 2" 
    ....
    ->
    set(layer['map'].'lat',%1);
    set(layer['map'].'lng',%2); ?

    Edited 2 times, last by alfabeta (August 19, 2024 at 2:54 PM).

  • for radar see here : https://krpano.com/plugins/radar


    the rest is too undefined....

    if it is a custom map (image) you would not use lat/long at all

    you simply set hotspots with x/y coordinates.


    %1 etc is an old way to pass action arguments

    you can see the modern way in the 2nd code example in my post above

    more infos about that here: https://krpano.com/docu/xml/#action

  • Hi,

    here the Googlemaps plugin documentation:

    krpano.com - Plugins - Google Maps

    1) the <radar> there don't need to be 'added', that's just an element for settings and you can anytime set them, e.g.

    Code
    layer[maps].radar.visible = true;
    layer[maps].radar.size = 350;
    layer[maps].radar.alpha = 0.33;


    2) spots can be added using the plugin actions:

    krpano.com - Plugins - Google Maps

    e.g.

    Code
    layer[maps].addspot(spot1, LAT, LNG, ...);
    layer[maps].addspot(spot2, LAT, LNG, ...);


    3) to set the map position:

    Code
    layer[maps].setcenter(LAT, LNG); 

    or animated:

    Code
    layer[maps].panto(LAT, LNG); 


    Best regards,
    Klaus

  • Some changes here, create both layers with the action

    Code
    <scene ... onstart="map_action(40,30,-50);">

    Here both layers are displayed but the child map a white rectangle

    Edited 2 times, last by alfabeta: typo correction (September 3, 2024 at 11:42 PM).

  • Testing, if in the action I replace the 3 arguments by some values like

    set(layer[map].lat, latitude);  by set(layer[map].lat, 35);

    the map is displayed but radar and spot, only the map.

    Edited once, last by alfabeta (September 4, 2024 at 3:16 PM).

  • Code
    set(layer[map].lat, latitude);    
    set(layer[map].lng, longitude);

    This is where there can be a problem. Sometimes you MUST give a get or a copy.

    Try:

    set(layer[map].lat, get(latitude));

    or

    copy(layer[map].lat, latitude);

    or

    set(layer[map].lat, *latitude);

    or

    set(layer[map].lat, %1);


    Same with ‘longitude’ and ‘heading’.

    Piotr

  • I've include the map style into the action.
    I tried all your suggestions but nothing changes: the map is loaded at the correct coords but radar and spot are absent.
    See that radar doesn't use any of the arguments and it isn't displayed.

    • New
    • Official Post

    Hi,

    the plugin actions like addspot/panto are only available AFTER the plugin has loaded and is ready.

    In your code you set the plugin url and call these actions basically at the same time.
    In the log there should be even a warning about unknown addspot/panto actions in this case.

    That means wait for the onmapready event before calling them.
    Additionally the radar will be only shown on active spots, therefore 'true' would need to be passed for the active argument.

    Here one example how this could be done for your case:

    Code
    calc(layer[map].onmapready,
      "layer[map].addspot('P1'," + latitude + "," + longitude + "," + heading + ",true);" + 
      "layer[map].panto(" + latitude + "," + longitude + ");"
    );

    Best regards,
    Klaus

Participate now!

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