2012-06-22 2 views
0

Google 어스 응용 프로그램을 개발하는 데있어 새로운 기능입니다. 장소 표시를 가져 오는 방법을 알고 싶습니다. 인바운드 폴리곤을 그립니다. 미리 감사드립니다.다각형 google 어스 api 내 장소 표시 가져 오기

내 코드

var ge; 
var pm = null; 
var isMouseDown = false; 
var lineStringPlacemark = null; 
var coords = null; 
var pointCount = 0; 
var doc = null; 
var markers = []; 
var polygons; 

google.load("earth", "1"); 

function init() { 
    google.earth.createInstance('map', initCB, failureCB); 

} 

function initCB(instance) { 
    ge = instance; 
    ge.getWindow().setVisibility(true); 
    // add a navigation control 
    ge.getNavigationControl().setVisibility(ge.VISIBILITY_AUTO); 

    //create document 
    doc = ge.createDocument(''); 
    ge.getFeatures().appendChild(doc); 

    // add some event 
    google.earth.addEventListener(ge.getGlobe(), 'mousemove', onmousemove); 
    google.earth.addEventListener(ge.getGlobe(), 'mousedown', function(event) { onmousedown(event); }); 

    loadData(ge); 
} 

function failureCB(errorCode) { 
    alert(errorCode); 
} 

google.setOnLoadCallback(init); 

function loadData(ge){ 
    EarthRequest = new htmldb_Get(null,$v('pFlowId'),'APPLICATION_PROCESS=LoadEarthData',$v('pFlowStepId')); 
    EarthData = EarthRequest.get(); 

    if (EarthData) { 
     var data = jQuery.parseJSON(EarthData); 
     //printObject(data.row); 
     $.each(data.row,function(item){ 
      latitude = parseFloat(data.row[item]['LATITUDE']); 
      longitude = parseFloat(data.row[item]['LONGITUDE']); 
      if(latitude==0 || longitude==0 || isNaN(latitude) || isNaN(longitude)){ 
       //do nothing 
      } 
      else{ 
       marker = createMarker(ge,data.row[item]['CELL_ID']+' '+data.row[item]['SITE_NAME'],latitude ,longitude,data.row[item]['CELL_ID']); 
       if(marker){ 
      markers.push(marker); 
     } 
      } 
     }); 

    var la = ge.createLookAt(''); 
    la.set(latitude, longitude, 
     0, 
     ge.ALTITUDE_RELATIVE_TO_GROUND, 
     0, 
     0, 
     5000 
    ); 
    ge.getView().setAbstractView(la); 
    } 
} 

function createMarker(ge,placeName,latitude,longitude,placeId){ 
    placemark = ge.createPlacemark(''); 

    var icon = ge.createIcon(''); 
    icon.setHref('map_new.png'); 
    var style = ge.createStyle(''); //create a new style 
    style.getIconStyle().setIcon(icon); 

    var lat = parseFloat(latitude); 
    var lon = parseFloat(longitude); 
    var point = ge.createPoint(''); 
    point.setLatitude(lat); 
    point.setLongitude(lon); 

    placemark.setStyleSelector(style); //apply the style to the placemark 
    placemark.setGeometry(point); 

    // add the placemark to the earth DOM 
    ge.getFeatures().appendChild(placemark); 

    placemark.setName(placeName); 

    google.earth.addEventListener(placemark, 'click', function(event) { 
     loadPlaceDetail(placeId); 
    }); 

    return placemark; 
} 

function onmousemove(event) { 
    if (isMouseDown) { 
    coords.pushLatLngAlt(event.getLatitude(), event.getLongitude(), 0); 
    } 
} 

//convert line to polygon 
function convertLineStringToPolygon(placemark) { 
    var polygon = ge.createPolygon(''); 
    var outer = ge.createLinearRing(''); 
    polygon.setOuterBoundary(outer); 

    var lineString = placemark.getGeometry(); 
    for (var i = 0; i < lineString.getCoordinates().getLength(); i++) { 
    var coord = lineString.getCoordinates().get(i); 
    outer.getCoordinates().pushLatLngAlt(coord.getLatitude(), 
            coord.getLongitude(), 
            coord.getAltitude()); 
    } 
    placemark.setGeometry(polygon); 
    return polygon; 
} 

//mouse click event 
function onmousedown(event) { 
    if (isMouseDown) { 
     var lastdoc = doc.getFeatures().getChildNodes().getLength(); 

     isMouseDown = false; 
     coords.pushLatLngAlt(event.getLatitude(), event.getLongitude(), 0); 
     convertLineStringToPolygon(lineStringPlacemark); 
    if(lastdoc>1){ 
     doc.getFeatures().removeChild(doc.getFeatures().getFirstChild()); 
       //I want to add some function to calculate polygon bound 
     } 

    } else { 
    if(event.getAltKey()){ 

     isMouseDown = true; 
     lineStringPlacemark = ge.createPlacemark(''); 
     var lineString = ge.createLineString(''); 
     lineStringPlacemark.setGeometry(lineString); 
     lineString.setTessellate(true); 
     lineString.setAltitudeMode(ge.ALTITUDE_CLAMP_TO_GROUND); 

     lineStringPlacemark.setStyleSelector(ge.createStyle('')); 
     var lineStyle = lineStringPlacemark.getStyleSelector().getLineStyle(); 
     lineStyle.setWidth(4); 
     lineStyle.getColor().set('ddffffff'); // aabbggrr formatx 
     lineStyle.setColorMode(ge.COLOR_RANDOM); 
     var polyStyle = lineStringPlacemark.getStyleSelector().getPolyStyle(); 
     polyStyle.getColor().set('ddffffff'); // aabbggrr format 
     polyStyle.setColorMode(ge.COLOR_RANDOM); 

     coords = lineString.getCoordinates(); 
     coords.pushLatLngAlt(event.getLatitude(), event.getLongitude(), 0); 

     //doc = ge.createDocument(''); 
     doc.getFeatures().appendChild(lineStringPlacemark); 
    } 
    } 
} 

그래서 convertLineStringToPolygon 실행 후, 나는 바인딩 다각형을 얻고 데이터를 다시로드해야합니다. 바운드 내의 위치가 폴리곤을 만들고 아이콘을 건너 뛰지 않는 경우. Google지도는 GPolygon.Contains() 메소드를 사용할 수 있습니다. http://econym.org.uk/gmap/example_inside.htm

+0

시도해 보았던 코드를 입력하십시오. Stackoverflow [연구 조수가 아닙니다] (http://meta.stackexchange.com/a/128553/188968). –

+0

코드를 추가했습니다. – user1474000

답변

0

GEarthExtensions point in poly

의 예는 http://code.google.com/p/earth-api-utility-library/

이 사용하는 구글 어스의 확장자 라이브러리를 사용하지만 구글 어스에 대해 아직 해결책 여기

을 ecoynm에서 예를 들어 구글 맵이있어 찾을 수 없습니다 마우스 이동 이벤트

google.earth.addEventListener(ge.getGlobe(), 'mousemove', function(evt) { 
    var poly = new geo.Polygon(pts); 
    var contains = poly.containsPoint(
     new geo.Point(evt.getLatitude(), evt.getLongitude())); 
    placemark.setStyleSelector(contains ? onStyle : offStyle); 
}); 
관련 문제