Place an object inside an SVG in javafx

隐身守侯 提交于 2021-02-17 07:15:06

问题


I am making Risk in java with javaFX. I have the map displayed in an fxml file, with every country having an SVGPath. I want to know how can I put a circle with a number inside it, in the centre of the SVG. I am hoping I can do this in the CSS but so far I cant get it working.

My SVGPaths look like this:

    <SVGPath id="Egypt" styleClass="grey-country, africa, country" content="M484 328c8,2 15,10 23,9 0,-4 0,-4 1,-7 12,-3 24,4 35,8 5,0 9,0 14,0 1,5 3,10 4,15 -2,0 -4,-1 -6,-1 2,9 5,17 7,26 -3,1 -3,1 -5,4 -11,0 -22,0 -33,0 -2,6 -2,6 -1,9 -2,0 -3,0 -4,0 0,1 0,3 0,4 -7,-2 -8,-7 -15,-9 0,-2 -1,-4 -2,-6 -12,-2 -19,-3 -28,-11 -1,-11 0,-19 -1,-29 1,-1 2,-1 2,-2 1,-2 1,-4 1,-7 4,-3 4,-3 8,-3z"/>
    <SVGPath id="Congo" styleClass="grey-country, africa, country" content="M473 502c-5,-6 -11,-12 -11,-20 4,-3 4,-4 6,-9 2,0 4,0 6,0 0,-1 0,-2 0,-3 9,2 9,2 13,2 1,-8 2,-13 0,-20 4,-2 5,-5 10,-7 1,-1 1,-2 1,-4 7,-1 11,-5 17,-9 4,11 9,19 16,29 1,-1 2,-2 2,-3 1,2 2,4 2,6 6,0 11,1 16,2 1,11 -9,11 -10,19 -2,0 -3,0 -4,0 -1,4 -2,11 -7,12 1,5 1,11 2,17 -1,2 -2,3 -3,5 -1,0 -2,0 -3,0 1,5 1,11 2,16 -2,0 -3,0 -4,0 0,-1 0,-3 0,-4 -23,-5 -15,-2 -21,-20 -2,0 -4,-1 -6,-1 0,1 -1,2 -1,3 -1,0 -3,0 -4,1 -1,-4 -1,-4 -4,-9 -8,-1 -9,-2 -15,-3z"/>
    <SVGPath id="Madagascar" styleClass="grey-country, africa, country" content="M579 589c-5,-6 -4,-15 -1,-22 0,0 1,0 2,0 2,-15 1,-16 14,-21 6,-5 6,-5 7,-8 1,0 2,0 3,0 0,5 0,11 0,17 0,0 -1,0 -2,0 0,1 0,2 0,4 -1,0 -2,0 -3,0 -1,11 -9,26 -20,30z"/>
    <SVGPath id="South Africa" styleClass="grey-country, africa, country" content="M473 502c6,1 7,2 15,3 3,5 3,5 4,9 1,-1 3,-1 4,-1 0,-1 1,-2 1,-3 2,0 4,1 6,1 6,18 -2,15 21,20 0,1 0,3 0,4 1,0 2,0 4,0 -1,-5 -1,-11 -2,-16 1,0 2,0 3,0 1,-2 2,-3 3,-5 0,0 1,0 2,0 2,3 5,7 7,10 0,8 0,16 0,23 2,0 3,0 5,1 0,-2 0,-12 2,-18 5,-2 10,-3 16,-4 0,13 2,29 -13,33 -1,2 -1,2 -6,7 -1,9 0,19 -10,22 -2,13 -2,13 -3,18 -1,0 -2,0 -3,0 0,1 0,2 0,3 -1,0 -2,0 -3,0 -7,18 -20,18 -39,22 -2,-1 -4,-2 -5,-2 0,-2 0,-3 0,-4 0,0 1,0 2,0 0,-10 -1,-15 -6,-24 -1,-9 -2,-12 -5,-30 -4,-11 -8,-21 -2,-31 1,0 3,-1 4,-1 0,-8 -1,-16 -1,-24 1,0 2,-1 3,-1 0,-3 0,-7 -1,-11 -1,0 -2,0 -3,0 0,0 0,-1 0,-1z"/>
    <SVGPath id="North Africa" styleClass="grey-country, africa, country" content="M468 473c-1,-4 -1,-6 0,-10 -7,-3 -7,-3 -13,-3 -2,-6 -2,-6 -4,-7 -5,0 -9,1 -14,1 0,1 0,2 0,3 -16,-1 -25,7 -36,-8 -6,-2 -10,-16 -12,-22 0,0 -1,0 -2,0 0,-1 0,-2 0,-3 -1,0 -2,0 -3,0 -2,-9 -2,-16 1,-25 0,-9 -1,-19 2,-28 5,-1 8,-15 10,-20 13,-6 13,-10 17,-25 7,-4 9,-7 14,-14 0,0 1,0 1,0 7,5 16,-1 23,-4 7,0 10,-1 28,-2 0,2 0,3 0,4 -1,1 -1,1 -2,1 2,3 1,6 1,10 -1,0 -3,0 -4,0 0,1 0,1 3,1 0,1 0,2 0,3 2,1 4,2 6,3 -4,0 -4,0 -8,3 0,3 0,5 -1,7 0,1 -1,1 -2,2 1,10 0,18 1,29 9,8 16,9 28,11 1,2 2,4 2,6 7,2 8,7 15,9 -2,13 -5,23 -4,37 -6,4 -10,8 -17,9 0,2 0,3 -1,4 -5,2 -6,5 -10,7 2,7 1,12 0,20 -4,0 -4,0 -13,-2 0,1 0,2 0,3 -2,0 -4,0 -6,0z"/> ```

来源:https://stackoverflow.com/questions/66065663/place-an-object-inside-an-svg-in-javafx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!