는 이런 짓을하지,하지만 여기에 대한 내 생각이다 결코 :
의는이 같은 세 가지 자동차의 배열이 있다고 가정 해 봅시다 :
var cars=[{name:"car1",x:100,y:101},{name:"car2",x:99,y:101},{name:"car3",x:90,y:111}];
처음 위치하여 정렬 할 것 :
를
cars.sort(sortfunction)
function sortfunction(a, b){
return a.x - b.x + a.y - b.y
}
그런 다음지도에 자동차를 배치하면 이전 위치를 살펴보십시오. 이 근처에 있다면, 레이블 클래스를 추가 :
var label=0;
for(var i=0; i<cars.length; i++) {
if(i>=1) {
if(Math.abs(cars[i-1].x-cars[i].x+cars[i-1].y-cars[i].y)<10) {
//Add your element with a label class $("<div class='car label"+label+"' style='...'>")
console.log(cars[i-1].name+" is to near to "+cars[i].name);
label++;
}
else {
//Add your element normal $("<div class='car' style='...'>")
label=0;
}
}
}
레이블 클래스 레이블 요소를 배치한다 :이 방법을 보여줍니다
.label0 {
/* position north */
}
.label1 {
/* position west*/
}
.label2 {
/* position east*/
}
/* can go on with nw, ne, se and sw if needed*/
Here is a fiddle합니다.
_ "어디서부터 시작해야할지 모르겠다!"_ 수학 수업에서주의를 기울여 ...? – CBroe