Question T3614
Visible to All Users

Trying to integrate ImageMapper as custom component

created 5 years ago

Has anyone successfully integrated https://coldiary.github.io/react-image-mapper/ as a custom component for both creating and taking a survey?

(I've been working on creating a wrapper, but figured I'd take a shot in the dark. :)

Thanks!
Billy McCafferty

Comments (1)

    Alternatively, does anyone have an example of using the imageHotArea custom component - as mentioned on https://github.com/surveyjs/widgets - within a React solution?

    Answers approved by surveyjs Support

    created 5 years ago

    Hello,

    I've fixed your plunker. This is the updated one - https://plnkr.co/edit/OP8jzZKdjVf6nXJG

    Two changes:

    • Introduced the unique mapName. In your case this name was the same with the designer surface on the design tab and test survey on the test tab. Your clicks were registered for the design survey due to the same map name.
    JavaScript
    var mapName = question.name + "_map_" + Date.now(); //get and prepare the img element var image = el.getElementsByTagName("img")[0]; image.src = question.imageLink; image.alt = question.name; image.useMap = "#" + mapName; //get and prepare the map element var myMap = el.getElementsByTagName("map")[0]; myMap.name = mapName; myMap.style.cursor = "pointer";
    • Changed the way the value assigned:
    JavaScript
    question.value = (question.value || []).concat([{ x: e.x, y: e.y }]);

    Thanks, Serge
    SurveyJS Team

      Comments (2)

        That worked!! THANK YOU!!! Your timing was impeccable for a demo I'm doing later today…thanks again!!

          You are welcome!

          Thanks, Serge
          SurveyJS Team

          created 5 years ago

          Hello,

          Custom widgets in SurveyJS are designed to be used in all supported platforms (KnockoutJS, React, VueJS). Thus most of custom widgets are implemented in pure JavaScript and can be used everywhere in SurveyJS ecosystem.

          You can use a React component as a custom widget. And it will work with the survey-react library. But SurveyJS Creator is based on the survey-knockout library and React component will not work here. If you want custom widget will be able in SurveyJS Creator (and consequently in all other platforms) this widget should be implemented in platform (framework) independent manner.

          Thanks, Serge
          SurveyJS Team

            Comments (1)

              I'm super close to getting this working! :)

              The only problem is that the selected click isn't being reflected in the question answers when the survey is completed; e.g., https://plnkr.co/edit/nRaBDEXcbhp0SaJi?preview

              You can see that the custom component is adding the coordinates of what was clicked to the question.value but the value is not being reflected in the question responses when the survey is completed. Do you know what I'm doing wrong?

              Thanks!
              Billy McCafferty