ভিজ্যুয়ালাইজিং ডেটা: ম্যাপিং ভূমিকম্প

ওভারভিউ

এই টিউটোরিয়ালটি আপনাকে দেখায় কিভাবে Google মানচিত্রে ডেটা ভিজ্যুয়ালাইজ করতে হয়। উদাহরণ হিসাবে, এই টিউটোরিয়ালের মানচিত্রগুলি ভূমিকম্পের অবস্থান এবং তাদের মাত্রা সম্পর্কে ডেটা কল্পনা করে। আপনার নিজস্ব ডেটা উত্সের সাথে ব্যবহার করার কৌশলগুলি শিখুন এবং নীচের মত Google মানচিত্রে শক্তিশালী গল্প তৈরি করুন৷

উপরে দেখা প্রথম 2টি ফ্রেম (বাম থেকে ডানে) মৌলিক মার্কার এবং আকারের বৃত্ত সহ মানচিত্র প্রদর্শন করে। শেষ ফ্রেমটি একটি হিটম্যাপ প্রদর্শন করে।

আপনার ডেটা আমদানি করা হচ্ছে

এই টিউটোরিয়ালটি ইউনাইটেড স্টেটস জিওলজিক্যাল সার্ভে (USGS) থেকে রিয়েল-টাইম ভূমিকম্প ডেটা ব্যবহার করে। ইউএসজিএস ওয়েবসাইটটি বেশ কয়েকটি ফর্ম্যাটে তাদের ডেটা সরবরাহ করে, যা আপনি আপনার অ্যাপ্লিকেশনের মাধ্যমে স্থানীয় অ্যাক্সেসের জন্য আপনার ডোমেনে অনুলিপি করতে পারেন। এই টিউটোরিয়ালটি নথির মাথায় একটি script ট্যাগ যুক্ত করে সরাসরি USGS সার্ভার থেকে JSONP-কে অনুরোধ করে।

// Create a script tag and set the USGS URL as the source.
        var script = document.createElement('script');

        script.src = 'http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_week.geojsonp';
        document.getElementsByTagName('head')[0].appendChild(script);

মৌলিক মার্কার স্থাপন

এখন আপনি ইউএসজিএস ফিড থেকে ভূমিকম্পের অবস্থান সম্পর্কে ডেটা আপনার অ্যাপ্লিকেশনে টেনেছেন, আপনি এটি মানচিত্রে প্রদর্শন করতে পারেন। এই বিভাগটি আপনাকে দেখায় কিভাবে একটি মানচিত্র তৈরি করতে হয় যা প্রতিটি ভূমিকম্পের কেন্দ্রস্থলে একটি মৌলিক মার্কার স্থাপন করতে আমদানি করা ডেটা ব্যবহার করে।

নীচের বিভাগটি এই টিউটোরিয়ালে মানচিত্র তৈরি করার জন্য আপনার প্রয়োজনীয় পুরো কোডটি প্রদর্শন করে।

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

let map: google.maps.Map;

function initMap(): void {
  map = new google.maps.Map(document.getElementById("map") as HTMLElement, {
    zoom: 2,
    center: new google.maps.LatLng(2.8, -187.3),
    mapTypeId: "terrain",
  });

  // Create a <script> tag and set the USGS URL as the source.
  const script = document.createElement("script");

  // This example uses a local copy of the GeoJSON stored at
  // http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_week.geojsonp
  script.src =
    "https://developers.google.com/maps/documentation/javascript/examples/json/earthquake_GeoJSONP.js";
  document.getElementsByTagName("head")[0].appendChild(script);
}

// Loop through the results array and place a marker for each
// set of coordinates.
const eqfeed_callback = function (results: any) {
  for (let i = 0; i < results.features.length; i++) {
    const coords = results.features[i].geometry.coordinates;
    const latLng = new google.maps.LatLng(coords[1], coords[0]);

    new google.maps.Marker({
      position: latLng,
      map: map,
    });
  }
};

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

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

let map;

function initMap() {
  map = new google.maps.Map(document.getElementById("map"), {
    zoom: 2,
    center: new google.maps.LatLng(2.8, -187.3),
    mapTypeId: "terrain",
  });

  // Create a <script> tag and set the USGS URL as the source.
  const script = document.createElement("script");

  // This example uses a local copy of the GeoJSON stored at
  // http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_week.geojsonp
  script.src =
    "https://developers.google.com/maps/documentation/javascript/examples/json/earthquake_GeoJSONP.js";
  document.getElementsByTagName("head")[0].appendChild(script);
}

// Loop through the results array and place a marker for each
// set of coordinates.
const eqfeed_callback = function (results) {
  for (let i = 0; i < results.features.length; i++) {
    const coords = results.features[i].geometry.coordinates;
    const latLng = new google.maps.LatLng(coords[1], coords[0]);

    new google.maps.Marker({
      position: latLng,
      map: map,
    });
  }
};

window.initMap = initMap;
window.eqfeed_callback = eqfeed_callback;

সিএসএস

/* 
 * 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;
}

এইচটিএমএল

<html>
  <head>
    <title>Earthquake Markers</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>

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

মানচিত্র কাস্টমাইজ করতে আকার এবং হিটম্যাপ ব্যবহার করে

এই বিভাগটি আপনাকে মানচিত্রে সমৃদ্ধ ডেটাসেটগুলি কাস্টমাইজ করার অন্যান্য উপায় দেখায়৷ এই টিউটোরিয়ালের পূর্ববর্তী বিভাগে তৈরি করা মানচিত্রটি বিবেচনা করুন যা প্রতিটি ভূমিকম্পের অবস্থানে মার্কার দেখায়। আপনি অতিরিক্ত ডেটা কল্পনা করতে মার্কারগুলিকে কাস্টমাইজ করতে পারেন, যেমন সবচেয়ে বেশি ভূমিকম্প হয় এমন অবস্থান এবং তাদের মাত্রা বা গভীরতা।

মৌলিক মার্কার কাস্টমাইজ করার জন্য এখানে কিছু বিকল্প রয়েছে:

  • বৃত্তের আকার ব্যবহার করে:
    আপনি চিহ্ন ব্যবহার করে ভূমিকম্পের মাত্রার সাথে আপেক্ষিক আকারের সাথে বৃত্ত (বা অন্য কোন আকৃতি) আঁকতে পারেন। এইভাবে, শক্তিশালী ভূমিকম্পকে মানচিত্রের বৃহত্তম বৃত্ত হিসাবে উপস্থাপন করা হয়।

  • হিটম্যাপ ব্যবহার করে:
    ভিজ্যুয়ালাইজেশন লাইব্রেরিতে হিটম্যাপ লেয়ার ভূমিকম্পের বন্টন প্রদর্শনের একটি সহজ কিন্তু শক্তিশালী উপায় অফার করে। হিটম্যাপগুলি বিন্দুর ঘনত্বের প্রতিনিধিত্ব করতে রঙ ব্যবহার করে, এটি উচ্চ কার্যকলাপের ক্ষেত্রগুলিকে বাছাই করা সহজ করে তোলে। হিটম্যাপগুলি WeightedLocations ব্যবহার করতে পারে যাতে, উদাহরণস্বরূপ, বড় ভূমিকম্পগুলি হিটম্যাপে আরও স্পষ্টভাবে প্রদর্শিত হয়।

বৃত্তের আকার

নিচের মানচিত্রটি চেনাশোনা ব্যবহার করে কাস্টমাইজড মার্কার প্রদর্শন করে। সেই নির্দিষ্ট স্থানে ভূমিকম্পের মাত্রার সাথে বৃত্তের আকার বৃদ্ধি পায়।

নীচের বিভাগটি কাস্টমাইজড চেনাশোনা মার্কারগুলির সাথে একটি মানচিত্র তৈরি করতে আপনার প্রয়োজনীয় পুরো কোডটি প্রদর্শন করে৷

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

let map: google.maps.Map;

function initMap(): void {
  map = new google.maps.Map(document.getElementById("map") as HTMLElement, {
    zoom: 2,
    center: { lat: -33.865427, lng: 151.196123 },
    mapTypeId: "terrain",
  });

  // Create a <script> tag and set the USGS URL as the source.
  const script = document.createElement("script");

  // This example uses a local copy of the GeoJSON stored at
  // http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_week.geojsonp
  script.src =
    "https://developers.google.com/maps/documentation/javascript/examples/json/earthquake_GeoJSONP.js";
  document.getElementsByTagName("head")[0].appendChild(script);

  map.data.setStyle((feature) => {
    const magnitude = feature.getProperty("mag") as number;
    return {
      icon: getCircle(magnitude),
    };
  });
}

function getCircle(magnitude: number) {
  return {
    path: google.maps.SymbolPath.CIRCLE,
    fillColor: "red",
    fillOpacity: 0.2,
    scale: Math.pow(2, magnitude) / 2,
    strokeColor: "white",
    strokeWeight: 0.5,
  };
}

function eqfeed_callback(results: any) {
  map.data.addGeoJson(results);
}

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

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

let map;

function initMap() {
  map = new google.maps.Map(document.getElementById("map"), {
    zoom: 2,
    center: { lat: -33.865427, lng: 151.196123 },
    mapTypeId: "terrain",
  });

  // Create a <script> tag and set the USGS URL as the source.
  const script = document.createElement("script");

  // This example uses a local copy of the GeoJSON stored at
  // http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_week.geojsonp
  script.src =
    "https://developers.google.com/maps/documentation/javascript/examples/json/earthquake_GeoJSONP.js";
  document.getElementsByTagName("head")[0].appendChild(script);
  map.data.setStyle((feature) => {
    const magnitude = feature.getProperty("mag");
    return {
      icon: getCircle(magnitude),
    };
  });
}

function getCircle(magnitude) {
  return {
    path: google.maps.SymbolPath.CIRCLE,
    fillColor: "red",
    fillOpacity: 0.2,
    scale: Math.pow(2, magnitude) / 2,
    strokeColor: "white",
    strokeWeight: 0.5,
  };
}

function eqfeed_callback(results) {
  map.data.addGeoJson(results);
}

window.initMap = initMap;
window.eqfeed_callback = eqfeed_callback;

সিএসএস

/* 
 * 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;
}

এইচটিএমএল

<html>
  <head>
    <title>Earthquake Circles</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>

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

হিটম্যাপ

হিটম্যাপগুলি দর্শকদের জন্য ভূমিকম্পের বন্টন বোঝা সহজ করে তোলে, ইউএসজিএস দ্বারা রিপোর্ট করা হয়েছে৷ প্রতিটি কেন্দ্রে একটি মার্কার স্থাপন করার পরিবর্তে, হিটম্যাপগুলি ডেটা বিতরণের প্রতিনিধিত্ব করতে রঙ এবং আকৃতি ব্যবহার করে। এই উদাহরণে, লাল উচ্চ ভূমিকম্প কার্যকলাপের এলাকাগুলিকে প্রতিনিধিত্ব করে।

নীচের বিভাগটি এই মানচিত্রটি তৈরি করতে আপনার প্রয়োজনীয় পুরো কোডটি প্রদর্শন করে।

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

let map: google.maps.Map;

function initMap(): void {
  map = new google.maps.Map(document.getElementById("map") as HTMLElement, {
    zoom: 2,
    center: { lat: -33.865427, lng: 151.196123 },
    mapTypeId: "terrain",
  });

  // Create a <script> tag and set the USGS URL as the source.
  const script = document.createElement("script");

  // This example uses a local copy of the GeoJSON stored at
  // http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_week.geojsonp
  script.src =
    "https://developers.google.com/maps/documentation/javascript/examples/json/earthquake_GeoJSONP.js";
  document.getElementsByTagName("head")[0].appendChild(script);
}

function eqfeed_callback(results: any) {
  const heatmapData: google.maps.LatLng[] = [];

  for (let i = 0; i < results.features.length; i++) {
    const coords = results.features[i].geometry.coordinates;
    const latLng = new google.maps.LatLng(coords[1], coords[0]);

    heatmapData.push(latLng);
  }

  const heatmap = new google.maps.visualization.HeatmapLayer({
    data: heatmapData,
    dissipating: false,
    map: map,
  });
}

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

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

let map;

function initMap() {
  map = new google.maps.Map(document.getElementById("map"), {
    zoom: 2,
    center: { lat: -33.865427, lng: 151.196123 },
    mapTypeId: "terrain",
  });

  // Create a <script> tag and set the USGS URL as the source.
  const script = document.createElement("script");

  // This example uses a local copy of the GeoJSON stored at
  // http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_week.geojsonp
  script.src =
    "https://developers.google.com/maps/documentation/javascript/examples/json/earthquake_GeoJSONP.js";
  document.getElementsByTagName("head")[0].appendChild(script);
}

function eqfeed_callback(results) {
  const heatmapData = [];

  for (let i = 0; i < results.features.length; i++) {
    const coords = results.features[i].geometry.coordinates;
    const latLng = new google.maps.LatLng(coords[1], coords[0]);

    heatmapData.push(latLng);
  }

  const heatmap = new google.maps.visualization.HeatmapLayer({
    data: heatmapData,
    dissipating: false,
    map: map,
  });
}

window.initMap = initMap;
window.eqfeed_callback = eqfeed_callback;

সিএসএস

/* 
 * 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;
}

এইচটিএমএল

<html>
  <head>
    <title>Earthquake Heatmap</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&libraries=visualization&v=weekly"
      defer
    ></script>
  </body>
</html>

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

অধিক তথ্য

নিম্নলিখিত বিষয়গুলি সম্পর্কে আরও পড়ুন: