डेटा विज़ुअलाइज़ेशन: भूकंप की मैपिंग

खास जानकारी

इस ट्यूटोरियल में, Google Maps पर डेटा विज़ुअलाइज़ करने का तरीका बताया गया है. उदाहरण के लिए, इस ट्यूटोरियल में दिए गए मैप में, भूकंप की जगह और उसकी तीव्रता से जुड़ा डेटा विज़ुअलाइज़ किया गया है. अपने डेटा सोर्स के साथ इस्तेमाल करने के लिए, तकनीकें जानें. साथ ही, Google Maps पर नीचे दिए गए उदाहरणों की तरह, दिलचस्प कहानियां बनाएं.

बाईं ओर मौजूद फ़्रेम में, बुनियादी मार्कर वाला मैप दिखाया गया है. वहीं, दाईं ओर मौजूद फ़्रेम में, अलग-अलग साइज़ के सर्कल वाला मैप दिखाया गया है.

अपना डेटा आयात करें

इस ट्यूटोरियल में, अमेरिका के भूवैज्ञानिक सर्वेक्षण (यूएसजीएस) से मिले, भूकंप के रीयल-टाइम डेटा का इस्तेमाल किया गया है. यूएसजीएस की वेबसाइट पर, अलग-अलग फ़ॉर्मैट में डेटा उपलब्ध है. इसे कॉपी करके, अपने डोमेन पर सेव किया जा सकता है, ताकि आपका ऐप्लिकेशन इसे स्थानीय तौर पर ऐक्सेस कर सके. इस ट्यूटोरियल में, दस्तावेज़ के हेडर में script टैग जोड़कर, सीधे यूएसजीएस के सर्वर से 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);

बुनियादी मार्कर जोड़ना

आपने यूएसजीएस के फ़ीड से, भूकंप की जगह के बारे में डेटा अपने ऐप्लिकेशन में इंपोर्ट कर लिया है. अब इसे मैप पर दिखाया जा सकता है. इस सेक्शन में, मैप बनाने का तरीका बताया गया है. इसमें इंपोर्ट किए गए डेटा का इस्तेमाल करके, भूकंप की हर जगह के एपीसेंटर पर बुनियादी मार्कर जोड़ा जाता है.

नीचे दिए गए सेक्शन में, इस ट्यूटोरियल में मैप बनाने के लिए ज़रूरी पूरा कोड दिखाया गया है.

TypeScript

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;

JavaScript

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;

CSS

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

<html>
  <head>
    <title>Earthquake Markers</title>

    <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 script 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>

सैंपल आज़माएं

मैप को पसंद के मुताबिक बनाने के लिए, शेप का इस्तेमाल करना

इस सेक्शन में, मैप पर मौजूद रिच डेटासेट को पसंद के मुताबिक बनाने का एक और तरीका बताया गया है. इस ट्यूटोरियल के पिछले सेक्शन में बनाए गए मैप को देखें. इसमें भूकंप की हर जगह पर मार्कर दिखाए गए हैं. अतिरिक्त डेटा को विज़ुअलाइज़ करने के लिए, मार्कर को पसंद के मुताबिक बनाया जा सकता है. जैसे, भूकंप की तीव्रता या गहराई.

नीचे दिए गए मैप में, सर्कल सिंबल आइकॉन का इस्तेमाल करके, पसंद के मुताबिक बनाए गए मार्कर दिखाए गए हैं. हर सर्कल का साइज़, उस भूकंप की तीव्रता के हिसाब से बढ़ता है जिसे वह दिखाता है.

नीचे दिए गए सेक्शन में, पसंद के मुताबिक बनाए गए सर्कल मार्कर वाला मैप बनाने के लिए ज़रूरी पूरा कोड दिखाया गया है.

TypeScript

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;

JavaScript

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;

CSS

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

<html>
  <head>
    <title>Earthquake Circles</title>

    <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 script 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>

सैंपल आज़माएं

ज़्यादा जानकारी

इन विषयों के बारे में ज़्यादा जानें: