SVG 文件的路径
Path of an SVG file
如何获取路径内的属性并编辑任何特定属性。例如,如果我想为任何选定的 ID 更改该路径的颜色。我如何在 Processing 中为此编写代码。如果可能,请提供示例。我尝试使用 getChildren() 但不确定我是否做对了。
这就是我尝试做的
void setup() {
size(1000, 800);
background(255);
noLoop();
//loading the map and the csv file
baseMap=loadShape("nepalmap.svg");
ArrayList<String> names = new ArrayList();
for (PShape ps : baseMap.getChildren()) { //get pshape from themap
names.add(ps.getName());
}
location=loadTable("location.csv", "header");
for (TableRow row : location.rows()) {
String id = row.getString("district");
float[] latlon = new float[2];
latlon[0]=row.getFloat("Latitude");
latlon[1]=row.getFloat("Longitude");
PShape shape = baseMap.findChild(id);
if (shape == null) {
println("Unfound: " + id );
我需要能够使用地区名称获取路径。我将举例说明其中一个地区的路径是什么样子的,以便更好地理解。找到地区后,我需要更改我想要的地区的颜色。
Link 到 SVG 文件
https://1drv.ms/u/s!ArCqZlwbF3LRbomDBoJu3Qt0_hA?e=F5GAY1
谢谢
根据您的代码,假设每个地区都是根 SVG 节点的直接子节点。对于您的 SVG,这可能是正确的,也可能不是。
如果您不确定,可以使用 findChild() 而不是 getChild()
。
不同之处在于 findChild 将遍历 SVG 层次结构,直到找到该名称的子项(如果存在)。
注意您有两个数据源:SVG 和 CSV。
确保两者使用相同的名称(键敏感)。如果他们与您不匹配 findChild()
可能 return null
(顺便说一句,“未找到”检查做得很好!)
一旦您获得了 PShape 区的引用,您就可以尝试调用 setFill()
for example or disableStyle()
,这会禁用 SVG 样式并使用您在处理中设置的最新 fill/stroke 属性。
如何获取路径内的属性并编辑任何特定属性。例如,如果我想为任何选定的 ID 更改该路径的颜色。我如何在 Processing 中为此编写代码。如果可能,请提供示例。我尝试使用 getChildren() 但不确定我是否做对了。 这就是我尝试做的
void setup() { size(1000, 800); background(255); noLoop(); //loading the map and the csv file baseMap=loadShape("nepalmap.svg"); ArrayList<String> names = new ArrayList(); for (PShape ps : baseMap.getChildren()) { //get pshape from themap names.add(ps.getName()); } location=loadTable("location.csv", "header"); for (TableRow row : location.rows()) { String id = row.getString("district"); float[] latlon = new float[2]; latlon[0]=row.getFloat("Latitude"); latlon[1]=row.getFloat("Longitude"); PShape shape = baseMap.findChild(id); if (shape == null) { println("Unfound: " + id );
我需要能够使用地区名称获取路径。我将举例说明其中一个地区的路径是什么样子的,以便更好地理解。找到地区后,我需要更改我想要的地区的颜色。
Link 到 SVG 文件 https://1drv.ms/u/s!ArCqZlwbF3LRbomDBoJu3Qt0_hA?e=F5GAY1
谢谢
根据您的代码,假设每个地区都是根 SVG 节点的直接子节点。对于您的 SVG,这可能是正确的,也可能不是。
如果您不确定,可以使用 findChild() 而不是 getChild()
。
不同之处在于 findChild 将遍历 SVG 层次结构,直到找到该名称的子项(如果存在)。
注意您有两个数据源:SVG 和 CSV。
确保两者使用相同的名称(键敏感)。如果他们与您不匹配 findChild()
可能 return null
(顺便说一句,“未找到”检查做得很好!)
一旦您获得了 PShape 区的引用,您就可以尝试调用 setFill()
for example or disableStyle()
,这会禁用 SVG 样式并使用您在处理中设置的最新 fill/stroke 属性。