2012-05-23 5 views
0

데이터베이스에서 여러 개의 분리 된 다각형 (건물)을 그리려합니다. 내 데이터베이스에서 얻는 데이터는 다음과 같습니다다중 다각형 MySQL

<buildings> 
    <building build_id="94" build_gebaeude="A" 
     build_geoX="49.26173942769648" build_geoY="7.350542675857582" 
    /> 
    <building build_id="95" build_gebaeude="A" 
     build_geoX="49.26173942769648" build_geoY="7.3524094933319475" 
    /> 
    <building build_id="96" build_gebaeude="A" 
     build_geoX="49.26019903253632" build_geoY="7.35234512031559" 
    /> 
    <building build_id="97" build_gebaeude="A" 
     build_geoX="49.26032506667364" build_geoY="7.350692879562416" 
    /> 
    <building build_id="98" build_gebaeude="B" 
     build_geoX="49.26155738350112" build_geoY="7.362129818801918" 
    /> 
    <building build_id="99" build_gebaeude="B" 
     build_geoX="49.26157138692462" build_geoY="7.364275586013832" 
    /> 
    <building build_id="100" build_gebaeude="B" 
     build_geoX="49.260255047748224" build_geoY="7.364361416702309" 
    /> 
    <building build_id="101" build_gebaeude="B" 
     build_geoX="49.260311062896506" build_geoY="7.362065445785561" 
    /> 
</buildings> 

다음 코드는 내가 건물을 그리는 일을하고 무엇을 보여줍니다

for (var i = 0; i < building.length-1; i++) { 
    var point = new google.maps.LatLng(
     parseFloat(building[i].getAttribute("build_geoX")), 
     parseFloat(building[i].getAttribute("build_geoY")) 
    ); 

    latlngbounds.extend(point); 

    if(building[i].getAttribute("build_gebaeude") == 
     building[i+1].getAttribute("build_gebaeude")) 
    { 
     path.push(point); 
    } 
    else { 
     path.push(point); 
     poly = new google.maps.Polygon({ 
      paths: path, 
      strokeWeight: 5, 
      strokeOpacity: 1, 
      fillOpacity: 0.30, 
      strokeColor:'#FFFFFF', 
      fillColor: '#a3141d' 
     }); 
     polygons.push(poly); 
     path.clear(); 
    } 
} 
polygons[0].setMap(map); 
polygons[1].setMap(map); 

문제는 모든 지점이 그려하지 않는 것이 무엇입니까? 문제가 어디 있는지 모르겠다.

답변

0

paths 배열에 문제가있는 것 같습니다. 그것은 당신이 paths는 자바 스크립트 Array 또는 배열과 같은 객체인지 여부를 포함 한 코드에서 분명하지 않다,하지만 당신은 for 루프 내 paths 작업 후 루프 내에서 paths을 취소하려고하기 때문에, 내가 제안 :

  • 평등
  • 변경은 건물의 특성을 확인하기 위해 사용하는 코드를 반복 및 테스트 배열의 상태를 관리하는 코드를 추가 필요로 루프 내에서 새로운 pathsArray 만들기 당신이 다각형 생성자에 경로 배열을 전달하고 있기 때문에, 당신의 문제가 정확히 무엇인지 확실하지 않다 배열
    var paths = null; 
    var aNewPathIsNeeded = true; 
    for (var i = 0; i < building.length-1; i++) { 
        //Create your point 
        //Extend your bounds 
        //Since you always add the point to the paths array, move it out of the if 
        //check and perform some array state management: 
    
        if (aNewPathIsNeeded) { 
         paths = new Array(point); 
         aNewPathIsNeeded = false; 
        } 
        else { paths.push(point); } 
    
        //Change the if condition to deal with just the specific case of interest: 
    
        var currentBldgAttr = building[i].getAttribute("build_gebaeude"); 
        var nextBldgAttr = building[i+1].getAttribute("build_gebaeude"); 
        if (!(currentBldgAttr === nextBldgAttr)) { //Change to use: '===' 
         //Create your polygon 
         //Add the polygon to the polygons array 
         //New code to manage paths state: 
         aNewPathIsNeeded = true; 
        } 
    } 
    

을 취소하지만,이 코드는 당신이 이동 도움이 될 것입니다 생각하지 않습니다 앞으로. 부수적으로, clear()은 JavaScript Array 메서드가 아닙니다. Array을 비우려면 array.length = 0을 다음과 같이 사용하십시오. Is JavaScript's array.clear() not a function?