How is Layer.add accessed?
See original GitHub issueI’ve been trying to add a new shape object to an existing Layer in response to a click event. (Feel free to tell me that’s not how this package works 🤣) Just a quick sample to demonstrate what I’ve tried:
import React from 'react';
import { render } from 'react-dom';
import { Stage, Layer, Circle } from 'react-konva';
const myLayer = <Layer />;
const App = () => <Stage>{myLayer}</Stage>;
render(<App />, document.getElementById('root'));
// Later when the user clicks on something, but we can try this now why not
const myNewRuntimeElement = <Circle/>;
myLayer.add(myNewRuntimeElement);
BUT, this yeilds an error: TypeError: myLayer.add is not a function
“Okay, well if its not here, where do I go?”
I tried reaching into the Layer ref…
let myLayerRef;
const myLayer = <Layer ref={node => myLayerRef = node}/>;
...
myLayerRef.add(myNewRuntimeElement);
…Which has the add
function defined, but gives an error: TypeError: child.getParent is not a function
.
I get the same error if I pass the circle’s ref to add
, but that feels like a react anti-pattern rabbit hole I’d prefer not to go down. Is this something I can accomplish with this tool, and if so, how?
Thanks! 😄
Issue Analytics
- State:
- Created 5 years ago
- Comments:13 (4 by maintainers)
Top Results From Across the Web
Add layers to maps (Map Viewer Classic) - ArcGIS Online
To get started adding layers, sign in to the site, open Map Viewer Classic, and click the Add button. You can search for...
Read more >Using layers with your Lambda function - AWS Documentation
Accessing layer content from your function Each Lambda runtime adds specific /opt directory folders to the PATH variable. Your function code can access...
Read more >Experience Builder - access pop-up for layers add...
I notice that pop-ups for the layers added to the map through this widget cannot be accessed. Could anyone help me figure out...
Read more >Accessing layers - Sketchbook
From the menubar, select Window > Layer Editor. Accessing layers in Sketchbook for mobile devices. If you're on a tablet, the Layer Editor...
Read more >Accessing layer's visibility presets? - GIS Stack Exchange
You can access the visibilityPresetCollection through the project instance: QgsProject.instance().visibilityPresetCollection().
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hello @victormanuelfrancodev okay, thanks it is clear! The rect is drawn on the layer by an array, but I want to draw it as many times as I click on my image Or how do I write the function that I call on onClick()? So what do I write to my onClick function which is also in the render()?
Because I tried some solutions, but none of them worked and I confused. This is my first program in react. I’m implementing an earlier code that I wrote in pure javascript and konva.
Okay. Thanks.