সংক্ষিপ্ত বিবরণ
এই টিউটোরিয়ালটি আপনাকে দেখাবে কীভাবে গুগল ম্যাপে ডেটা ভিজ্যুয়ালাইজ করতে হয়। উদাহরণস্বরূপ, এই টিউটোরিয়ালের ম্যাপগুলোতে ভূমিকম্পের অবস্থান এবং মাত্রা সম্পর্কিত ডেটা ভিজ্যুয়ালাইজ করা হয়েছে। আপনার নিজের ডেটা সোর্সের সাথে ব্যবহার করার কৌশলগুলো শিখুন এবং নিচেরগুলোর মতো গুগল ম্যাপে শক্তিশালী স্টোরি তৈরি করুন।
বাম দিকের ফ্রেমে সাধারণ চিহ্নসহ একটি মানচিত্র এবং ডান দিকের ফ্রেমে আকার দেওয়া বৃত্তসহ একটি মানচিত্র প্রদর্শিত হচ্ছে।
আপনার ডেটা আমদানি করুন
এই টিউটোরিয়ালটিতে ইউনাইটেড স্টেটস জিওলজিক্যাল সার্ভে (USGS)-এর রিয়েল-টাইম ভূমিকম্পের ডেটা ব্যবহার করা হয়েছে। 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>
<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>নমুনা চেষ্টা করুন
মানচিত্র কাস্টমাইজ করতে আকার ব্যবহার করুন
এই বিভাগে একটি মানচিত্রে সমৃদ্ধ ডেটাসেট কাস্টমাইজ করার আরেকটি উপায় দেখানো হয়েছে। এই টিউটোরিয়ালের আগের বিভাগে তৈরি করা মানচিত্রটির কথা ভাবুন, যেখানে প্রতিটি ভূমিকম্পের অবস্থানে মার্কার দেখানো হয়েছে। আপনি মাত্রা বা গভীরতার মতো অতিরিক্ত ডেটা দেখানোর জন্য মার্কারগুলো কাস্টমাইজ করতে পারেন।
নিচের মানচিত্রটিতে বৃত্তাকার প্রতীক আইকন ব্যবহার করে বিশেষভাবে তৈরি করা চিহ্নিতকারী দেখানো হয়েছে। প্রতিটি বৃত্তের আকার, এটি যে ভূমিকম্পকে নির্দেশ করে তার মাত্রার সাথে সাথে বৃদ্ধি পায়।
নিচের অংশে কাস্টমাইজড বৃত্তাকার মার্কারসহ একটি মানচিত্র তৈরি করার জন্য প্রয়োজনীয় সম্পূর্ণ কোডটি দেখানো হয়েছে।
টাইপস্ক্রিপ্ট
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>
<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>নমুনা চেষ্টা করুন
আরও তথ্য
নিম্নলিখিত বিষয়গুলো সম্পর্কে আরও পড়ুন: