2012-02-10 2 views
1

Google지도 javascript V3 API를 사용하고 있으며 사각형 오버레이의 가시성 설정에 문제가 있습니다. 기본적으로, 클릭 리스너를 가지고 있고, 수신기 내부에이 코드를 가지고 :Google Maps Javascript Overlay의 가시성

var neLat = containmentCenter.lat()+ydiff; 
var neLng = containmentCenter.lng()+xdiff; 
var swLat = containmentCenter.lat()-ydiff; 
var swLng = containmentCenter.lng()-xdiff; 
nebound = google.maps.LatLng(neLat, neLng); 
swbound = google.maps.LatLng(swLat, swLng); 
crbounds = google.maps.LatLngBounds(swbound, nebound); 
var containRectangleOptions = { 
    strokeColor: "#FF0000", 
    strokeOpacity: 0.8, 
    strokeWeight: 2, 
    fillColor: "#FF0000", 
    fillOpacity: 0.35, 
    map: map, 
    bounds: crbounds, 
    editable: true, 
    visible: true 
}; 
containRectangle.setMap(map); 
containRectangle.setOptions(containRectangleOptions); 
containRectangle.setVisible(true); 
alert("Center: ("+containmentCenter.lat()+","+containmentCenter.lng()+")\nY:  
    "+ydiff+"\nX: "+xdiff+"\nVisible: "+containRectangle.getVisible()); 
containRectangle가에 리스너 위의 직사각형 내가 초기화 (내부 정의 오버레이)와 인

containRectangle = new google.maps.Rectangle(defaultRectangleOptions); 

defaultRectangleOptions은 경계가 map.getBounds()이고 visible이 false로 설정된다는 점을 제외하고는 containRectangleOptions과 완전히 동일합니다.

경고()가 올바른 좌표를 보여주고 실제로 containsRectangle.getVisible()이 true라는 사실에 관계없이 클릭 할 때 문제가되는 사각형이 보이지 않습니다. 또한 containsRectangle을 defaultRectangleOptions에 표시하려고 시도했지만 여전히 표시되지 않습니다. 또한 클릭 할 때 원을 표시하는 데 거의 동일한 코드가 있으며 올바르게 작동하지만 사각형이 표시되지 않습니다.

+0

라이브 코드에 연결하거나 JS Fiddle에 코드를 올릴 수 있습니까? 문제를 쉽게 해결할 수 있습니다. – andresf

답변

0

나는 내 자신의 문제를 해결했습니다. 경계 객체를 초기화하는 방식에서 오류가 발생했습니다. new 연산자를 사용하여 모든 것을 수정했습니다.