डेटा विज़ुअलाइज़ेशन: भूकंप के बारे में जानकारी हासिल करना

खास जानकारी

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

ऊपर दिखने वाले पहले दो फ़्रेम (बाएं से दाएं) मैप को बेसिक मार्कर, और साइज़ के सर्कल. आखिरी फ़्रेम, हीटमैप दिखाता है.

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

इस ट्यूटोरियल में भूकंप का रीयल-टाइम डेटा: द यूनाइटेड स्टेट्स जियोलॉजिकल सर्वे (USGS). USGS वेबसाइट में डेटा हो सकता है जिसे आप स्थानीय तौर पर ऐक्सेस करने के लिए अपने डोमेन में कॉपी कर सकते हैं आपके ऐप्लिकेशन के हिसाब से. इस ट्यूटोरियल का अनुरोध है सीधे USGS सर्वर से JSONP दस्तावेज़ में सबसे ऊपर script टैग जोड़कर.

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

सीएसएस

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

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

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

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

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

यहां बुनियादी मार्कर को पसंद के मुताबिक बनाने के कुछ विकल्प दिए गए हैं:

  • सर्कल के साइज़ का इस्तेमाल करना:
    आपके पास अपनी इमेज के लिए दिए गए भूकंप की तीव्रता सिंबल. इस तरह से, भयंकर भूकंपों को सबसे बड़े सर्कल के तौर पर दिखाया जाता है मैप.

  • हीटमैप का इस्तेमाल करना:
    विज़ुअलाइज़ेशन लाइब्रेरी में हीटमैप लेयर की मदद से विज्ञापन को आसानी से लोड होने में मदद मिलती है यह दिखाने का एक तरीका है. हीटमैप में रंगों का इस्तेमाल करके बिंदुओं का घनत्व दिखाती है, जिससे उच्च वाले क्षेत्रों को चुनना आसान हो जाता है गतिविधि. हीटमैप में WeightedLocations का भी इस्तेमाल किया जा सकता है. उदाहरण के लिए, हीटमैप में बड़े भूकंपों को ज़्यादा प्रमुखता से दिखाया जाता है.

वृत्त का आकार

नीचे दिया गया मैप वृत्तों का उपयोग करके कस्टमाइज़ किए गए मार्कर दिखाता है. सर्कल का साइज़ किसी जगह पर भूकंप की तीव्रता बढ़ने के साथ.

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

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;

सीएसएस

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

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

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

हीटमैप

हीटमैप से दर्शकों के लिए भूकंप के तरीके को समझना आसान हो जाता है. USGS की ओर से रिपोर्ट की गई. हर भूकंप की जगह पर मार्कर लगाने के बजाय, हीटमैप में डेटा का डिस्ट्रिब्यूशन दिखाने के लिए, रंग और आकार का इस्तेमाल किया जाता है. इसमें उदाहरण के लिए, लाल रंग, भूकंप वाली जगहों को दिखाता है.

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

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);
}

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;

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);
}

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>

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

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

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

इन विषयों के बारे में और पढ़ें: