खास जानकारी
इस ट्यूटोरियल में, Google Maps पर डेटा को विज़ुअलाइज़ करने का तरीका बताया गया है. उदाहरण के तौर पर, इस ट्यूटोरियल में दिए गए मैप में भूकंप की जगह और उसकी तीव्रता के डेटा को दिखाया गया है. अपने डेटा स्रोत के साथ इस्तेमाल करने की तकनीकें सीखें और नीचे दी गई जानकारी की तरह ही Google Maps पर असरदार कहानियां बनाएं.
ऊपर देखे गए पहले दो फ़्रेम (बाएं से दाएं), बुनियादी मार्कर और आकार के सर्कल के साथ मैप दिखाते हैं. आखिरी फ़्रेम हीटमैप दिखाता है.
अपना डेटा आयात करना
इस ट्यूटोरियल में, अमेरिका के जियोलॉजिकल सर्वे (यूएसजीएस) से मिले रीयल-टाइम में भूकंप के डेटा का इस्तेमाल किया जाता है. USGS वेबसाइट अपना डेटा कई फ़ॉर्मैट में देती है, जिन्हें आप अपने ऐप्लिकेशन से अपने डोमेन पर कॉपी कर सकते हैं, ताकि लोकल ऐक्सेस पा सकें. यह ट्यूटोरियल, दस्तावेज़ के सबसे ऊपर script
टैग जोड़कर, सीधे JSONP का अनुरोध करता है. यह अनुरोध USGS सर्वर से किया जाता है.
// 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> <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
का भी इस्तेमाल किया जा सकता है, ताकि उदाहरण के लिए, बड़े भूकंपों को हीटमैप में बेहतर तरीके से दिखाया जा सके.
सर्कल का साइज़
नीचे दिया गया मैप, सर्कल का इस्तेमाल करके कस्टमाइज़ किए गए मार्कर दिखाता है. किसी खास जगह पर आए भूकंप की तीव्रता के हिसाब से, सर्कल का साइज़ बढ़ता है.
नीचे दिया गया अनुभाग उस पूरे कोड को प्रदर्शित करता है, जिसकी ज़रूरत आपको कस्टमाइज़ किए गए मंडली मार्कर के साथ मैप बनाने के लिए होती है.
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"); 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> <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>
सैंपल आज़माएं
हीटमैप
यूएसजीएस की रिपोर्ट के मुताबिक, हीटमैप से दर्शकों के लिए भूकंप के असर को आसानी से समझा जा सकता है. हर केंद्र पर मार्कर रखने के बजाय, हीटमैप डेटा के वितरण को दिखाने के लिए रंग और आकार का इस्तेमाल करता है. इस उदाहरण में, लाल रंग से उन इलाकों को दिखाया गया है जहां भूकंप आने की ज़्यादा आशंका है.
नीचे दिया गया सेक्शन वह पूरा कोड दिखाता है, जिसकी ज़रूरत आपको यह मैप बनाने के लिए होती है.
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> <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>
सैंपल आज़माएं
ज़्यादा जानकारी
इन विषयों के बारे में और पढ़ें: