설 연수
하하호홓
설 연수
전체 방문자
오늘
어제
  • 분류 전체보기 (231)
    • Back-End (2)
      • Java (20)
      • JSP (13)
      • Spring (18)
      • Kotlin (0)
      • node.js (0)
    • Front-End (68)
      • JavaScript (19)
      • jQuery (39)
      • Angular (4)
      • HTML (5)
    • Dev-Ops (12)
      • Linux, Cloud (5)
      • docker, k8s (5)
      • ElasticSeach (2)
    • Other (33)
      • OOP (3)
      • 알고리즘 (2)
      • DB (12)
      • Git (1)
      • Swift (4)
    • Backup (65)

블로그 메뉴

    공지사항

    인기 글

    태그

    • angular4
    • INVALID
    • docker
    • flex
    • Redis
    • Angular
    • angular2
    • jOOQ
    • MYSQL
    • 크로스도메인
    • 404 error
    • 패스트캠퍼스
    • angular 콜백
    • jquery invalid
    • page not found
    • CORS
    • RESTful
    • angular callback
    • mongodb
    • Kafka

    최근 댓글

    최근 글

    티스토리

    hELLO · Designed By 정상우.
    설 연수

    하하호홓

    Backup

    구글맵 - 컨트롤에 상태 추가하기 (예제 - 위치저장하기)

    2012. 4. 18. 11:51

    컨트롤에 상태 추가하기

    컨트롤이 상태를 보관할 수도 있습니다. 다음 예는 위에 표시된 예와 비슷하지만, 새로운 홈 위치를 표시하도록 컨트롤을 설정하는 추가 '홈 설정' 버튼이 컨트롤에 포함됩니다. 이 작업은 컨트롤에 상태를 저장하고 해당 상태에 대한 getters 및 setters를 제공할 home_ 속성을 만들어서 수행합니다.

    var map;
    var chicago = new google.maps.LatLng(41.850033, -87.6500523);

    /**
     * The HomeControl adds a control to the map that
     * returns the user to the control's defined home.
     */


    // Define a property to hold the Home state
    HomeControl.prototype.home_ = null;

    // Define setters and getters for this property
    HomeControl.prototype.getHome = function() {
     
    return this.home_;
    }

    HomeControl.prototype.setHome = function(home) {
     
    this.home_ = home;
    }

    function HomeControl(map, div, home) {

     
    // Get the control DIV. We'll attach our control UI to this DIV.
     
    var controlDiv = div;

     
    // We set up a variable for the 'this' keyword since we're adding event
     
    // listeners later and 'this' will be out of scope.
     
    var control = this;

     
    // Set the home property upon construction
      control
    .home_ = home;

     
    // Set CSS styles for the DIV containing the control. Setting padding to
     
    // 5 px will offset the control from the edge of the map
      controlDiv
    .style.padding = '5px';

     
    // Set CSS for the control border
     
    var goHomeUI = document.createElement('DIV');
      goHomeUI
    .title = 'Click to set the map to Home';
      controlDiv
    .appendChild(goHomeUI);

     
    // Set CSS for the control interior
     
    var goHomeText = document.createElement('DIV');
      goHomeText
    .innerHTML = 'Home';
      goHomeUI
    .appendChild(goHomeText);
     
     
    // Set CSS for the setHome control border
     
    var setHomeUI = document.createElement('DIV');
      setHomeUI
    .title = 'Click to set Home to the current center';
      controlDiv
    .appendChild(setHomeUI);

     
    // Set CSS for the control interior
     
    var setHomeText = document.createElement('DIV');
      setHomeText
    .innerHTML = 'Set Home';
      setHomeUI
    .appendChild(setHomeText);

     
    // Setup the click event listener for Home:
     
    // simply set the map to the control's current home property.
      google
    .maps.event.addDomListener(goHomeUI, 'click', function() {
       
    var currentHome = control.getHome();
        map
    .setCenter(currentHome);
     
    });

     
    // Setup the click event listener for Set Home:
     
    // Set the control's home to the current Map center.
      google
    .maps.event.addDomListener(setHomeUI, 'click', function() {
       
    var newHome = map.getCenter();
        control
    .setHome(newHome);
     
    });
    }

    function initialize() {
     
    var mapDiv = document.getElementById('map_canvas');
     
    var myOptions = {
        zoom
    : 12,
        center
    : chicago,
        mapTypeId
    : google.maps.MapTypeId.ROADMAP
     
    }
      map
    = new google.maps.Map(mapDiv, myOptions);

     
    // Create the DIV to hold the control and call the HomeControl()
     
    // constructor passing in this DIV.
     
    var homeControlDiv = document.createElement('DIV');
     
    var homeControl = new HomeControl(map, homeControlDiv, chicago);

      homeControlDiv
    .index = 1;
      map
    .controls[google.maps.ControlPosition.TOP_RIGHT].push(homeControlDiv);
    }

    예 보기(control-custom-state.html)

    'Backup' 카테고리의 다른 글

    구글맵 - 오버레이(마커) 찍기  (0) 2012.04.18
    구글맵 - 스타일링  (0) 2012.04.18
    구글맵 - 맞춤형 컨트롤  (0) 2012.04.18
    구글맵 - 컨트롤 배치  (0) 2012.04.18
    구글맵 - 컨트롤 옵션  (0) 2012.04.18
      'Backup' 카테고리의 다른 글
      • 구글맵 - 오버레이(마커) 찍기
      • 구글맵 - 스타일링
      • 구글맵 - 맞춤형 컨트롤
      • 구글맵 - 컨트롤 배치
      설 연수
      설 연수

      티스토리툴바