我有一个函数可以获取经度和纬度并将其转换为x和y进行绘图。转换到X和Y工作正常,这不是我遇到的问题。绘制点,以便它们不重叠,如果它们具有相同的坐标
我想确保两点不绘制在同一个地方。在一组结果中,大约有30个在另一个之上(因为它们具有相同的经度和纬度),这个数字可能会大得多。
目前,我试图通过移动点至点的左侧,右侧,顶部或底部,使一个正方形来实现这一目标。一旦绘制了由点组成的正方形,然后移动到下一行并在前一个正方形周围绘制另一个点的平方。
的代码是Javascript支持,但是它是非常通用的,所以我想这是稍微无关。
我的代码如下:
var prevLong, prevLat, rand = 1, line = 1, spread = 8, i = 0;
function plot_points(long, lat){
// CODE HERE TO CONVERT long and lat into x and y
// System to not overlap the points
if((prevLat == lat) && (prevLong == long)) {
if(rand==1) {
x += spread*line;
} else if(rand==2) {
x -= spread*line;
} else if(rand==3) {
y += spread*line;
} else if(rand==4) {
y -= spread*line;
} else if(rand==5) {
x += spread*line;
y += spread*line;
} else if(rand==6) {
x -= spread*line;
y -= spread*line;
} else if(rand==7) {
x += spread*line;
y -= spread*line;
} else if(rand==8) {
x -= spread*line;
y += spread*line;
// x = double
} else if(rand==9) {
x += spread*line;
y += spread;
} else if(rand==10) {
x += spread;
y += spread*line;
} else if(rand==11) {
x -= spread*line;
y -= spread;
} else if(rand==12) {
x -= spread;
y -= spread*line;
} else if(rand==13) {
x += spread*line;
y -= spread;
} else if(rand==14) {
x += spread;
y -= spread*line;
} else if(rand==15) {
x += spread*line;
y -= spread;
} else if(rand==16) {
x += spread;
y -= spread*line;
} else if(rand==17) {
x -= spread*line;
y += spread;
} else if(rand==18) {
x -= spread;
y += spread*line;
} else if(rand==19) {
x -= spread*line;
y += spread;
} else if(rand==20) {
x -= spread;
y += spread*line;
}
if(rand == 20) {rand = 1; line++; } else { rand++; }
i++
} else {
line = 1;
i = 0;
}
prevLat = latitude;
prevLong = longitude;
return [x,y];
}
这是输出:
它不能正常工作,我甚至不知道如果我以正确的方式接近问题在所有。
有没有人需要这样做?你会建议什么方法?
你是否打开到密度表示的备选implmentations?要么通过直径,颜色或其他变体? – 2010-04-16 18:04:37
您的意思是,例如,将具有相同坐标的点合并为一个点,然后使用大小/颜色来显示密度?每个点代表一个不同的数据,因此他们需要分开识别。 IE浏览器。从一个角度来看,有许多不同的值是独特的。 – betamax 2010-04-16 18:11:11
关于您的评论,我的解决方案假定所有的点都以相同的颜色呈现。我仍然认为用相同的坐标来计算点的数量比较容易,然后根据总数来排列点。这些点当然可以根据其他标准进行着色,但是可以根据计数进行排列。 – Ernelli 2010-04-16 18:31:34