我有使用RaphaelJS生成的美国地图。目前我正专注于佛罗里达州的国家路径。我试图使用RaphaelJS的getBBox()和isPointInsidePath()函数在佛罗里达州的路径内生成随机圆圈。当在浏览器中运行时,似乎处于工作的边缘,除了生成的所有点似乎都在State的路径边界上。当我在JSFiddle中重新创建时,这些点似乎进入了状态,但是在州边界之外总是留在边界框内。
var FLPath = "M562.5,325.1l1.7,5.4l2.7,7.2l3.9,7l2.7,4.7l3.6,4.1l3,2.7l1.2,2.1l-0.8,1l-0.6,1l2.1,5.5l2.1,2.1l1.9,3.9l2.7,4.3l3.3,6.1l1,5.6l0.4,8.9l0.4,1.3l-0.2,2.5l-1.8,1l0.2,1.4l-0.4,1.4l0.2,1.8l0.4,1.4l-2,2.4l-2.3,1.1l-2.9,0.1l-1.1,1.2l-1.8,0.7l-1-0.4l-0.8-0.7l-0.2-2.1l-0.6-2.5l-2.5-3.8l-2.7-1.7l-2.9-0.2l-0.6,1l-2.3-3.3l-0.4-2.7l-1.9-3l-1.3-0.8l-1.2,1.6l-1.3-0.2l-1.6-3.7l-2.1-2.9l-2.1-3.9l-1.9-2.3l-2.7-2.7l1.6-1.8l2.4-4.1l-0.1-1.2l-3.3-0.7l-1.2,0.4l0.2,0.4l1.9,0.7l-1.1,3.3l-0.6,0.4l-1.3-3l-1-3.6l-0.2-2l1.1-3.5v-7l-2.3-2.7l-1-2.3l-3.8-1l-1.4-0.4l-1.2-1.9l-2.5-1.2l-0.8-2.5l-2-0.7l-1.8-2.7l-3.1-1.1l-2.1-1.1h-1.9l-3,0.6l-0.1,1.4l0.6,0.7l-0.4,0.8l-2.3-0.1l-2.7,2.7l-2.7,1.4h-2.9l-2.4,1l-0.2-2l-1.2-1.4l-2.1-0.8l-1.2-1.1l-6-2.9l-5.6-1.3l-3.3,0.4l-4.4,0.4l-4.4,1.6l-2.6,0.4l-0.1-5.9l-1.9-1.4l-1.3-1.3l0.2-2.3l7.6-1l18.9-2.1l5-0.4l4,0.2l1.9,2.9l1.1,1.1l6,0.4l8-0.4l15.9-1l4-0.5l3.8,0.1l0.3,2.1l1.6,0.6l0.1-3.4l-1.1-3.1l1-1l4.1,0.4L562.5,325.1z M571.8,423.1l1.8-0.4l1-0.1l1.1-1.7l1.7-1.2l1,0.4l1.3,0.2l0.3,0.8l-2.6,0.9l-3.1,1.1l-1.7,0.9L571.8,423.1z M581.8,419.4l0.9,0.8l2-1.6l3.9-3.1l2.7-2.9l1.9-4.9l0.7-1.3l0.1-2.5l-0.5,0.4l-0.7,2.1l-1.1,3.4l-2.4,3.9l-3.3,3.1l-2.5,1.4L581.8,419.4z";
var random = 5 - 1;
function createVariables(randomNumber, StatePath){
var statePathNew = paper.path(StatePath);
var stateBBox = statePathNew.getBBox();
var accounts = [];
var i = 0;
while (i <= randomNumber) {
var xRandom = Math.floor(Math.random() * (stateBBox.x2 - stateBBox.x + 1)) + stateBBox.x;
var yRandom = Math.floor(Math.random() * (stateBBox.y2 - stateBBox.y + 1)) + stateBBox.y;
if(Raphael.isPointInsidePath(StatePath,xRandom,yRandom) === true) {
accounts[i] = paper.circle(xRandom,yRandom,2).attr({fill:"red"});
i++;
}
}
}
createVariables(random, FLPath);
我的问题是如何生成不“粘贴”到状态路径/边界的圆圈?