오늘 :
2,083 / 350,490
어제 :
2,089 / 319,904
전체 :
22,331,307 / 324,379,810

Open API 공부

Naver, Daum, Google Open API

추천 수 : 12 / 0
조회 수 : 20916
2007.11.30 (13:52:45)


http://www.subkorea.com/api/google/MapsAPI/overlay-custom.htm구글지도와 사각(범위)표시, 콘트롤, 지도 버튼

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <title>Google Maps JavaScript API Example: Custom Overlay</title>
    <script src="http://maps.google.com/maps?file=api&v=2&key=abc...xyz"
            type="text/javascript"></script>
    <script type="text/javascript">

    // A Rectangle is a simple overlay that outlines a lat/lng bounds on the
    // map. It has a border of the given weight and color and can optionally
    // have a semi-transparent background color.
    function Rectangle(bounds, opt_weight, opt_color) {
      this.bounds_ = bounds;
      this.weight_ = opt_weight || 2;
      this.color_ = opt_color || "#888888";
    }
    Rectangle.prototype = new GOverlay();

    // Creates the DIV representing this rectangle.
    Rectangle.prototype.initialize = function(map) {
      // Create the DIV representing our rectangle
      var div = document.createElement("div");
      div.style.border = this.weight_ + "px solid " + this.color_;
      div.style.position = "absolute";

      // Our rectangle is flat against the map, so we add our selves to the
      // MAP_PANE pane, which is at the same z-index as the map itself (i.e.,
      // below the marker shadows)
      map.getPane(G_MAP_MAP_PANE).appendChild(div);

      this.map_ = map;
      this.div_ = div;
    }

    // Remove the main DIV from the map pane
    Rectangle.prototype.remove = function() {
      this.div_.parentNode.removeChild(this.div_);
    }

    // Copy our data to a new Rectangle
    Rectangle.prototype.copy = function() {
      return new Rectangle(this.bounds_, this.weight_, this.color_,
                           this.backgroundColor_, this.opacity_);
    }

    // Redraw the rectangle based on the current projection and zoom level
    Rectangle.prototype.redraw = function(force) {
      // We only need to redraw if the coordinate system has changed
      if (!force) return;

      // Calculate the DIV coordinates of two opposite corners of our bounds to
      // get the size and position of our rectangle
      var c1 = this.map_.fromLatLngToDivPixel(this.bounds_.getSouthWest());
      var c2 = this.map_.fromLatLngToDivPixel(this.bounds_.getNorthEast());

      // Now position our DIV based on the DIV coordinates of our bounds
      this.div_.style.width = Math.abs(c2.x - c1.x) + "px";
      this.div_.style.height = Math.abs(c2.y - c1.y) + "px";
      this.div_.style.left = (Math.min(c2.x, c1.x) - this.weight_) + "px";
      this.div_.style.top = (Math.min(c2.y, c1.y) - this.weight_) + "px";
    }


    function initialize() {
      if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map_canvas"));
        map.setCenter(new GLatLng(37.4419, -122.1419), 13);
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());

        // Display a rectangle in the center of the map at about a quarter of
        // the size of the main map
        var bounds = map.getBounds();
        var southWest = bounds.getSouthWest();
        var northEast = bounds.getNorthEast();
        var lngDelta = (northEast.lng() - southWest.lng()) / 4;
        var latDelta = (northEast.lat() - southWest.lat()) / 4;
        var rectBounds = new GLatLngBounds(
            new GLatLng(southWest.lat() + latDelta,
                        southWest.lng() + lngDelta),
            new GLatLng(northEast.lat() - latDelta,
                        northEast.lng() - lngDelta));
        map.addOverlay(new Rectangle(rectBounds));
      }
    }

    </script>
  </head>
  <body onload="initialize()" onunload="GUnload()">
    <div id="map_canvas" style="width: 500px; height: 300px"></div>
  </body>
</html>

번호 제목 닉네임 등록일 조회 추천
42 xhr-requests 첨부 파일
cyber
2007-11-30 19058 6
Selected overlay-custom 첨부 파일
cyber
2007-11-30 20916 12
40 tile-detector 첨부 파일
cyber
2007-11-30 18240 8
39 tileoverlay-simple 첨부 파일
cyber
2007-11-30 18946 8
38 groundoverlay-simple 첨부 파일
cyber
2007-11-30 18400 12
37 polygon-simple 첨부 파일
cyber
2007-11-30 19056 16
36 polyline-encoding 첨부 파일
cyber
2007-11-30 22171 6
35 polyline-geodesic 첨부 파일
cyber
2007-11-30 22135 8
34 polyline-simple 첨부 파일
cyber
2007-11-30 22577 6
33 marker-textfiles 첨부 파일
cyber
2007-11-30 20139 23
Tag List