কাস্টম ওভারলে

প্ল্যাটফর্ম নির্বাচন করুন: অ্যান্ড্রয়েড আইওএস জাভাস্ক্রিপ্ট

ভূমিকা

ওভারলেগুলি হল মানচিত্রের বস্তু যা অক্ষাংশ/দ্রাঘিমাংশ স্থানাঙ্কের সাথে আবদ্ধ, তাই আপনি যখন মানচিত্রটি টেনে বা জুম করেন তখন তারা সরে যায়। পূর্বনির্ধারিত ওভারলে প্রকারের তথ্যের জন্য, মানচিত্রে অঙ্কন দেখুন।

মানচিত্র জাভাস্ক্রিপ্ট API আপনার নিজস্ব কাস্টম ওভারলে তৈরি করার জন্য একটি OverlayView ক্লাস প্রদান করে। OverlayView হল একটি বেস ক্লাস যা আপনার ওভারলে তৈরি করার সময় আপনাকে অবশ্যই প্রয়োগ করতে হবে এমন বেশ কয়েকটি পদ্ধতি প্রদান করে। ক্লাসটি কয়েকটি পদ্ধতিও প্রদান করে যা স্ক্রীন স্থানাঙ্ক এবং মানচিত্রের অবস্থানগুলির মধ্যে অনুবাদ করা সম্ভব করে।

একটি কাস্টম ওভারলে যোগ করুন

এখানে একটি কাস্টম ওভারলে তৈরি করার জন্য প্রয়োজনীয় পদক্ষেপগুলির একটি সারাংশ রয়েছে:

  • google.maps.OverlayView() এর একটি নতুন উদাহরণে আপনার কাস্টম ওভারলে অবজেক্টের prototype সেট করুন। কার্যত, এটি ওভারলে ক্লাসকে সাবক্লাস করবে।
  • আপনার কাস্টম ওভারলে জন্য একটি কনস্ট্রাক্টর তৈরি করুন, এবং যে কোনো প্রারম্ভিক পরামিতি সেট করুন।
  • আপনার প্রোটোটাইপের মধ্যে একটি onAdd() পদ্ধতি প্রয়োগ করুন এবং মানচিত্রে ওভারলে সংযুক্ত করুন। ওভারলে সংযুক্ত করার জন্য মানচিত্র প্রস্তুত হলে OverlayView.onAdd() কল করা হবে।
  • আপনার প্রোটোটাইপের মধ্যে একটি draw() পদ্ধতি প্রয়োগ করুন এবং আপনার বস্তুর ভিজ্যুয়াল ডিসপ্লে পরিচালনা করুন। যখন বস্তুটি প্রথম প্রদর্শিত হবে তখন OverlayView.draw() কল করা হবে।
  • আপনি ওভারলে এর মধ্যে যোগ করা কোনো উপাদান পরিষ্কার করতে একটি onRemove() পদ্ধতি প্রয়োগ করতে হবে।

নীচে প্রতিটি ধাপে আরও বিশদ রয়েছে। আপনি সম্পূর্ণ, কাজের উদাহরণ কোড দেখতে পারেন: উদাহরণ কোড দেখুন

ওভারলে সাবক্লাস করুন

নীচের উদাহরণটি একটি সাধারণ চিত্র ওভারলে তৈরি করতে OverlayView ব্যবহার করে।

এখন আমরা USGSOverlay ক্লাসের জন্য একটি কনস্ট্রাক্টর তৈরি করি এবং পাস করা প্যারামিটারগুলিকে নতুন অবজেক্টের বৈশিষ্ট্য হিসাবে শুরু করি।

টাইপস্ক্রিপ্ট

/**
 * The custom USGSOverlay object contains the USGS image,
 * the bounds of the image, and a reference to the map.
 */
class USGSOverlay extends google.maps.OverlayView {
  private bounds: google.maps.LatLngBounds;
  private image: string;
  private div?: HTMLElement;

  constructor(bounds: google.maps.LatLngBounds, image: string) {
    super();

    this.bounds = bounds;
    this.image = image;
  }

জাভাস্ক্রিপ্ট

/**
 * The custom USGSOverlay object contains the USGS image,
 * the bounds of the image, and a reference to the map.
 */
class USGSOverlay extends google.maps.OverlayView {
  bounds;
  image;
  div;
  constructor(bounds, image) {
    super();
    this.bounds = bounds;
    this.image = image;
  }

আমরা এখনও ওভারলে কনস্ট্রাক্টরে মানচিত্রের সাথে এই ওভারলে সংযুক্ত করতে পারি না। প্রথমত, আমাদের নিশ্চিত করতে হবে যে মানচিত্রের সমস্ত প্যান উপলব্ধ রয়েছে, কারণ তারা একটি মানচিত্রে কোন বস্তুগুলিকে প্রদর্শিত হবে তা নির্দিষ্ট করে। API একটি সহায়ক পদ্ধতি প্রদান করে যা নির্দেশ করে যে এটি ঘটেছে। আমরা পরবর্তী বিভাগে সেই পদ্ধতিটি পরিচালনা করব।

ওভারলে শুরু করুন

যখন ওভারলে প্রথম তাৎক্ষণিক হয় এবং প্রদর্শনের জন্য প্রস্তুত হয়, তখন আমাদের ব্রাউজারের DOM এর মাধ্যমে মানচিত্রের সাথে সংযুক্ত করতে হবে। API নির্দেশ করে যে ওভারলে-এর onAdd() পদ্ধতি ব্যবহার করে ওভারলে মানচিত্রে যোগ করা হয়েছে। এই পদ্ধতিটি পরিচালনা করার জন্য আমরা আমাদের ছবি ধরে রাখার জন্য একটি <div> তৈরি করি, একটি <img> উপাদান যোগ করি, এটি <div> এর সাথে সংযুক্ত করি এবং তারপর মানচিত্রের একটি প্যানে ওভারলে সংযুক্ত করি। একটি ফলক হল DOM গাছের মধ্যে একটি নোড।

MapPanes টাইপের প্যানগুলি মানচিত্রে বিভিন্ন স্তরের জন্য স্ট্যাকিং অর্ডার নির্দিষ্ট করে। নিম্নলিখিত প্যানগুলি উপলব্ধ, এবং ক্রমানুসারে গণনা করা হয় যাতে সেগুলি নীচে থেকে উপরে স্ট্যাক করা হয়:

  • mapPane হল সর্বনিম্ন ফলক এবং টাইলসের উপরে। এটি DOM ইভেন্টগুলি নাও পেতে পারে৷ (প্যান 0)।
  • overlayLayer পলিলাইন, বহুভুজ, গ্রাউন্ড ওভারলে এবং টাইল লেয়ার ওভারলে রয়েছে। এটি DOM ইভেন্টগুলি নাও পেতে পারে৷ (প্যান 1)।
  • markerLayer মার্কার ধারণ করে। এটি DOM ইভেন্টগুলি নাও পেতে পারে৷ (প্যান 2)।
  • overlayMouseTarget উপাদান রয়েছে যা DOM ইভেন্টগুলি গ্রহণ করে। (প্যান 3)।
  • floatPane তথ্য উইন্ডো ধারণ করে। এটা সব মানচিত্র ওভারলে উপরে. (প্যান 4)।

কারণ আমাদের ছবিটি একটি "গ্রাউন্ড ওভারলে", আমরা overlayLayer প্যান ব্যবহার করব। যখন আমাদের সেই ফলকটি থাকবে, তখন আমরা শিশু হিসাবে এটির সাথে আমাদের বস্তু সংযুক্ত করব।

টাইপস্ক্রিপ্ট

/**
 * onAdd is called when the map's panes are ready and the overlay has been
 * added to the map.
 */
onAdd() {
  this.div = document.createElement("div");
  this.div.style.borderStyle = "none";
  this.div.style.borderWidth = "0px";
  this.div.style.position = "absolute";

  // Create the img element and attach it to the div.
  const img = document.createElement("img");

  img.src = this.image;
  img.style.width = "100%";
  img.style.height = "100%";
  img.style.position = "absolute";
  this.div.appendChild(img);

  // Add the element to the "overlayLayer" pane.
  const panes = this.getPanes()!;

  panes.overlayLayer.appendChild(this.div);
}

জাভাস্ক্রিপ্ট

/**
 * onAdd is called when the map's panes are ready and the overlay has been
 * added to the map.
 */
onAdd() {
  this.div = document.createElement("div");
  this.div.style.borderStyle = "none";
  this.div.style.borderWidth = "0px";
  this.div.style.position = "absolute";

  // Create the img element and attach it to the div.
  const img = document.createElement("img");

  img.src = this.image;
  img.style.width = "100%";
  img.style.height = "100%";
  img.style.position = "absolute";
  this.div.appendChild(img);

  // Add the element to the "overlayLayer" pane.
  const panes = this.getPanes();

  panes.overlayLayer.appendChild(this.div);
}

ওভারলে আঁকুন

উল্লেখ্য যে আমরা উপরের কোডে কোনো বিশেষ ভিজ্যুয়াল ডিসপ্লে চালু করিনি। এপিআই যখনই ম্যাপে ওভারলে আঁকতে হবে তখন ওভারলেতে একটি আলাদা draw() পদ্ধতি ব্যবহার করে, প্রথমবার যোগ করা সহ।

তাই আমরা এই draw() পদ্ধতিটি বাস্তবায়ন করব, getProjection() ব্যবহার করে ওভারলে এর MapCanvasProjection পুনরুদ্ধার করব এবং সঠিক স্থানাঙ্কগুলি গণনা করব যেখানে বস্তুর উপরের ডানদিকে এবং নীচের বাম বিন্দুতে অ্যাঙ্কর করতে হবে। তারপর আমরা <div> আকার পরিবর্তন করতে পারি। পরিবর্তে এটি ওভারলে কনস্ট্রাক্টরে আমরা নির্দিষ্ট করা সীমার সাথে মেলে চিত্রটির আকার পরিবর্তন করবে।

টাইপস্ক্রিপ্ট

draw() {
  // We use the south-west and north-east
  // coordinates of the overlay to peg it to the correct position and size.
  // To do this, we need to retrieve the projection from the overlay.
  const overlayProjection = this.getProjection();

  // Retrieve the south-west and north-east coordinates of this overlay
  // in LatLngs and convert them to pixel coordinates.
  // We'll use these coordinates to resize the div.
  const sw = overlayProjection.fromLatLngToDivPixel(
    this.bounds.getSouthWest()
  )!;
  const ne = overlayProjection.fromLatLngToDivPixel(
    this.bounds.getNorthEast()
  )!;

  // Resize the image's div to fit the indicated dimensions.
  if (this.div) {
    this.div.style.left = sw.x + "px";
    this.div.style.top = ne.y + "px";
    this.div.style.width = ne.x - sw.x + "px";
    this.div.style.height = sw.y - ne.y + "px";
  }
}

জাভাস্ক্রিপ্ট

draw() {
  // We use the south-west and north-east
  // coordinates of the overlay to peg it to the correct position and size.
  // To do this, we need to retrieve the projection from the overlay.
  const overlayProjection = this.getProjection();
  // Retrieve the south-west and north-east coordinates of this overlay
  // in LatLngs and convert them to pixel coordinates.
  // We'll use these coordinates to resize the div.
  const sw = overlayProjection.fromLatLngToDivPixel(
    this.bounds.getSouthWest(),
  );
  const ne = overlayProjection.fromLatLngToDivPixel(
    this.bounds.getNorthEast(),
  );

  // Resize the image's div to fit the indicated dimensions.
  if (this.div) {
    this.div.style.left = sw.x + "px";
    this.div.style.top = ne.y + "px";
    this.div.style.width = ne.x - sw.x + "px";
    this.div.style.height = sw.y - ne.y + "px";
  }
}

একটি কাস্টম ওভারলে সরান

মানচিত্র থেকে ওভারলে পরিষ্কারভাবে মুছে ফেলার জন্য আমরা একটি onRemove() পদ্ধতি যোগ করি।

টাইপস্ক্রিপ্ট

/**
 * The onRemove() method will be called automatically from the API if
 * we ever set the overlay's map property to 'null'.
 */
onRemove() {
  if (this.div) {
    (this.div.parentNode as HTMLElement).removeChild(this.div);
    delete this.div;
  }
}

জাভাস্ক্রিপ্ট

/**
 * The onRemove() method will be called automatically from the API if
 * we ever set the overlay's map property to 'null'.
 */
onRemove() {
  if (this.div) {
    this.div.parentNode.removeChild(this.div);
    delete this.div;
  }
}

একটি কাস্টম ওভারলে লুকান এবং দেখান৷

আপনি যদি একটি ওভারলে তৈরি বা অপসারণ না করে লুকাতে বা প্রদর্শন করতে চান, তাহলে ওভারলেটির দৃশ্যমানতা সামঞ্জস্য করতে আপনি আপনার নিজস্ব hide() এবং show() পদ্ধতি প্রয়োগ করতে পারেন। বিকল্পভাবে, আপনি মানচিত্রের DOM থেকে ওভারলে আলাদা করতে পারেন, যদিও এই অপারেশনটি একটু বেশি ব্যয়বহুল। মনে রাখবেন যে আপনি যদি ওভারলেটিকে মানচিত্রের DOM-এ পুনরায় সংযুক্ত করেন, তাহলে এটি ওভারলে-এর onAdd() পদ্ধতি পুনরায় চালু করবে।

নিম্নলিখিত উদাহরণটি ওভারলে এর প্রোটোটাইপে hide() এবং show() পদ্ধতি যুক্ত করে যা কন্টেইনার <div> এর দৃশ্যমানতা টগল করে। উপরন্তু, আমরা একটি toggleDOM() পদ্ধতি যোগ করি, যা মানচিত্রের সাথে/থেকে ওভারলে সংযুক্ত করে বা বিচ্ছিন্ন করে।

টাইপস্ক্রিপ্ট

/**
 *  Set the visibility to 'hidden' or 'visible'.
 */
hide() {
  if (this.div) {
    this.div.style.visibility = "hidden";
  }
}

show() {
  if (this.div) {
    this.div.style.visibility = "visible";
  }
}

toggle() {
  if (this.div) {
    if (this.div.style.visibility === "hidden") {
      this.show();
    } else {
      this.hide();
    }
  }
}

toggleDOM(map: google.maps.Map) {
  if (this.getMap()) {
    this.setMap(null);
  } else {
    this.setMap(map);
  }
}

জাভাস্ক্রিপ্ট

/**
 *  Set the visibility to 'hidden' or 'visible'.
 */
hide() {
  if (this.div) {
    this.div.style.visibility = "hidden";
  }
}
show() {
  if (this.div) {
    this.div.style.visibility = "visible";
  }
}
toggle() {
  if (this.div) {
    if (this.div.style.visibility === "hidden") {
      this.show();
    } else {
      this.hide();
    }
  }
}
toggleDOM(map) {
  if (this.getMap()) {
    this.setMap(null);
  } else {
    this.setMap(map);
  }
}

বোতাম নিয়ন্ত্রণ যোগ করুন

toggle এবং toggleDom পদ্ধতিগুলিকে ট্রিগার করতে, বোতাম নিয়ন্ত্রণগুলি মানচিত্রে যোগ করা হয়।

টাইপস্ক্রিপ্ট

const toggleButton = document.createElement("button");

toggleButton.textContent = "Toggle";
toggleButton.classList.add("custom-map-control-button");

const toggleDOMButton = document.createElement("button");

toggleDOMButton.textContent = "Toggle DOM Attachment";
toggleDOMButton.classList.add("custom-map-control-button");

toggleButton.addEventListener("click", () => {
  overlay.toggle();
});

toggleDOMButton.addEventListener("click", () => {
  overlay.toggleDOM(map);
});

map.controls[google.maps.ControlPosition.TOP_RIGHT].push(toggleDOMButton);
map.controls[google.maps.ControlPosition.TOP_RIGHT].push(toggleButton);

জাভাস্ক্রিপ্ট

const toggleButton = document.createElement("button");

toggleButton.textContent = "Toggle";
toggleButton.classList.add("custom-map-control-button");

const toggleDOMButton = document.createElement("button");

toggleDOMButton.textContent = "Toggle DOM Attachment";
toggleDOMButton.classList.add("custom-map-control-button");
toggleButton.addEventListener("click", () => {
  overlay.toggle();
});
toggleDOMButton.addEventListener("click", () => {
  overlay.toggleDOM(map);
});
map.controls[google.maps.ControlPosition.TOP_RIGHT].push(toggleDOMButton);
map.controls[google.maps.ControlPosition.TOP_RIGHT].push(toggleButton);

সম্পূর্ণ নমুনা কোড

সম্পূর্ণ নমুনা কোড নীচে:

টাইপস্ক্রিপ্ট

// This example adds hide() and show() methods to a custom overlay's prototype.
// These methods toggle the visibility of the container <div>.
// overlay to or from the map.

function initMap(): void {
  const map = new google.maps.Map(
    document.getElementById("map") as HTMLElement,
    {
      zoom: 11,
      center: { lat: 62.323907, lng: -150.109291 },
      mapTypeId: "satellite",
    }
  );

  const bounds = new google.maps.LatLngBounds(
    new google.maps.LatLng(62.281819, -150.287132),
    new google.maps.LatLng(62.400471, -150.005608)
  );

  // The photograph is courtesy of the U.S. Geological Survey.
  let image = "https://developers.google.com/maps/documentation/javascript/";

  image += "examples/full/images/talkeetna.png";

  /**
   * The custom USGSOverlay object contains the USGS image,
   * the bounds of the image, and a reference to the map.
   */
  class USGSOverlay extends google.maps.OverlayView {
    private bounds: google.maps.LatLngBounds;
    private image: string;
    private div?: HTMLElement;

    constructor(bounds: google.maps.LatLngBounds, image: string) {
      super();

      this.bounds = bounds;
      this.image = image;
    }

    /**
     * onAdd is called when the map's panes are ready and the overlay has been
     * added to the map.
     */
    onAdd() {
      this.div = document.createElement("div");
      this.div.style.borderStyle = "none";
      this.div.style.borderWidth = "0px";
      this.div.style.position = "absolute";

      // Create the img element and attach it to the div.
      const img = document.createElement("img");

      img.src = this.image;
      img.style.width = "100%";
      img.style.height = "100%";
      img.style.position = "absolute";
      this.div.appendChild(img);

      // Add the element to the "overlayLayer" pane.
      const panes = this.getPanes()!;

      panes.overlayLayer.appendChild(this.div);
    }

    draw() {
      // We use the south-west and north-east
      // coordinates of the overlay to peg it to the correct position and size.
      // To do this, we need to retrieve the projection from the overlay.
      const overlayProjection = this.getProjection();

      // Retrieve the south-west and north-east coordinates of this overlay
      // in LatLngs and convert them to pixel coordinates.
      // We'll use these coordinates to resize the div.
      const sw = overlayProjection.fromLatLngToDivPixel(
        this.bounds.getSouthWest()
      )!;
      const ne = overlayProjection.fromLatLngToDivPixel(
        this.bounds.getNorthEast()
      )!;

      // Resize the image's div to fit the indicated dimensions.
      if (this.div) {
        this.div.style.left = sw.x + "px";
        this.div.style.top = ne.y + "px";
        this.div.style.width = ne.x - sw.x + "px";
        this.div.style.height = sw.y - ne.y + "px";
      }
    }

    /**
     * The onRemove() method will be called automatically from the API if
     * we ever set the overlay's map property to 'null'.
     */
    onRemove() {
      if (this.div) {
        (this.div.parentNode as HTMLElement).removeChild(this.div);
        delete this.div;
      }
    }

    /**
     *  Set the visibility to 'hidden' or 'visible'.
     */
    hide() {
      if (this.div) {
        this.div.style.visibility = "hidden";
      }
    }

    show() {
      if (this.div) {
        this.div.style.visibility = "visible";
      }
    }

    toggle() {
      if (this.div) {
        if (this.div.style.visibility === "hidden") {
          this.show();
        } else {
          this.hide();
        }
      }
    }

    toggleDOM(map: google.maps.Map) {
      if (this.getMap()) {
        this.setMap(null);
      } else {
        this.setMap(map);
      }
    }
  }

  const overlay: USGSOverlay = new USGSOverlay(bounds, image);

  overlay.setMap(map);

  const toggleButton = document.createElement("button");

  toggleButton.textContent = "Toggle";
  toggleButton.classList.add("custom-map-control-button");

  const toggleDOMButton = document.createElement("button");

  toggleDOMButton.textContent = "Toggle DOM Attachment";
  toggleDOMButton.classList.add("custom-map-control-button");

  toggleButton.addEventListener("click", () => {
    overlay.toggle();
  });

  toggleDOMButton.addEventListener("click", () => {
    overlay.toggleDOM(map);
  });

  map.controls[google.maps.ControlPosition.TOP_RIGHT].push(toggleDOMButton);
  map.controls[google.maps.ControlPosition.TOP_RIGHT].push(toggleButton);
}

declare global {
  interface Window {
    initMap: () => void;
  }
}
window.initMap = initMap;

জাভাস্ক্রিপ্ট

// This example adds hide() and show() methods to a custom overlay's prototype.
// These methods toggle the visibility of the container <div>.
// overlay to or from the map.
function initMap() {
  const map = new google.maps.Map(document.getElementById("map"), {
    zoom: 11,
    center: { lat: 62.323907, lng: -150.109291 },
    mapTypeId: "satellite",
  });
  const bounds = new google.maps.LatLngBounds(
    new google.maps.LatLng(62.281819, -150.287132),
    new google.maps.LatLng(62.400471, -150.005608),
  );
  // The photograph is courtesy of the U.S. Geological Survey.
  let image = "https://developers.google.com/maps/documentation/javascript/";

  image += "examples/full/images/talkeetna.png";
  /**
   * The custom USGSOverlay object contains the USGS image,
   * the bounds of the image, and a reference to the map.
   */
  class USGSOverlay extends google.maps.OverlayView {
    bounds;
    image;
    div;
    constructor(bounds, image) {
      super();
      this.bounds = bounds;
      this.image = image;
    }
    /**
     * onAdd is called when the map's panes are ready and the overlay has been
     * added to the map.
     */
    onAdd() {
      this.div = document.createElement("div");
      this.div.style.borderStyle = "none";
      this.div.style.borderWidth = "0px";
      this.div.style.position = "absolute";

      // Create the img element and attach it to the div.
      const img = document.createElement("img");

      img.src = this.image;
      img.style.width = "100%";
      img.style.height = "100%";
      img.style.position = "absolute";
      this.div.appendChild(img);

      // Add the element to the "overlayLayer" pane.
      const panes = this.getPanes();

      panes.overlayLayer.appendChild(this.div);
    }
    draw() {
      // We use the south-west and north-east
      // coordinates of the overlay to peg it to the correct position and size.
      // To do this, we need to retrieve the projection from the overlay.
      const overlayProjection = this.getProjection();
      // Retrieve the south-west and north-east coordinates of this overlay
      // in LatLngs and convert them to pixel coordinates.
      // We'll use these coordinates to resize the div.
      const sw = overlayProjection.fromLatLngToDivPixel(
        this.bounds.getSouthWest(),
      );
      const ne = overlayProjection.fromLatLngToDivPixel(
        this.bounds.getNorthEast(),
      );

      // Resize the image's div to fit the indicated dimensions.
      if (this.div) {
        this.div.style.left = sw.x + "px";
        this.div.style.top = ne.y + "px";
        this.div.style.width = ne.x - sw.x + "px";
        this.div.style.height = sw.y - ne.y + "px";
      }
    }
    /**
     * The onRemove() method will be called automatically from the API if
     * we ever set the overlay's map property to 'null'.
     */
    onRemove() {
      if (this.div) {
        this.div.parentNode.removeChild(this.div);
        delete this.div;
      }
    }
    /**
     *  Set the visibility to 'hidden' or 'visible'.
     */
    hide() {
      if (this.div) {
        this.div.style.visibility = "hidden";
      }
    }
    show() {
      if (this.div) {
        this.div.style.visibility = "visible";
      }
    }
    toggle() {
      if (this.div) {
        if (this.div.style.visibility === "hidden") {
          this.show();
        } else {
          this.hide();
        }
      }
    }
    toggleDOM(map) {
      if (this.getMap()) {
        this.setMap(null);
      } else {
        this.setMap(map);
      }
    }
  }

  const overlay = new USGSOverlay(bounds, image);

  overlay.setMap(map);

  const toggleButton = document.createElement("button");

  toggleButton.textContent = "Toggle";
  toggleButton.classList.add("custom-map-control-button");

  const toggleDOMButton = document.createElement("button");

  toggleDOMButton.textContent = "Toggle DOM Attachment";
  toggleDOMButton.classList.add("custom-map-control-button");
  toggleButton.addEventListener("click", () => {
    overlay.toggle();
  });
  toggleDOMButton.addEventListener("click", () => {
    overlay.toggleDOM(map);
  });
  map.controls[google.maps.ControlPosition.TOP_RIGHT].push(toggleDOMButton);
  map.controls[google.maps.ControlPosition.TOP_RIGHT].push(toggleButton);
}

window.initMap = initMap;

সিএসএস

/* 
 * Always set the map height explicitly to define the size of the div element
 * that contains the map. 
 */
#map {
  height: 100%;
}

/* 
 * Optional: Makes the sample page fill the window. 
 */
html,
body {
  height: 100%;
  margin: 0;
  padding: 0;
}

.custom-map-control-button {
  background-color: #fff;
  border: 0;
  border-radius: 2px;
  box-shadow: 0 1px 4px -1px rgba(0, 0, 0, 0.3);
  margin: 10px;
  padding: 0 0.5em;
  font: 400 18px Roboto, Arial, sans-serif;
  overflow: hidden;
  height: 40px;
  cursor: pointer;
}
.custom-map-control-button:hover {
  background: rgb(235, 235, 235);
}

এইচটিএমএল

<html>
  <head>
    <title>Showing/Hiding Overlays</title>
    <script src="https://polyfill.io/v3/polyfill.min.js?features=default"></script>

    <link rel="stylesheet" type="text/css" href="./style.css" />
    <script type="module" src="./index.js"></script>
  </head>
  <body>
    <div id="map"></div>

    <!-- 
      The `defer` attribute causes the callback to execute after the full HTML
      document has been parsed. For non-blocking uses, avoiding race conditions,
      and consistent behavior across browsers, consider loading using Promises.
      See https://developers.google.com/maps/documentation/javascript/load-maps-js-api
      for more information.
      -->
    <script
      src="https://maps.googleapis.com/maps/api/js?key=AIzaSyB41DRUbKWJHPxaFjMAwdrzWzbVKartNGg&callback=initMap&v=weekly"
      defer
    ></script>
  </body>
</html>

নমুনা চেষ্টা করুন