4 Replies Latest reply on Oct 19, 2015 8:27 PM by jlittle RSS
    yewkh Explorer

    State based formatting for Image widget

    Hi,


    I am trying to make the image widget to display the icon image based on the state. For other widget such as Google Map, this can be done easily using the State Based Formatting. However, it seems I couldn't find such feature for Image widget.


    Was trying to use scripting way to achieve it as below.


    var result; 


    if(Things[Station_ID].RemoteMachineConnected == true)

        result = MediaEntities["Connection_Up"].GetImage();


    else {

    result = MediaEntities["Connection_Down"].GetImage();

    }


    However, the resulting Image couldn't be linked in Mashup as Image widget is expecting Source URL.


    How do we get the URL of a media entity through script? Or if there is built-in State-based formatting in Image widget?


    Thanks in advance!

      • State based formatting for Image widget
        adam Creator

        Hi Yew,

         

        By using the Value Display as opposed to the Image widget, your Mashup will be able to support the Service you've already written. If you prefer to use the Image widget, your Service simply needs to return an IMAGELINK of the following format: "Thingworx/MediaEntities/name_of_Media_Entity".


        Thanks,

        Adam



        • State based formatting for Image widget
          yewkh Explorer

          Thanks Adam.

           

          For the value display suggestion. It works.


          For the Image widget suggestion, 

          I tried using var result = MediaEntities["Connection_Down"];  with result set to IMAGELINK. But seems it returned a broken link. Just wanted to find out more if the script is written correctly in this case...


          Using REST way Thingworx/MediaEntities/Connection_Down renders the image successfully though.


          Please advise. Thanks!



          • State based formatting for Image widget
            adam Creator

            Yew,

             

            To use the Image widget, you would set result to:


            result = "Thingworx/MediaEntities/Connection_Down";


            and have your Service return an IMAGELINK. You can then bind the result from your Service to the Image widget's SourceURL property.</div></p>

              • Re: State based formatting for Image widget
                jlittle Explorer

                Just a clarification point here, as I got stuck for a few moments on Thingworx 6.5 using the strings suggested above.

                 

                The result string needs a leading slash:

                  result = "/Thingworx/MediaEntities/Connection_Down";

                 

                Omitting the leading slash resulted in a broken image for me.