It there any way to set/get data in konva object?
Just like jquery use the method 'data' to set and get info,eg: $('#abc').data('id','123') !
You can use custom attributes. Just make sure they don't overlap with built-in properties.
https://konvajs.org/api/Konva.Node.html#setAttr
https://konvajs.org/api/Konva.Node.html#getAttr
// set
shape.setAttr('someData', 0);
// get
shape.getAttr('someData');
Related
I am creating gridlines using CAReplicatorLayer. To each gridline, I also want to add a CATextLayer that shows the corresponding numerical value. I do not want to do this manually, however with CAReplicatorLayer there doesn't seem to be a way to dynamically change the string property of each text layer, and they all show the same initial value that is set.
Is there a way around this or do I have to create and maintain the text layer objects manually?
Alright, so I ended up creating an array of CATextLayers and maintaining it manually alongside the gridlines created by the CAReplicatorLayer.
I need to render dynamic GeoJSON data to a map in iOS.
I am using react-native-maps. I was able to render the geojson to the map, but it only shows the stroke of each region and not the fill color:
How can I add a unique color to each state or region on the map?
You need to make sure that your GeoJSON has a valid fill value at geojson.features[n].properties.fill. If your GeoJSON doesn't already have that value, you can write a function to add it. For example:
const colorizedGeojson = {
...geojson,
features: geojson.features.map(feature => ({
...feature,
properties: {
...feature.properties,
fill: getColor(feature.properties.values.population)
}
})),
};
You'll have to implement your own getColor function, depending on the data you want to represent. The population value used here is just an example. Using d3 interpolation to get the color for the value you want to represent is a common choice.
Once you've added the fill property to your GeoJSON data, you can pass that object to the component. Make sure you don't pass the fillColor property to the component, as that would override the feature colors.
<Geojson geojson={colorizedGeojson} />
That's it! The react-native-maps component will render each region/country with the color you choose:
If it still relevant, you can use multiple <Geojson /> components inside <MapView> and set different fillColor prop to them depends on your condition.
I need access to extracted style attributes (e.g. fill color, stroke color, etc.) for a KML file once loaded. I can't seem to find a way to access the style once the layer has been added. The myLayer.getStyle() returns a function as expected but how does one access the style attributes?
You get the styles by calling the function.
As the docs say, you should pass an ol.Feature object and a resolution value.
But it seems to return something also when you leave the parameters undefined.
var styleFn = myLayer.getStyle();
console.log(styleFn());
In openlayers3, in the Style Object, they don't have a method of set('') and also dont have setImage() and setText(). If i want to modify the image angle or text content, do someone know how to do ?
ol.Feature#getStyle returns a ol.style.Style (or an array);
ol.style.Style#getText returns a ol.style.Text;
ol.style.Text#setText is what you want.
So can be something like:
feature.getStyle().getText().setText('new content');
Does anyone know if you are able to set the colour of the text for a vertex label in JUNG.
I'm using the Visualisation Viewer and can seem to be able to set the colour for everything else.
vv = new VisualizationViewer<String,Integer>(treeLayout, new Dimension(410,557));
Transformer<String,Paint> vertexPaint = new Transformer<String,Paint>() {
public Paint transform(String b) {
return Color.orange;
}
};
vv.setBackground(Color.white);
vv.getRenderContext().setEdgeShapeTransformer(new EdgeShape.Line());
vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller());
vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
//vv.getRenderContext().setVertexFontTransformer(vertexFont);
// add a listener for ToolTips
vv.setVertexToolTipTransformer(new ToStringLabeller());
vv.getRenderContext().setArrowFillPaintTransformer(new ConstantTransformer(Color.WHITE));
The DefaultVertexLabelRenderer and the DefaultEdgeLabelRenderer extend JLabel (it is similar to the way cell renderers work in JTable and JTree).
By default, it uses the foreground color of the VisualizationViewer to draw the label text.
vv.setForegroundColor(Color.red);
will make all of your labels red.
This approach is less expensive than making all of the labels parse HTML.
Sorry that the solution is so obscure.
Additionally, since the default renderers extend JLabel, the use of html is the same as it is for JLabel. There are good online resources to show examples of using html with javax.swing. What's missing is documentation to make the connection between using html in JUNG and using html in javax.swing.
You can use HTML in the label to specify the color; an example is here: https://stackoverflow.com/a/2017576/664856
In your case,
vv.getRenderContext().setVertexLabelRenderer(new DefaultVertexLabelRenderer(Color.RED));
should work (if you wanted selected vertex to be Red). I tested it myself. This applies to the selected vertex.
Upon inspection of code, I would have to believe that the link I provided does correctly work for those vertices which are not selected, but I did not actually try implementing that link.