Using dojox gfx to enable a node to be draggable following retrieval of sgv data from a JSON source

I have a collection of shapes on a surface that I need to convert to JSON using the dojox.gfx.utils.toJson(surface) method. Once I have the JSON data, I then utilize

dojox.gfx.utils.fromJson(surface, json)
to append it back to the surface. However, I encountered an issue when trying to make a node moveable. Despite saving it to JSON and reappending it to the surface, the node loses its moveable functionality. I've been unable to find a solution to restore the moveability of the node post-loading. Is there a way to achieve this? My goal is to be able to save and load SVG data on my page while still being able to freely move the elements around. While working with Dojo seemed straightforward initially, this particular problem has complicated matters. If achieving this becomes too challenging with Dojo, are there any alternative libraries that could better suit my requirements?

Edit: For reference, here is the actual code snippet: http://pastebin.com/2qLCTw8B

Answer №1

After some exploration, I managed to find the solution to my issue.

One key point I discovered is that when requiring a dojo module, it is beneficial to assign it to a variable, a practice I was unaware of before. This allows for easier usage of functions like 'on' which adds event listeners throughout the code. With this knowledge, creating a movable node upon click becomes a simple task.

However, it dawned on me that this process may be redundant since one could simply iterate over the surface's children array and make all nodes moveable.

For those interested, here is the refined version of the code: http://pastebin.com/wAvSnZpN

In case events are still preferred, below is the necessary code snippet:

function HandleMouseDown(e) {
    var foo = new dojox.gfx.Moveable(e.gfxTarget);
}

on(surface, 'mousedown', HandleMouseDown);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Creating an array using Vue.js

When I initialize a Vue data array like this [0: Object, 2: Object];, the console log in Vue shows the array as [0: Object, 1: undefined 2: Object];. This causes issues when iterating through with 'v-for="cell in row.cells"' as it results in tryi ...

Combining several files into a single variable to encode

I'm encountering an issue with the multiple file upload option. Even though it shows that 2 files have been uploaded, when I try to print the encoded value in the console, it only encodes and takes the value of my last uploaded file. How can I encode ...

JavaScript code that exhibits a sandwich pattern

My apologies if the title of the question is misleading. I am actually seeking the JavaScript equivalent of the following Python code: ## python code def call_with_context(fn, *args): ## code to create context, e.g. profiling, db.connect, or drawing co ...

What is the reason for the hotel's Object _id not being saved in MongoDB?

Can you assist with troubleshooting this issue? This is the HotelRoom Module: const mongoose = require('mongoose'); const Schema = mongoose.Schema; const HotelRoomSchema = new Schema({ name : { type : String, require : true ...

Ways to dynamically incorporate input fields into a form

My current project involves managing an Asset Management system for a company with multiple locations. This system has the capability to return unused asset items back to storage. I am faced with the task of returning a large number of items, which requi ...

Enhance User Experience by Implementing Event Listeners for Changing Link Visibility Using mouseover and getElementsBy

I am new to JavaScript and struggling to find a solution. Despite searching online for fixes, none of the solutions I've found seem to work for me. I have spent hours troubleshooting the issue but I must be missing something crucial. Can someone plea ...

Having trouble incorporating Duo Web SDK into angular application

We are currently working on incorporating Duo Two-factor authentication into our Angular application. For instructions, you can take a look at the documentation available here. The issue we are encountering is that their JavaScript file searches for an i ...

Retrieve information using server-side rendering

I'm faced with a situation where my page utilizes query parameters to fetch data via SSR. The challenge arises when these query parameters frequently change, triggering a re-fetch of the data using SSR despite there being no client-side data fetching ...

The isInvalid property fails to apply red highlighting to the input box in a react-bootstrap form

Working on creating forms using React and react-bootstrap. Currently, my form includes an email field structured like this - https://i.sstatic.net/dlbWn.png Here's the code snippet of how it looks: <Form noValidate autoComplete="off&quo ...

What is the best way to pass multiple variables to PHP through an AngularJS Ajax request?

Currently, I am in the process of learning AngularJS and I am curious about how I can send multiple data variables through Angular AJAX, similar to how I would accomplish this task using jQuery. Using jQuery, I have previously achieved this like so: $.po ...

Synchronize all series in Highcharts charts simultaneously

I have implemented the following code to showcase a Highchart with 3 signals, which are updated periodically with animation. However, I am facing an issue where, for 2 of the signals, the dots are updated first and then the curve slides into the dots. This ...

Unable to modify variable to play audio

As I work on constructing my website, I am incorporating various sounds to enhance user experience when interacting with buttons and other elements. However, managing multiple audio files has proven challenging, as overlapping sounds often result in no aud ...

What is the process for saving the selected value from a radio button into the database?

Below is an example of code I am working with: <label style="cursor:pointer;"><input type="radio" name="rads" value="'.$correct.'" id = "radio">'.$answer.'</label> <button onclick="myFunction()">Value</butto ...

Displaying Stats.js inside a different canvas using ThreeJS

Just starting out with Three.js and wanted to test displaying the Stats.js in a small scenario. Check it out here Decided not to use modules for now, but followed similar code structure as in the examples: var stats = new Stats(); var renderer = ...

Running an API and transferring Json data to S3, all the while transforming it into Avro format

I am trying to set up an API in Nifi using the HandleHTTP processor. My goal is to pass some mock JSON data through this process. Next, I aim to convert the JSON data into Avro format and then store it in an S3 bucket. However, I keep encountering an erro ...

Issue: Unhandled rejection TypeError: Unable to access properties of an undefined variable (retrieving 'data')

Currently, I am developing applications using a combination of spring boot for the backend and react for the frontend. My goal is to create a form on the client side that can be submitted to save data in the database. After filling out the form and attemp ...

Every initial test with Protractor ends in failure

Here are the versions I am currently using: protractor v5.1.2 chromedriver v2.33 node v6.11.4 npm 3.10.10 selenium-webdriver v3.0.1 I am a beginner with protractor and I am attempting to run the provided test natively included in protractor. The test scr ...

Why is there an error when trying to assign Type '{}' in generics typescript?

I'm having trouble understanding why this code is causing an error. The error message says - Type '{}' is not assignable to type 'Keys<T>'. type Keys<T extends string|symbol>={ [key in T]: string; }; const foo = < ...

When using the HTML5 input type time in Chrome and the value is set to 00:00:00, it may not be fully completed

After inputting the html code below <input id="time_in" type="time" step="1" name="duration"> and setting the value in the browser to "00:00:00", everything appears fine. However, upon inspecting the console or submitting the form, the value gets ...

alter the JSON by removing certain data from its contents

Currently, I am diving into learning Angular. I have successfully retrieved data from a local JSON file and managed to delete an element from the array in that JSON. However, whenever I refresh the page, the deleted array reappears. How can I update the JS ...