এই নথিতে আপনি Maps JavaScript API ব্যবহার করে প্রদর্শন করতে পারেন এমন মানচিত্রের ধরন নিয়ে আলোচনা করে। API এই মানচিত্র সম্পর্কে তথ্য ধারণ করার জন্য একটি MapType
অবজেক্ট ব্যবহার করে। একটি MapType
হল একটি ইন্টারফেস যা মানচিত্র টাইলগুলির প্রদর্শন এবং ব্যবহার এবং স্ক্রীন স্থানাঙ্ক থেকে বিশ্ব স্থানাঙ্কে (মানচিত্রে) স্থানাঙ্ক সিস্টেমের অনুবাদ সংজ্ঞায়িত করে। প্রতিটি MapType
টাইলস পুনরুদ্ধার এবং রিলিজ পরিচালনা করার জন্য কয়েকটি পদ্ধতি এবং বৈশিষ্ট্যগুলি থাকতে হবে যা এর চাক্ষুষ আচরণকে সংজ্ঞায়িত করে।
Maps JavaScript API-এর মধ্যে মানচিত্রের প্রকারের অভ্যন্তরীণ কাজগুলি একটি উন্নত বিষয়। বেশিরভাগ বিকাশকারীরা নীচে উল্লিখিত মৌলিক মানচিত্র প্রকারগুলি ব্যবহার করতে পারেন৷ যাইহোক, আপনি স্টাইল করা মানচিত্র ব্যবহার করে বিদ্যমান মানচিত্রের প্রকারের উপস্থাপনাও সংশোধন করতে পারেন বা কাস্টম মানচিত্র প্রকারগুলি ব্যবহার করে আপনার নিজস্ব মানচিত্র টাইলস সংজ্ঞায়িত করতে পারেন। কাস্টম মানচিত্রের প্রকারগুলি প্রদান করার সময়, আপনাকে মানচিত্রের মানচিত্র প্রকার রেজিস্ট্রি কীভাবে সংশোধন করতে হবে তা বুঝতে হবে।
মৌলিক মানচিত্র প্রকার
Maps JavaScript API-এর মধ্যে চার ধরনের মানচিত্র পাওয়া যায়। পরিচিত "পেইন্টেড" রোড ম্যাপ টাইলস ছাড়াও, Maps JavaScript API অন্যান্য মানচিত্র প্রকারগুলিকেও সমর্থন করে৷
নিম্নলিখিত মানচিত্র প্রকারগুলি মানচিত্র জাভাস্ক্রিপ্ট API-এ উপলব্ধ:
-
roadmap
ডিফল্ট রোড ম্যাপ ভিউ প্রদর্শন করে। এটি ডিফল্ট মানচিত্র প্রকার। -
satellite
গুগল আর্থ স্যাটেলাইট ছবি প্রদর্শন করে। -
hybrid
স্বাভাবিক এবং স্যাটেলাইট দৃশ্যের মিশ্রণ প্রদর্শন করে। -
terrain
ভূখণ্ডের তথ্যের উপর ভিত্তি করে একটি ভৌত মানচিত্র প্রদর্শন করে।
আপনি Map
দ্বারা ব্যবহৃত মানচিত্রের ধরনটি পরিবর্তন করুন এর mapTypeId
বৈশিষ্ট্য সেট করে, হয় কনস্ট্রাক্টরের মধ্যে এর Map options
অবজেক্ট সেট করে, অথবা মানচিত্রের setMapTypeId()
পদ্ধতিতে কল করে। mapTypeID
প্রপার্টি roadmap
ডিফল্ট।
নির্মাণের সময় mapTypeId
সেট করা হচ্ছে:
var myLatlng = new google.maps.LatLng(-34.397, 150.644); var mapOptions = { zoom: 8, center: myLatlng, mapTypeId: 'satellite' }; var map = new google.maps.Map(document.getElementById('map'), mapOptions);
গতিশীলভাবে mapTypeId
পরিবর্তন করা হচ্ছে:
map.setMapTypeId('terrain');
মনে রাখবেন যে আপনি প্রকৃতপক্ষে মানচিত্রের মানচিত্র প্রকারটি সরাসরি সেট করেন না, তবে এর পরিবর্তে একটি শনাক্তকারী ব্যবহার করে একটি MapType
উল্লেখ করার জন্য এর mapTypeId
সেট করুন৷ মানচিত্র জাভাস্ক্রিপ্ট API এই রেফারেন্সগুলি পরিচালনা করার জন্য নীচে ব্যাখ্যা করা একটি মানচিত্রের প্রকার রেজিস্ট্রি ব্যবহার করে৷
45° চিত্র
মানচিত্র জাভাস্ক্রিপ্ট API নির্দিষ্ট অবস্থানের জন্য বিশেষ 45° চিত্র সমর্থন করে। এই উচ্চ-রেজোলিউশন চিত্রাবলী প্রতিটি মূল দিক (উত্তর, দক্ষিণ, পূর্ব, পশ্চিম) প্রতি দৃষ্টিভঙ্গি দেখায়। সমর্থিত মানচিত্র প্রকারের জন্য এই ছবিগুলি উচ্চতর জুম স্তরে উপলব্ধ।
নিম্নলিখিত চিত্রটি নিউ ইয়র্ক সিটির একটি 45° দৃষ্টিকোণ দেখায়:
satellite
এবং hybrid
মানচিত্রের ধরনগুলি যেখানে উপলব্ধ সেখানে উচ্চ জুম স্তরে (12 এবং তার বেশি) 45° চিত্র সমর্থন করে৷ যদি ব্যবহারকারী এমন একটি অবস্থানে জুম করে যার জন্য এই ধরনের চিত্র বিদ্যমান, এই মানচিত্র প্রকারগুলি স্বয়ংক্রিয়ভাবে নিম্নলিখিত পদ্ধতিতে তাদের দৃষ্টিভঙ্গি পরিবর্তন করে:
- স্যাটেলাইট বা হাইব্রিড চিত্রগুলি বর্তমান অবস্থানকে কেন্দ্র করে 45° দৃষ্টিকোণ প্রদান করে চিত্রগুলির সাথে প্রতিস্থাপিত হয়৷ ডিফল্টরূপে, এই ধরনের দৃষ্টিভঙ্গি উত্তর দিকে ভিত্তিক। ব্যবহারকারী জুম আউট করলে, ডিফল্ট স্যাটেলাইট বা হাইব্রিড চিত্র আবার প্রদর্শিত হবে। জুম লেভেল এবং
tilt
মানের উপর নির্ভর করে আচরণ পরিবর্তিত হয়: - জুম লেভেল 12 এবং 18 এর মধ্যে টপ-ডাউন বেসম্যাপ (0°) ডিফল্টভাবে প্রদর্শিত হয় যদি না
tilt
45 এ সেট করা হয়। - 18 বা তার বেশি জুম লেভেলে 45° বেসম্যাপ দেখায় যদি না
tilt
0 এ সেট করা হয়। - ঘূর্ণন নিয়ন্ত্রণ দৃশ্যমান হয়ে ওঠে. ঘূর্ণন নিয়ন্ত্রণ বিকল্পগুলি প্রদান করে যা ব্যবহারকারীকে টিল্ট টগল করতে এবং উভয় দিকে 90° বৃদ্ধিতে ভিউ ঘোরাতে সক্ষম করে। রোটেট কন্ট্রোল লুকানোর জন্য,
rotateControl
কেfalse
এ সেট করুন।
45° চিত্র প্রদর্শন করে একটি মানচিত্রের ধরন থেকে জুম আউট করা এই প্রতিটি পরিবর্তনকে ফিরিয়ে দেয়, মূল মানচিত্রের প্রকারগুলিকে পুনঃপ্রতিষ্ঠা করে।
45° চিত্রাবলী সক্ষম এবং অক্ষম করুন৷
আপনি Map
বস্তুতে setTilt(0)
কল করে 45° চিত্র অক্ষম করতে পারেন। সমর্থিত মানচিত্র প্রকারের জন্য 45° চিত্র সক্ষম করতে, setTilt(45)
কল করুন। Map
getTilt()
পদ্ধতি সর্বদা মানচিত্রে প্রদর্শিত বর্তমান tilt
প্রতিফলিত করবে; যদি আপনি একটি মানচিত্রে একটি tilt
সেট করেন এবং তারপরে সেই tilt
সরিয়ে দেন (উদাহরণস্বরূপ, মানচিত্রটি জুম করে), মানচিত্রের getTilt()
পদ্ধতিটি 0
ফেরত দেবে।
গুরুত্বপূর্ণ: 45° চিত্র শুধুমাত্র রাস্টার মানচিত্রে সমর্থিত; এই চিত্র ভেক্টর মানচিত্রে ব্যবহার করা যাবে না।
নিম্নলিখিত উদাহরণটি নিউ ইয়র্ক সিটির 45° দৃশ্য প্রদর্শন করে:
টাইপস্ক্রিপ্ট
function initMap(): void { const map = new google.maps.Map( document.getElementById("map") as HTMLElement, { center: { lat: 40.76, lng: -73.983 }, zoom: 15, mapTypeId: "satellite", } ); map.setTilt(45); } declare global { interface Window { initMap: () => void; } } window.initMap = initMap;
জাভাস্ক্রিপ্ট
function initMap() { const map = new google.maps.Map(document.getElementById("map"), { center: { lat: 40.76, lng: -73.983 }, zoom: 15, mapTypeId: "satellite", }); map.setTilt(45); } window.initMap = initMap;
নমুনা চেষ্টা করুন
45° চিত্র ঘোরান
45° চিত্রে প্রকৃতপক্ষে প্রতিটি মূল দিক (উত্তর, দক্ষিণ, পূর্ব, পশ্চিম) ছবির একটি সংগ্রহ রয়েছে। একবার আপনার মানচিত্র 45° চিত্র প্রদর্শন করলে, আপনি Map
অবজেক্টে setHeading()
কল করে, উত্তর থেকে ডিগ্রী হিসাবে প্রকাশ করা একটি সংখ্যা মান পাস করে চিত্রটিকে এর মূল দিকগুলির একটির দিকে অভিমুখ করতে পারেন।
নিম্নলিখিত উদাহরণটি একটি বায়বীয় মানচিত্র দেখায় এবং বোতামটি ক্লিক করা হলে প্রতি 3 সেকেন্ডে মানচিত্রটি স্বয়ংক্রিয়ভাবে ঘোরে:
টাইপস্ক্রিপ্ট
let map: google.maps.Map; function initMap(): void { map = new google.maps.Map(document.getElementById("map") as HTMLElement, { center: { lat: 40.76, lng: -73.983 }, zoom: 15, mapTypeId: "satellite", heading: 90, tilt: 45, }); // add listener to button document.getElementById("rotate")!.addEventListener("click", autoRotate); } function rotate90(): void { const heading = map.getHeading() || 0; map.setHeading(heading + 90); } function autoRotate(): void { // Determine if we're showing aerial imagery. if (map.getTilt() !== 0) { window.setInterval(rotate90, 3000); } } declare global { interface Window { initMap: () => void; } } window.initMap = initMap;
জাভাস্ক্রিপ্ট
let map; function initMap() { map = new google.maps.Map(document.getElementById("map"), { center: { lat: 40.76, lng: -73.983 }, zoom: 15, mapTypeId: "satellite", heading: 90, tilt: 45, }); // add listener to button document.getElementById("rotate").addEventListener("click", autoRotate); } function rotate90() { const heading = map.getHeading() || 0; map.setHeading(heading + 90); } function autoRotate() { // Determine if we're showing aerial imagery. if (map.getTilt() !== 0) { window.setInterval(rotate90, 3000); } } window.initMap = initMap;
নমুনা চেষ্টা করুন
ম্যাপ টাইপ রেজিস্ট্রি পরিবর্তন করুন
একটি মানচিত্রের mapTypeId
হল একটি স্ট্রিং শনাক্তকারী যা একটি MapType
একটি অনন্য মানের সাথে সংযুক্ত করতে ব্যবহৃত হয়। প্রতিটি Map
অবজেক্ট একটি MapTypeRegistry
বজায় রাখে যাতে সেই মানচিত্রের জন্য উপলব্ধ MapType
s এর সংগ্রহ থাকে। এই রেজিস্ট্রিটি ম্যাপের ম্যাপ টাইপ নিয়ন্ত্রণে উপলব্ধ মানচিত্রের ধরন নির্বাচন করতে ব্যবহৃত হয়, উদাহরণস্বরূপ।
আপনি ম্যাপ টাইপ রেজিস্ট্রি থেকে সরাসরি পড়েন না। পরিবর্তে, আপনি কাস্টম মানচিত্রের প্রকারগুলি যোগ করে এবং আপনার পছন্দের একটি স্ট্রিং শনাক্তকারীর সাথে সংযুক্ত করে রেজিস্ট্রিটি সংশোধন করুন৷ আপনি মৌলিক মানচিত্রের প্রকারগুলি পরিবর্তন বা পরিবর্তন করতে পারবেন না (যদিও আপনি মানচিত্রের সংশ্লিষ্ট mapTypeControlOptions
এর চেহারা পরিবর্তন করে মানচিত্র থেকে সেগুলি সরাতে পারেন)।
নিম্নলিখিত কোডটি মানচিত্রের মানচিত্রের mapTypeControlOptions
শুধুমাত্র দুটি মানচিত্র প্রকার দেখানোর জন্য মানচিত্রকে সেট করে এবং MapType
ইন্টারফেসের প্রকৃত বাস্তবায়নে এই শনাক্তকারীর সাথে অ্যাসোসিয়েশন যোগ করার জন্য রেজিস্ট্রি সংশোধন করে।
// Modify the control to only display two maptypes, the // default ROADMAP and the custom 'mymap'. // Note that because this is an association, we // don't need to modify the MapTypeRegistry beforehand. var MY_MAPTYPE_ID = 'mymaps'; var mapOptions = { zoom: 12, center: brooklyn, mapTypeControlOptions: { mapTypeIds: ['roadmap', MY_MAPTYPE_ID] }, mapTypeId: MY_MAPTYPE_ID }; // Create our map. This creation will implicitly create a // map type registry. map = new google.maps.Map(document.getElementById('map'), mapOptions); // Create your custom map type using your own code. // (See below.) var myMapType = new MyMapType(); // Set the registry to associate 'mymap' with the // custom map type we created, and set the map to // show that map type. map.mapTypes.set(MY_MAPTYPE_ID, myMapType);
স্টাইল করা মানচিত্র
StyledMapType
আপনাকে স্ট্যান্ডার্ড Google বেস ম্যাপের উপস্থাপনা কাস্টমাইজ করতে দেয়, রাস্তা, পার্ক এবং বিল্ট-আপ এলাকার মতো উপাদানগুলির ভিজ্যুয়াল ডিসপ্লে পরিবর্তন করে ডিফল্ট মানচিত্রের ধরণে ব্যবহৃত একটি ভিন্ন শৈলী প্রতিফলিত করতে। StyledMapType
শুধুমাত্র ডিফল্ট roadmap
মানচিত্র প্রকারকে প্রভাবিত করে।
StyledMapType
সম্পর্কে আরও তথ্যের জন্য, এমবেডেড JSON শৈলী ঘোষণার ব্যবহার দেখুন।
কাস্টম মানচিত্র প্রকার
মানচিত্র জাভাস্ক্রিপ্ট API কাস্টম মানচিত্র প্রকারের প্রদর্শন এবং পরিচালনা সমর্থন করে, যা আপনাকে আপনার নিজস্ব মানচিত্র চিত্র বা টাইল ওভারলে বাস্তবায়ন করতে দেয়।
মানচিত্র জাভাস্ক্রিপ্ট API-এর মধ্যে বেশ কিছু সম্ভাব্য মানচিত্র প্রকার বাস্তবায়ন বিদ্যমান:
- স্ট্যান্ডার্ড টাইল সেটে ছবি থাকে যা সম্মিলিতভাবে সম্পূর্ণ কার্টোগ্রাফিক মানচিত্র গঠন করে। এই টাইল সেটগুলি বেস মানচিত্র প্রকার হিসাবেও পরিচিত। এই মানচিত্র প্রকারগুলি বিদ্যমান ডিফল্ট মানচিত্র প্রকারের মতো কাজ করে এবং আচরণ করে:
roadmap
,satellite
,hybrid
এবংterrain
৷ আপনি মানচিত্র জাভাস্ক্রিপ্ট API-এর মধ্যে UI-কে আপনার কাস্টম মানচিত্রের ধরনটিকে একটি আদর্শmapTypes
প্রকারের অ্যারেতে আপনার কাস্টম মানচিত্রের ধরণ যোগ করতে পারেন (উদাহরণস্বরূপ, এটিকে MapType নিয়ন্ত্রণে অন্তর্ভুক্ত করে)। - ইমেজ টাইল ওভারলে যা বিদ্যমান বেস মানচিত্রের প্রকারের উপরে প্রদর্শিত হয়। সাধারণত, এই মানচিত্র প্রকারগুলিকে অতিরিক্ত তথ্য প্রদর্শনের জন্য একটি বিদ্যমান মানচিত্রের ধরন বাড়ানোর জন্য ব্যবহার করা হয় এবং প্রায়শই নির্দিষ্ট অবস্থান এবং/অথবা জুম স্তরে সীমাবদ্ধ থাকে। মনে রাখবেন যে এই টাইলগুলি স্বচ্ছ হতে পারে, যা আপনাকে বিদ্যমান মানচিত্রে বৈশিষ্ট্য যোগ করার অনুমতি দেয়।
- নন-ইমেজ মানচিত্র প্রকার, যা আপনাকে মানচিত্র তথ্য প্রদর্শনের সবচেয়ে মৌলিক স্তরে ম্যানিপুলেট করতে দেয়।
এই বিকল্পগুলির প্রতিটি একটি ক্লাস তৈরির উপর নির্ভর করে যা MapType
ইন্টারফেস প্রয়োগ করে। অতিরিক্তভাবে, ImageMapType
ক্লাস চিত্রের মানচিত্র প্রকারগুলি তৈরিকে সহজ করার জন্য কিছু অন্তর্নির্মিত আচরণ প্রদান করে।
MapType
ইন্টারফেস
আপনি MapType
প্রয়োগ করে এমন ক্লাস তৈরি করার আগে, Google Maps কীভাবে স্থানাঙ্ক নির্ধারণ করে এবং মানচিত্রের কোন অংশগুলি দেখানো হবে তা নির্ধারণ করে তা বোঝা গুরুত্বপূর্ণ। যেকোন বেস বা ওভারলে মানচিত্র প্রকারের জন্য আপনাকে অনুরূপ যুক্তি প্রয়োগ করতে হবে। মানচিত্র এবং টাইল স্থানাঙ্কের নির্দেশিকা পড়ুন।
কাস্টম মানচিত্রের ধরন অবশ্যই MapType
ইন্টারফেস বাস্তবায়ন করবে। এই ইন্টারফেসটি নির্দিষ্ট বৈশিষ্ট্য এবং পদ্ধতিগুলি নির্দিষ্ট করে যা API-কে আপনার মানচিত্র প্রকার(গুলি) এর অনুরোধগুলি শুরু করার অনুমতি দেয় যখন API নির্ধারণ করে যে এটি বর্তমান ভিউপোর্ট এবং জুম স্তরের মধ্যে মানচিত্রের টাইলগুলি প্রদর্শন করতে হবে৷ কোন টাইল লোড করতে হবে তা নির্ধারণ করতে আপনি এই অনুরোধগুলি পরিচালনা করেন।
দ্রষ্টব্য : আপনি এই ইন্টারফেসটি বাস্তবায়ন করতে আপনার নিজস্ব ক্লাস তৈরি করতে পারেন। বিকল্পভাবে, আপনার যদি সামঞ্জস্যপূর্ণ চিত্র থাকে তবে আপনি ImageMapType
ক্লাস ব্যবহার করতে পারেন যা ইতিমধ্যে এই ইন্টারফেসটি প্রয়োগ করে।
MapType
ইন্টারফেস বাস্তবায়নকারী ক্লাসগুলির জন্য আপনাকে নিম্নলিখিত বৈশিষ্ট্যগুলিকে সংজ্ঞায়িত এবং পপুলেট করতে হবে:
-
tileSize
(প্রয়োজনীয়) টাইলের আকার নির্দিষ্ট করে (google.maps.Size
টাইপ)। আকারগুলি অবশ্যই আয়তক্ষেত্রাকার হতে হবে যদিও সেগুলি বর্গক্ষেত্র হতে হবে না। -
maxZoom
(প্রয়োজনীয়) সর্বাধিক জুম স্তর নির্দিষ্ট করে যেখানে এই মানচিত্র প্রকারের টাইলগুলি প্রদর্শন করতে হবে৷ -
minZoom
(ঐচ্ছিক) ন্যূনতম জুম স্তর নির্দিষ্ট করে যেখানে এই মানচিত্র প্রকারের টাইল প্রদর্শন করতে হবে। ডিফল্টরূপে, এই মানটি0
ইঙ্গিত করে যে কোন ন্যূনতম জুম স্তর বিদ্যমান নেই। -
name
(ঐচ্ছিক) এই মানচিত্রের প্রকারের নাম নির্দিষ্ট করে। এই বৈশিষ্ট্যটি শুধুমাত্র তখনই প্রয়োজনীয় যদি আপনি চান যে এই মানচিত্রের ধরনটি একটি MapType নিয়ন্ত্রণের মধ্যে নির্বাচনযোগ্য। ( নিয়ন্ত্রণ বিকল্প দেখুন।) -
alt
(ঐচ্ছিক) এই মানচিত্র প্রকারের জন্য বিকল্প পাঠ্য নির্দিষ্ট করে, হোভার টেক্সট হিসাবে প্রদর্শিত। এই বৈশিষ্ট্যটি শুধুমাত্র তখনই প্রয়োজনীয় যদি আপনি চান যে এই মানচিত্রের ধরনটি একটি MapType নিয়ন্ত্রণের মধ্যে নির্বাচনযোগ্য। ( নিয়ন্ত্রণ বিকল্প দেখুন।)
উপরন্তু, MapType
ইন্টারফেস বাস্তবায়নকারী ক্লাসগুলিকে নিম্নলিখিত পদ্ধতিগুলি বাস্তবায়ন করতে হবে:
getTile()
(প্রয়োজনীয়) বলা হয় যখনই API নির্ধারণ করে যে মানচিত্রটিকে প্রদত্ত ভিউপোর্টের জন্য নতুন টাইলস প্রদর্শন করতে হবে।getTile()
পদ্ধতিতে নিম্নলিখিত স্বাক্ষর থাকতে হবে:getTile(tileCoord:Point,zoom:number,ownerDocument:Document):Node
MapType
এরtileSize
,minZoom
, এবংmaxZoom
বৈশিষ্ট্য এবং মানচিত্রের বর্তমান ভিউপোর্ট এবং জুম স্তরের উপর ভিত্তি করে এপিআই এটিকেgetTile()
কল করতে হবে কিনা তা নির্ধারণ করে। এই পদ্ধতির জন্য হ্যান্ডলারকে একটি পাস করা স্থানাঙ্ক, জুম স্তর এবং DOM উপাদান দিয়ে একটি HTML উপাদান ফেরত দেওয়া উচিত যাতে টাইল চিত্রটি যুক্ত করতে হয়।releaseTile()
(ঐচ্ছিক) বলা হয় যখনই API নির্ধারণ করে যে মানচিত্রটি একটি টাইল অপসারণ করতে হবে কারণ এটি দৃশ্যের বাইরে পড়ে যায়। এই পদ্ধতিতে নিম্নলিখিত স্বাক্ষর থাকতে হবে:releaseTile(tile:Node)
ম্যাপ যুক্ত করার সময় ম্যাপের টাইলসের সাথে সংযুক্ত যেকোন উপাদানগুলিকে অপসারণ করার জন্য আপনাকে সাধারণত পরিচালনা করতে হবে। উদাহরণস্বরূপ, যদি আপনি ইভেন্ট শ্রোতাদের ম্যাপ টাইল ওভারলেতে সংযুক্ত করেন, তাহলে আপনার সেগুলিকে এখান থেকে সরানো উচিত।
getTile()
পদ্ধতি একটি প্রদত্ত ভিউপোর্টের মধ্যে কোন টাইলগুলি লোড করতে হবে তা নির্ধারণের জন্য প্রধান নিয়ামক হিসাবে কাজ করে।
ভিত্তি মানচিত্র প্রকার
আপনি এই পদ্ধতিতে যে মানচিত্রের প্রকারগুলি তৈরি করেন সেগুলি হয় একা দাঁড়াতে পারে বা ওভারলে হিসাবে অন্যান্য মানচিত্রের প্রকারগুলির সাথে একত্রিত হতে পারে৷ স্বতন্ত্র মানচিত্রের প্রকারগুলি বেস মানচিত্র প্রকার হিসাবে পরিচিত। আপনি এপিআই-এর সাথে এমন কাস্টম MapType
গুলি ব্যবহার করতে চাইতে পারেন যেমন এটি অন্য যেকোন বিদ্যমান বেস মানচিত্র প্রকার ( ROADMAP
, TERRAIN
, ইত্যাদি)। এটি করার জন্য, আপনার কাস্টম MapType
যোগ করুন Map
mapTypes
বৈশিষ্ট্যে। এই সম্পত্তি MapTypeRegistry
ধরনের।
নিম্নলিখিত কোডটি একটি মানচিত্রের টাইল স্থানাঙ্ক প্রদর্শন করতে একটি বেস MapType
তৈরি করে এবং টাইলগুলির একটি রূপরেখা আঁকে:
টাইপস্ক্রিপ্ট
/* * This demo demonstrates how to replace default map tiles with custom imagery. * In this case, the CoordMapType displays gray tiles annotated with the tile * coordinates. * * Try panning and zooming the map to see how the coordinates change. */ class CoordMapType { tileSize: google.maps.Size; maxZoom = 19; name = "Tile #s"; alt = "Tile Coordinate Map Type"; constructor(tileSize: google.maps.Size) { this.tileSize = tileSize; } getTile( coord: google.maps.Point, zoom: number, ownerDocument: Document ): HTMLElement { const div = ownerDocument.createElement("div"); div.innerHTML = String(coord); div.style.width = this.tileSize.width + "px"; div.style.height = this.tileSize.height + "px"; div.style.fontSize = "10"; div.style.borderStyle = "solid"; div.style.borderWidth = "1px"; div.style.borderColor = "#AAAAAA"; div.style.backgroundColor = "#E5E3DF"; return div; } releaseTile(tile: HTMLElement): void {} } function initMap(): void { const map = new google.maps.Map( document.getElementById("map") as HTMLElement, { zoom: 10, center: { lat: 41.85, lng: -87.65 }, streetViewControl: false, mapTypeId: "coordinate", mapTypeControlOptions: { mapTypeIds: ["coordinate", "roadmap"], style: google.maps.MapTypeControlStyle.DROPDOWN_MENU, }, } ); map.addListener("maptypeid_changed", () => { const showStreetViewControl = (map.getMapTypeId() as string) !== "coordinate"; map.setOptions({ streetViewControl: showStreetViewControl, }); }); // Now attach the coordinate map type to the map's registry. map.mapTypes.set( "coordinate", new CoordMapType(new google.maps.Size(256, 256)) ); } declare global { interface Window { initMap: () => void; } } window.initMap = initMap;
জাভাস্ক্রিপ্ট
/* * This demo demonstrates how to replace default map tiles with custom imagery. * In this case, the CoordMapType displays gray tiles annotated with the tile * coordinates. * * Try panning and zooming the map to see how the coordinates change. */ class CoordMapType { tileSize; maxZoom = 19; name = "Tile #s"; alt = "Tile Coordinate Map Type"; constructor(tileSize) { this.tileSize = tileSize; } getTile(coord, zoom, ownerDocument) { const div = ownerDocument.createElement("div"); div.innerHTML = String(coord); div.style.width = this.tileSize.width + "px"; div.style.height = this.tileSize.height + "px"; div.style.fontSize = "10"; div.style.borderStyle = "solid"; div.style.borderWidth = "1px"; div.style.borderColor = "#AAAAAA"; div.style.backgroundColor = "#E5E3DF"; return div; } releaseTile(tile) {} } function initMap() { const map = new google.maps.Map(document.getElementById("map"), { zoom: 10, center: { lat: 41.85, lng: -87.65 }, streetViewControl: false, mapTypeId: "coordinate", mapTypeControlOptions: { mapTypeIds: ["coordinate", "roadmap"], style: google.maps.MapTypeControlStyle.DROPDOWN_MENU, }, }); map.addListener("maptypeid_changed", () => { const showStreetViewControl = map.getMapTypeId() !== "coordinate"; map.setOptions({ streetViewControl: showStreetViewControl, }); }); // Now attach the coordinate map type to the map's registry. map.mapTypes.set( "coordinate", new CoordMapType(new google.maps.Size(256, 256)), ); } window.initMap = initMap;
নমুনা চেষ্টা করুন
ওভারলে মানচিত্র প্রকার
কিছু মানচিত্রের ধরন বিদ্যমান মানচিত্রের প্রকারের উপরে কাজ করার জন্য ডিজাইন করা হয়েছে। এই ধরনের মানচিত্রের প্রকারে স্বচ্ছ স্তর থাকতে পারে যা আগ্রহের পয়েন্টগুলি নির্দেশ করে বা ব্যবহারকারীকে অতিরিক্ত ডেটা দেখায়।
এই ক্ষেত্রে, আপনি মানচিত্রের ধরনটিকে একটি পৃথক সত্তা হিসাবে বিবেচনা না করে একটি ওভারলে হিসাবে চান৷ আপনি সরাসরি Map
এর overlayMapTypes
বৈশিষ্ট্য ব্যবহার করে একটি বিদ্যমান MapType
এ মানচিত্রের প্রকার যোগ করে এটি করতে পারেন। এই সম্পত্তিতে MapType
s-এর একটি MVCArray
রয়েছে৷ সমস্ত মানচিত্র প্রকার (বেস এবং ওভারলে) mapPane
স্তরের মধ্যে রেন্ডার করা হয়। ওভারলে মানচিত্রের প্রকারগুলি তারা সংযুক্ত বেস মানচিত্রের উপরে প্রদর্শিত হবে, যে ক্রমে তারা Map.overlayMapTypes
অ্যারেতে প্রদর্শিত হবে (উচ্চ সূচক মান সহ ওভারলেগুলি নিম্ন সূচক মান সহ ওভারলেগুলির সামনে প্রদর্শিত হয়)।
নিম্নলিখিত উদাহরণটি পূর্ববর্তীটির সাথে অভিন্ন ব্যতীত যে আমরা ROADMAP
মানচিত্রের প্রকারের উপরে একটি টাইল ওভারলে MapType
তৈরি করেছি:
টাইপস্ক্রিপ্ট
/* * This demo illustrates the coordinate system used to display map tiles in the * API. * * Tiles in Google Maps are numbered from the same origin as that for * pixels. For Google's implementation of the Mercator projection, the origin * tile is always at the northwest corner of the map, with x values increasing * from west to east and y values increasing from north to south. * * Try panning and zooming the map to see how the coordinates change. */ class CoordMapType implements google.maps.MapType { tileSize: google.maps.Size; alt: string|null = null; maxZoom: number = 17; minZoom: number = 0; name: string|null = null; projection: google.maps.Projection|null = null; radius: number = 6378137; constructor(tileSize: google.maps.Size) { this.tileSize = tileSize; } getTile( coord: google.maps.Point, zoom: number, ownerDocument: Document ): HTMLElement { const div = ownerDocument.createElement("div"); div.innerHTML = String(coord); div.style.width = this.tileSize.width + "px"; div.style.height = this.tileSize.height + "px"; div.style.fontSize = "10"; div.style.borderStyle = "solid"; div.style.borderWidth = "1px"; div.style.borderColor = "#AAAAAA"; return div; } releaseTile(tile: Element): void {} } function initMap(): void { const map = new google.maps.Map( document.getElementById("map") as HTMLElement, { zoom: 10, center: { lat: 41.85, lng: -87.65 }, } ); // Insert this overlay map type as the first overlay map type at // position 0. Note that all overlay map types appear on top of // their parent base map. const coordMapType = new CoordMapType(new google.maps.Size(256, 256)) map.overlayMapTypes.insertAt( 0, coordMapType ); } declare global { interface Window { initMap: () => void; } } window.initMap = initMap;
জাভাস্ক্রিপ্ট
/* * This demo illustrates the coordinate system used to display map tiles in the * API. * * Tiles in Google Maps are numbered from the same origin as that for * pixels. For Google's implementation of the Mercator projection, the origin * tile is always at the northwest corner of the map, with x values increasing * from west to east and y values increasing from north to south. * * Try panning and zooming the map to see how the coordinates change. */ class CoordMapType { tileSize; alt = null; maxZoom = 17; minZoom = 0; name = null; projection = null; radius = 6378137; constructor(tileSize) { this.tileSize = tileSize; } getTile(coord, zoom, ownerDocument) { const div = ownerDocument.createElement("div"); div.innerHTML = String(coord); div.style.width = this.tileSize.width + "px"; div.style.height = this.tileSize.height + "px"; div.style.fontSize = "10"; div.style.borderStyle = "solid"; div.style.borderWidth = "1px"; div.style.borderColor = "#AAAAAA"; return div; } releaseTile(tile) {} } function initMap() { const map = new google.maps.Map(document.getElementById("map"), { zoom: 10, center: { lat: 41.85, lng: -87.65 }, }); // Insert this overlay map type as the first overlay map type at // position 0. Note that all overlay map types appear on top of // their parent base map. const coordMapType = new CoordMapType(new google.maps.Size(256, 256)); map.overlayMapTypes.insertAt(0, coordMapType); } window.initMap = initMap;
নমুনা চেষ্টা করুন
চিত্র মানচিত্র প্রকার
একটি বেস ম্যাপ টাইপ হিসাবে কাজ করার জন্য একটি MapType
বাস্তবায়ন করা একটি সময়সাপেক্ষ এবং শ্রমসাধ্য কাজ হতে পারে। API একটি বিশেষ শ্রেণী প্রদান করে যা সবচেয়ে সাধারণ মানচিত্র প্রকারের জন্য MapType
ইন্টারফেস প্রয়োগ করে: মানচিত্রের ধরন যা একক ইমেজ ফাইল দিয়ে তৈরি টাইলস নিয়ে গঠিত।
এই ক্লাস, ImageMapType
ক্লাস, নিম্নলিখিত প্রয়োজনীয় বৈশিষ্ট্যগুলিকে সংজ্ঞায়িত করে একটি ImageMapTypeOptions
অবজেক্ট স্পেসিফিকেশন ব্যবহার করে তৈরি করা হয়েছে:
-
tileSize
(প্রয়োজনীয়) টাইলের আকার নির্দিষ্ট করে (google.maps.Size
টাইপ)। আকারগুলি অবশ্যই আয়তক্ষেত্রাকার হতে হবে যদিও সেগুলি বর্গাকার হওয়ার দরকার নেই৷ -
getTileUrl
(প্রয়োজনীয়) ফাংশনটি নির্দিষ্ট করে, সাধারণত একটি ইনলাইন ফাংশন আক্ষরিক হিসাবে সরবরাহ করা হয়, সরবরাহ করা বিশ্ব স্থানাঙ্ক এবং জুম স্তরের উপর ভিত্তি করে সঠিক চিত্র টাইলের নির্বাচন পরিচালনা করতে।
নিম্নলিখিত কোডটি Google এর চাঁদের টাইলস ব্যবহার করে একটি মৌলিক ImageMapType
প্রয়োগ করে৷ উদাহরণটি একটি স্বাভাবিককরণ ফাংশন ব্যবহার করে তা নিশ্চিত করতে যে টাইলসগুলি x-অক্ষ বরাবর পুনরাবৃত্তি হয়, কিন্তু আপনার মানচিত্রের y-অক্ষ বরাবর নয়।
টাইপস্ক্রিপ্ট
function initMap(): void { const map = new google.maps.Map( document.getElementById("map") as HTMLElement, { center: { lat: 0, lng: 0 }, zoom: 1, streetViewControl: false, mapTypeControlOptions: { mapTypeIds: ["moon"], }, } ); const moonMapType = new google.maps.ImageMapType({ getTileUrl: function (coord, zoom): string { const normalizedCoord = getNormalizedCoord(coord, zoom); if (!normalizedCoord) { return ""; } const bound = Math.pow(2, zoom); return ( "https://mw1.google.com/mw-planetary/lunar/lunarmaps_v1/clem_bw" + "/" + zoom + "/" + normalizedCoord.x + "/" + (bound - normalizedCoord.y - 1) + ".jpg" ); }, tileSize: new google.maps.Size(256, 256), maxZoom: 9, minZoom: 0, // @ts-ignore TODO 'radius' does not exist in type 'ImageMapTypeOptions' radius: 1738000, name: "Moon", }); map.mapTypes.set("moon", moonMapType); map.setMapTypeId("moon"); } // Normalizes the coords that tiles repeat across the x axis (horizontally) // like the standard Google map tiles. function getNormalizedCoord(coord, zoom) { const y = coord.y; let x = coord.x; // tile range in one direction range is dependent on zoom level // 0 = 1 tile, 1 = 2 tiles, 2 = 4 tiles, 3 = 8 tiles, etc const tileRange = 1 << zoom; // don't repeat across y-axis (vertically) if (y < 0 || y >= tileRange) { return null; } // repeat across x-axis if (x < 0 || x >= tileRange) { x = ((x % tileRange) + tileRange) % tileRange; } return { x: x, y: y }; } declare global { interface Window { initMap: () => void; } } window.initMap = initMap;
জাভাস্ক্রিপ্ট
function initMap() { const map = new google.maps.Map(document.getElementById("map"), { center: { lat: 0, lng: 0 }, zoom: 1, streetViewControl: false, mapTypeControlOptions: { mapTypeIds: ["moon"], }, }); const moonMapType = new google.maps.ImageMapType({ getTileUrl: function (coord, zoom) { const normalizedCoord = getNormalizedCoord(coord, zoom); if (!normalizedCoord) { return ""; } const bound = Math.pow(2, zoom); return ( "https://mw1.google.com/mw-planetary/lunar/lunarmaps_v1/clem_bw" + "/" + zoom + "/" + normalizedCoord.x + "/" + (bound - normalizedCoord.y - 1) + ".jpg" ); }, tileSize: new google.maps.Size(256, 256), maxZoom: 9, minZoom: 0, // @ts-ignore TODO 'radius' does not exist in type 'ImageMapTypeOptions' radius: 1738000, name: "Moon", }); map.mapTypes.set("moon", moonMapType); map.setMapTypeId("moon"); } // Normalizes the coords that tiles repeat across the x axis (horizontally) // like the standard Google map tiles. function getNormalizedCoord(coord, zoom) { const y = coord.y; let x = coord.x; // tile range in one direction range is dependent on zoom level // 0 = 1 tile, 1 = 2 tiles, 2 = 4 tiles, 3 = 8 tiles, etc const tileRange = 1 << zoom; // don't repeat across y-axis (vertically) if (y < 0 || y >= tileRange) { return null; } // repeat across x-axis if (x < 0 || x >= tileRange) { x = ((x % tileRange) + tileRange) % tileRange; } return { x: x, y: y }; } window.initMap = initMap;
নমুনা চেষ্টা করুন
অনুমান
পৃথিবী একটি ত্রিমাত্রিক গোলক (প্রায়), যখন একটি মানচিত্র একটি সমতল দ্বি-মাত্রিক পৃষ্ঠ। আপনি মানচিত্রের জাভাস্ক্রিপ্ট API-এর মধ্যে যে মানচিত্রটি দেখতে পান, পৃথিবীর যেকোনো সমতল মানচিত্রের মতো, এটি একটি সমতল পৃষ্ঠের উপর সেই গোলকের একটি অভিক্ষেপ । এর সহজ শর্তে, একটি অভিক্ষেপকে অভিক্ষেপের মানচিত্রে স্থানাঙ্কে অক্ষাংশ/দ্রাঘিমাংশের মানগুলির ম্যাপিং হিসাবে সংজ্ঞায়িত করা যেতে পারে।
মানচিত্র জাভাস্ক্রিপ্ট এপিআই-এ প্রজেকশনগুলি অবশ্যই Projection
ইন্টারফেস বাস্তবায়ন করবে। একটি Projection
বাস্তবায়ন অবশ্যই একটি স্থানাঙ্ক সিস্টেম থেকে অন্য একটি ম্যাপিং প্রদান করবে না, তবে একটি দ্বি-নির্দেশিক ম্যাপিং প্রদান করবে। অর্থাৎ, আপনাকে অবশ্যই নির্ধারণ করতে হবে কিভাবে আর্থ কোঅর্ডিনেট ( LatLng
অবজেক্ট) থেকে Projection
ক্লাসের ওয়ার্ল্ড কোঅর্ডিনেট সিস্টেমে এবং ওয়ার্ল্ড কোঅর্ডিনেট সিস্টেম থেকে আবার আর্থ কোঅর্ডিনেটে অনুবাদ করতে হবে। Google Maps ভৌগলিক ডেটা থেকে এর মানচিত্র তৈরি করতে এবং মানচিত্রের ইভেন্টগুলিকে ভৌগলিক স্থানাঙ্কে রূপান্তর করতে Mercator প্রজেকশন ব্যবহার করে। আপনি Map
(অথবা স্ট্যান্ডার্ড বেস MapType
প্রকারের যেকোনো একটি getProjection()
কল করে এই প্রজেকশনটি পেতে পারেন, বেশিরভাগ ব্যবহারের জন্য, এই স্ট্যান্ডার্ড Projection
যথেষ্ট হবে, তবে আপনি আপনার নিজস্ব কাস্টম প্রজেকশনও সংজ্ঞায়িত করতে এবং ব্যবহার করতে পারেন।
একটি অভিক্ষেপ বাস্তবায়ন
একটি কাস্টম প্রজেকশন বাস্তবায়ন করার সময়, আপনাকে কয়েকটি জিনিস সংজ্ঞায়িত করতে হবে:
- ম্যাপিং অক্ষাংশ এবং দ্রাঘিমাংশের জন্য সূত্রগুলি একটি কার্টেসিয়ান সমতলে এবং একটি কার্টেসিয়ান সমতল থেকে অক্ষাংশ এবং দ্রাঘিমাংশ স্থানাঙ্কে ম্যাপিংয়ের জন্য সংশ্লিষ্ট সূত্রগুলি। (
Projection
ইন্টারফেস শুধুমাত্র রেক্টিলাইনার কোঅর্ডিনেটে রূপান্তরকে সমর্থন করে।) - বেস টালি আকার. সমস্ত টাইলস আয়তক্ষেত্রাকার হতে হবে।
- বেস টাইল ব্যবহার করে একটি মানচিত্রের "বিশ্বের আকার" জুম স্তর 0 এ সেট করা হয়েছে। মনে রাখবেন যে জুম 0 এ একটি টাইল সমন্বিত মানচিত্রের জন্য, বিশ্বের আকার এবং বেস টাইলের আকার অভিন্ন।
অভিক্ষেপে রূপান্তর সমন্বয় করুন
প্রতিটি অভিক্ষেপ দুটি পদ্ধতি প্রদান করে যা এই দুটি স্থানাঙ্ক সিস্টেমের মধ্যে অনুবাদ করে, আপনাকে ভৌগলিক এবং বিশ্ব স্থানাঙ্কের মধ্যে রূপান্তর করার অনুমতি দেয়:
-
Projection.fromLatLngToPoint()
পদ্ধতি একটিLatLng
মানকে একটি বিশ্ব স্থানাঙ্কে রূপান্তর করে। এই পদ্ধতিটি মানচিত্রে ওভারলেগুলির অবস্থানের জন্য (এবং মানচিত্রের অবস্থানের জন্য) ব্যবহার করা হয়। -
Projection.fromPointToLatLng()
পদ্ধতি একটি বিশ্ব স্থানাঙ্ককে একটিLatLng
মানতে রূপান্তর করে। এই পদ্ধতিটি ম্যাপে ঘটে যাওয়া ক্লিকের মতো ঘটনাগুলিকে ভৌগলিক স্থানাঙ্কে রূপান্তর করতে ব্যবহৃত হয়।
Google মানচিত্র অনুমান করে যে অনুমানগুলি রেকটিলিয়ার।
সাধারণত, আপনি দুটি ক্ষেত্রে একটি অভিক্ষেপ ব্যবহার করতে পারেন: বিশ্বের একটি মানচিত্র তৈরি করতে, অথবা একটি স্থানীয় এলাকার মানচিত্র তৈরি করতে৷ পূর্বের ক্ষেত্রে, আপনাকে নিশ্চিত করতে হবে যে আপনার প্রক্ষেপণটিও সমস্ত দ্রাঘিমাংশে রেকটিলিয়ার এবং স্বাভাবিক। কিছু অনুমান (বিশেষত শঙ্কু অভিক্ষেপ) "স্থানীয়ভাবে স্বাভাবিক" (অর্থাৎ উত্তর বিন্দু) হতে পারে কিন্তু প্রকৃত উত্তর থেকে বিচ্যুত হয়; উদাহরণস্বরূপ, কিছু রেফারেন্স দ্রাঘিমাংশের সাপেক্ষে মানচিত্রটি আরও অবস্থান করে। আপনি স্থানীয়ভাবে এই ধরনের একটি অভিক্ষেপ ব্যবহার করতে পারেন, কিন্তু সচেতন থাকুন যে অভিক্ষেপটি অগত্যা অশুদ্ধ এবং রূপান্তর ত্রুটিগুলি স্পষ্টতই আপনি যে রেফারেন্স দ্রাঘিমাংশ থেকে বিচ্যুত হবেন তার থেকে আরও দূরে হয়ে যাবে।
অভিক্ষেপে মানচিত্র টাইল নির্বাচন
অনুমানগুলি কেবল অবস্থান বা ওভারলেগুলির অবস্থান নির্ধারণের জন্যই কার্যকর নয়, তবে মানচিত্রের টাইলগুলির অবস্থান নির্ধারণের জন্যও কার্যকর। Maps JavaScript API একটি MapType
ইন্টারফেস ব্যবহার করে বেস ম্যাপ রেন্ডার করে, যা অবশ্যই মানচিত্রের অভিক্ষেপ সনাক্তকরণের জন্য একটি projection
সম্পত্তি এবং টাইল সমন্বয় মানগুলির উপর ভিত্তি করে মানচিত্র টাইলগুলি পুনরুদ্ধার করার জন্য একটি getTile()
পদ্ধতি উভয়ই ঘোষণা করতে হবে৷ টাইল স্থানাঙ্কগুলি আপনার মৌলিক টাইল আকার (যা আয়তক্ষেত্রাকার হতে হবে) এবং আপনার মানচিত্রের "বিশ্বের আকার" উভয়ের উপর ভিত্তি করে, যা জুম স্তর 0 এ আপনার মানচিত্রের বিশ্বের পিক্সেল আকার।
আপনি আপনার MapType
এর tileSize
সম্পত্তির মধ্যে বেস টাইলের আকার নির্ধারণ করুন। আপনি আপনার প্রজেকশনের fromLatLngToPoint()
এবং fromPointToLatLng()
পদ্ধতির মধ্যে অন্তর্নিহিতভাবে বিশ্বের আকার সংজ্ঞায়িত করেন।
যেহেতু ছবি নির্বাচন এই পাস করা মানগুলির উপর নির্ভর করে, তাই map _ zoom _ tileX _ tileY .png
এর মতো এই পাস করা মানগুলিকে প্রোগ্রাম্যাটিকভাবে নির্বাচন করা যেতে পারে এমন ছবিগুলির নাম দেওয়া দরকারী।
নিম্নলিখিত উদাহরণটি গ্যাল-পিটার্স প্রজেকশন ব্যবহার করে একটি ImageMapType
সংজ্ঞায়িত করে:
টাইপস্ক্রিপ্ট
// This example defines an image map type using the Gall-Peters // projection. // https://en.wikipedia.org/wiki/Gall%E2%80%93Peters_projection const mapElement = document.querySelector("gmp-map") as google.maps.MapElement; let innerMap; async function initMap() { // Request the needed libraries. await google.maps.importLibrary("maps"); // Create a map. innerMap = mapElement.innerMap; innerMap.setOptions({ mapTypeControl: false, }); // Set the Gall-Peters map type. initGallPeters(); innerMap.mapTypes.set("gallPeters", gallPetersMapType); innerMap.setMapTypeId("gallPeters"); // Show the lat and lng under the mouse cursor. const coordsDiv = document.getElementById("coords") as HTMLElement; innerMap.addListener("mousemove", (event: google.maps.MapMouseEvent) => { coordsDiv.textContent = "lat: " + Math.round(event.latLng!.lat()) + ", " + "lng: " + Math.round(event.latLng!.lng()); }); // Add some markers to the map. innerMap.data.setStyle((feature) => { return { title: feature.getProperty("name") as string, optimized: false, }; }); innerMap.data.addGeoJson(cities); } let gallPetersMapType; function initGallPeters() { const GALL_PETERS_RANGE_X = 800; const GALL_PETERS_RANGE_Y = 512; // Fetch Gall-Peters tiles stored locally on our server. gallPetersMapType = new google.maps.ImageMapType({ getTileUrl: function (coord, zoom) { const scale = 1 << zoom; // Wrap tiles horizontally. const x = ((coord.x % scale) + scale) % scale; // Don't wrap tiles vertically. const y = coord.y; if (y < 0 || y >= scale) return ""; return ( "gall-peters_" + zoom + "_" + x + "_" + y + ".png" ); }, tileSize: new google.maps.Size(GALL_PETERS_RANGE_X, GALL_PETERS_RANGE_Y), minZoom: 0, maxZoom: 1, name: "Gall-Peters", }); // Describe the Gall-Peters projection used by these tiles. gallPetersMapType.projection = { fromLatLngToPoint: function (latLng) { const latRadians = (latLng.lat() * Math.PI) / 180; return new google.maps.Point( GALL_PETERS_RANGE_X * (0.5 + latLng.lng() / 360), GALL_PETERS_RANGE_Y * (0.5 - 0.5 * Math.sin(latRadians)) ); }, fromPointToLatLng: function (point, noWrap) { const x = point.x / GALL_PETERS_RANGE_X; const y = Math.max(0, Math.min(1, point.y / GALL_PETERS_RANGE_Y)); return new google.maps.LatLng( (Math.asin(1 - 2 * y) * 180) / Math.PI, -180 + 360 * x, noWrap ); }, }; } // GeoJSON, describing the locations and names of some cities. const cities = { type: "FeatureCollection", features: [ { type: "Feature", geometry: { type: "Point", coordinates: [-87.65, 41.85] }, properties: { name: "Chicago" }, }, { type: "Feature", geometry: { type: "Point", coordinates: [-149.9, 61.218] }, properties: { name: "Anchorage" }, }, { type: "Feature", geometry: { type: "Point", coordinates: [-99.127, 19.427] }, properties: { name: "Mexico City" }, }, { type: "Feature", geometry: { type: "Point", coordinates: [-0.126, 51.5] }, properties: { name: "London" }, }, { type: "Feature", geometry: { type: "Point", coordinates: [28.045, -26.201] }, properties: { name: "Johannesburg" }, }, { type: "Feature", geometry: { type: "Point", coordinates: [15.322, -4.325] }, properties: { name: "Kinshasa" }, }, { type: "Feature", geometry: { type: "Point", coordinates: [151.207, -33.867] }, properties: { name: "Sydney" }, }, { type: "Feature", geometry: { type: "Point", coordinates: [0, 0] }, properties: { name: "0°N 0°E" }, }, ], }; initMap();
জাভাস্ক্রিপ্ট
// This example defines an image map type using the Gall-Peters // projection. // https://en.wikipedia.org/wiki/Gall%E2%80%93Peters_projection const mapElement = document.querySelector("gmp-map"); let innerMap; async function initMap() { // Request the needed libraries. await google.maps.importLibrary("maps"); // Create a map. innerMap = mapElement.innerMap; innerMap.setOptions({ mapTypeControl: false, }); // Set the Gall-Peters map type. initGallPeters(); innerMap.mapTypes.set("gallPeters", gallPetersMapType); innerMap.setMapTypeId("gallPeters"); // Show the lat and lng under the mouse cursor. const coordsDiv = document.getElementById("coords"); innerMap.addListener("mousemove", (event) => { coordsDiv.textContent = "lat: " + Math.round(event.latLng.lat()) + ", " + "lng: " + Math.round(event.latLng.lng()); }); // Add some markers to the map. innerMap.data.setStyle((feature) => { return { title: feature.getProperty("name"), optimized: false, }; }); innerMap.data.addGeoJson(cities); } let gallPetersMapType; function initGallPeters() { const GALL_PETERS_RANGE_X = 800; const GALL_PETERS_RANGE_Y = 512; // Fetch Gall-Peters tiles stored locally on our server. gallPetersMapType = new google.maps.ImageMapType({ getTileUrl: function (coord, zoom) { const scale = 1 << zoom; // Wrap tiles horizontally. const x = ((coord.x % scale) + scale) % scale; // Don't wrap tiles vertically. const y = coord.y; if (y < 0 || y >= scale) return ""; return ("gall-peters_" + zoom + "_" + x + "_" + y + ".png"); }, tileSize: new google.maps.Size(GALL_PETERS_RANGE_X, GALL_PETERS_RANGE_Y), minZoom: 0, maxZoom: 1, name: "Gall-Peters", }); // Describe the Gall-Peters projection used by these tiles. gallPetersMapType.projection = { fromLatLngToPoint: function (latLng) { const latRadians = (latLng.lat() * Math.PI) / 180; return new google.maps.Point(GALL_PETERS_RANGE_X * (0.5 + latLng.lng() / 360), GALL_PETERS_RANGE_Y * (0.5 - 0.5 * Math.sin(latRadians))); }, fromPointToLatLng: function (point, noWrap) { const x = point.x / GALL_PETERS_RANGE_X; const y = Math.max(0, Math.min(1, point.y / GALL_PETERS_RANGE_Y)); return new google.maps.LatLng((Math.asin(1 - 2 * y) * 180) / Math.PI, -180 + 360 * x, noWrap); }, }; } // GeoJSON, describing the locations and names of some cities. const cities = { type: "FeatureCollection", features: [ { type: "Feature", geometry: { type: "Point", coordinates: [-87.65, 41.85] }, properties: { name: "Chicago" }, }, { type: "Feature", geometry: { type: "Point", coordinates: [-149.9, 61.218] }, properties: { name: "Anchorage" }, }, { type: "Feature", geometry: { type: "Point", coordinates: [-99.127, 19.427] }, properties: { name: "Mexico City" }, }, { type: "Feature", geometry: { type: "Point", coordinates: [-0.126, 51.5] }, properties: { name: "London" }, }, { type: "Feature", geometry: { type: "Point", coordinates: [28.045, -26.201] }, properties: { name: "Johannesburg" }, }, { type: "Feature", geometry: { type: "Point", coordinates: [15.322, -4.325] }, properties: { name: "Kinshasa" }, }, { type: "Feature", geometry: { type: "Point", coordinates: [151.207, -33.867] }, properties: { name: "Sydney" }, }, { type: "Feature", geometry: { type: "Point", coordinates: [0, 0] }, properties: { name: "0°N 0°E" }, }, ], }; initMap();
নমুনা চেষ্টা করুন
এই নথিতে আপনি Maps JavaScript API ব্যবহার করে প্রদর্শন করতে পারেন এমন মানচিত্রের ধরন নিয়ে আলোচনা করে। API এই মানচিত্র সম্পর্কে তথ্য ধারণ করার জন্য একটি MapType
অবজেক্ট ব্যবহার করে। একটি MapType
হল একটি ইন্টারফেস যা মানচিত্র টাইলগুলির প্রদর্শন এবং ব্যবহার এবং স্ক্রীন স্থানাঙ্ক থেকে বিশ্ব স্থানাঙ্কে (মানচিত্রে) স্থানাঙ্ক সিস্টেমের অনুবাদ সংজ্ঞায়িত করে। প্রতিটি MapType
টাইলস পুনরুদ্ধার এবং রিলিজ পরিচালনা করার জন্য কয়েকটি পদ্ধতি এবং বৈশিষ্ট্যগুলি থাকতে হবে যা এর চাক্ষুষ আচরণকে সংজ্ঞায়িত করে।
Maps JavaScript API-এর মধ্যে মানচিত্রের প্রকারের অভ্যন্তরীণ কাজগুলি একটি উন্নত বিষয়। বেশিরভাগ বিকাশকারীরা নীচে উল্লিখিত মৌলিক মানচিত্র প্রকারগুলি ব্যবহার করতে পারেন৷ যাইহোক, আপনি স্টাইল করা মানচিত্র ব্যবহার করে বিদ্যমান মানচিত্রের প্রকারের উপস্থাপনাও সংশোধন করতে পারেন বা কাস্টম মানচিত্র প্রকারগুলি ব্যবহার করে আপনার নিজস্ব মানচিত্র টাইলস সংজ্ঞায়িত করতে পারেন। কাস্টম মানচিত্রের প্রকারগুলি প্রদান করার সময়, আপনাকে মানচিত্রের মানচিত্র প্রকার রেজিস্ট্রি কীভাবে সংশোধন করতে হবে তা বুঝতে হবে।
মৌলিক মানচিত্র প্রকার
Maps JavaScript API-এর মধ্যে চার ধরনের মানচিত্র পাওয়া যায়। পরিচিত "পেইন্টেড" রোড ম্যাপ টাইলস ছাড়াও, Maps JavaScript API অন্যান্য মানচিত্র প্রকারগুলিকেও সমর্থন করে৷
নিম্নলিখিত মানচিত্র প্রকারগুলি মানচিত্র জাভাস্ক্রিপ্ট API-এ উপলব্ধ:
-
roadmap
ডিফল্ট রোড ম্যাপ ভিউ প্রদর্শন করে। এটি ডিফল্ট মানচিত্র প্রকার। -
satellite
গুগল আর্থ স্যাটেলাইট ছবি প্রদর্শন করে। -
hybrid
স্বাভাবিক এবং স্যাটেলাইট দৃশ্যের মিশ্রণ প্রদর্শন করে। -
terrain
ভূখণ্ডের তথ্যের উপর ভিত্তি করে একটি ভৌত মানচিত্র প্রদর্শন করে।
আপনি Map
দ্বারা ব্যবহৃত মানচিত্রের ধরনটি পরিবর্তন করুন এর mapTypeId
বৈশিষ্ট্য সেট করে, হয় কনস্ট্রাক্টরের মধ্যে এর Map options
অবজেক্ট সেট করে, অথবা মানচিত্রের setMapTypeId()
পদ্ধতিতে কল করে। mapTypeID
প্রপার্টি roadmap
ডিফল্ট।
নির্মাণের সময় mapTypeId
সেট করা হচ্ছে:
var myLatlng = new google.maps.LatLng(-34.397, 150.644); var mapOptions = { zoom: 8, center: myLatlng, mapTypeId: 'satellite' }; var map = new google.maps.Map(document.getElementById('map'), mapOptions);
গতিশীলভাবে mapTypeId
পরিবর্তন করা হচ্ছে:
map.setMapTypeId('terrain');
মনে রাখবেন যে আপনি প্রকৃতপক্ষে মানচিত্রের মানচিত্র প্রকারটি সরাসরি সেট করেন না, তবে এর পরিবর্তে একটি শনাক্তকারী ব্যবহার করে একটি MapType
উল্লেখ করার জন্য এর mapTypeId
সেট করুন৷ মানচিত্র জাভাস্ক্রিপ্ট API এই রেফারেন্সগুলি পরিচালনা করার জন্য নীচে ব্যাখ্যা করা একটি মানচিত্রের প্রকার রেজিস্ট্রি ব্যবহার করে৷
45° চিত্র
মানচিত্র জাভাস্ক্রিপ্ট API নির্দিষ্ট অবস্থানের জন্য বিশেষ 45° চিত্র সমর্থন করে। এই উচ্চ-রেজোলিউশন চিত্রাবলী প্রতিটি মূল দিক (উত্তর, দক্ষিণ, পূর্ব, পশ্চিম) প্রতি দৃষ্টিভঙ্গি দেখায়। সমর্থিত মানচিত্র প্রকারের জন্য এই ছবিগুলি উচ্চতর জুম স্তরে উপলব্ধ।
নিম্নলিখিত চিত্রটি নিউ ইয়র্ক সিটির একটি 45° দৃষ্টিকোণ দেখায়:
satellite
এবং hybrid
মানচিত্রের প্রকারগুলি যেখানে উপলব্ধ সেখানে উচ্চ জুম স্তরে (12 এবং তার বেশি) 45° চিত্র সমর্থন করে৷ যদি ব্যবহারকারী এমন একটি অবস্থানে জুম করে যার জন্য এই ধরনের চিত্র বিদ্যমান, এই মানচিত্র প্রকারগুলি স্বয়ংক্রিয়ভাবে নিম্নলিখিত পদ্ধতিতে তাদের দৃষ্টিভঙ্গি পরিবর্তন করে:
- স্যাটেলাইট বা হাইব্রিড চিত্রগুলি বর্তমান অবস্থানকে কেন্দ্র করে 45° দৃষ্টিকোণ প্রদান করে চিত্রগুলির সাথে প্রতিস্থাপিত হয়৷ ডিফল্টরূপে, এই ধরনের দৃষ্টিভঙ্গি উত্তর দিকে ভিত্তিক। ব্যবহারকারী জুম আউট করলে, ডিফল্ট স্যাটেলাইট বা হাইব্রিড চিত্র আবার প্রদর্শিত হবে। জুম লেভেল এবং
tilt
মানের উপর নির্ভর করে আচরণ পরিবর্তিত হয়: - জুম লেভেল 12 এবং 18 এর মধ্যে টপ-ডাউন বেসম্যাপ (0°) ডিফল্টভাবে প্রদর্শিত হয় যদি না
tilt
45 এ সেট করা হয়। - 18 বা তার বেশি জুম লেভেলে 45° বেসম্যাপ দেখায় যদি না
tilt
0 এ সেট করা হয়। - ঘূর্ণন নিয়ন্ত্রণ দৃশ্যমান হয়ে ওঠে. ঘূর্ণন নিয়ন্ত্রণ বিকল্পগুলি প্রদান করে যা ব্যবহারকারীকে টিল্ট টগল করতে এবং উভয় দিকে 90° বৃদ্ধিতে ভিউ ঘোরাতে সক্ষম করে। রোটেট কন্ট্রোল লুকানোর জন্য,
rotateControl
কেfalse
এ সেট করুন।
45° চিত্র প্রদর্শন করে একটি মানচিত্রের ধরন থেকে জুম আউট করা এই প্রতিটি পরিবর্তনকে ফিরিয়ে দেয়, মূল মানচিত্রের প্রকারগুলিকে পুনঃপ্রতিষ্ঠা করে।
45° চিত্রাবলী সক্ষম এবং অক্ষম করুন৷
আপনি Map
বস্তুতে setTilt(0)
কল করে 45° চিত্র অক্ষম করতে পারেন। সমর্থিত মানচিত্র প্রকারের জন্য 45° চিত্র সক্ষম করতে, setTilt(45)
কল করুন। Map
getTilt()
পদ্ধতি সর্বদা মানচিত্রে প্রদর্শিত বর্তমান tilt
প্রতিফলিত করবে; যদি আপনি একটি মানচিত্রে একটি tilt
সেট করেন এবং তারপরে সেই tilt
সরিয়ে দেন (উদাহরণস্বরূপ, মানচিত্রটি জুম করে), মানচিত্রের getTilt()
পদ্ধতিটি 0
ফেরত দেবে।
গুরুত্বপূর্ণ: 45° চিত্র শুধুমাত্র রাস্টার মানচিত্রে সমর্থিত; এই চিত্র ভেক্টর মানচিত্রে ব্যবহার করা যাবে না।
নিম্নলিখিত উদাহরণটি নিউ ইয়র্ক সিটির 45° দৃশ্য প্রদর্শন করে:
টাইপস্ক্রিপ্ট
function initMap(): void { const map = new google.maps.Map( document.getElementById("map") as HTMLElement, { center: { lat: 40.76, lng: -73.983 }, zoom: 15, mapTypeId: "satellite", } ); map.setTilt(45); } declare global { interface Window { initMap: () => void; } } window.initMap = initMap;
জাভাস্ক্রিপ্ট
function initMap() { const map = new google.maps.Map(document.getElementById("map"), { center: { lat: 40.76, lng: -73.983 }, zoom: 15, mapTypeId: "satellite", }); map.setTilt(45); } window.initMap = initMap;
নমুনা চেষ্টা করুন
45° চিত্র ঘোরান
45° চিত্রে প্রকৃতপক্ষে প্রতিটি মূল দিক (উত্তর, দক্ষিণ, পূর্ব, পশ্চিম) ছবির একটি সংগ্রহ রয়েছে। একবার আপনার মানচিত্র 45° চিত্র প্রদর্শন করলে, আপনি Map
অবজেক্টে setHeading()
কল করে, উত্তর থেকে ডিগ্রী হিসাবে প্রকাশ করা একটি সংখ্যা মান পাস করে চিত্রটিকে এর মূল দিকগুলির একটির দিকে অভিমুখ করতে পারেন।
নিম্নলিখিত উদাহরণটি একটি বায়বীয় মানচিত্র দেখায় এবং বোতামটি ক্লিক করা হলে প্রতি 3 সেকেন্ডে মানচিত্রটি স্বয়ংক্রিয়ভাবে ঘোরে:
টাইপস্ক্রিপ্ট
let map: google.maps.Map; function initMap(): void { map = new google.maps.Map(document.getElementById("map") as HTMLElement, { center: { lat: 40.76, lng: -73.983 }, zoom: 15, mapTypeId: "satellite", heading: 90, tilt: 45, }); // add listener to button document.getElementById("rotate")!.addEventListener("click", autoRotate); } function rotate90(): void { const heading = map.getHeading() || 0; map.setHeading(heading + 90); } function autoRotate(): void { // Determine if we're showing aerial imagery. if (map.getTilt() !== 0) { window.setInterval(rotate90, 3000); } } declare global { interface Window { initMap: () => void; } } window.initMap = initMap;
জাভাস্ক্রিপ্ট
let map; function initMap() { map = new google.maps.Map(document.getElementById("map"), { center: { lat: 40.76, lng: -73.983 }, zoom: 15, mapTypeId: "satellite", heading: 90, tilt: 45, }); // add listener to button document.getElementById("rotate").addEventListener("click", autoRotate); } function rotate90() { const heading = map.getHeading() || 0; map.setHeading(heading + 90); } function autoRotate() { // Determine if we're showing aerial imagery. if (map.getTilt() !== 0) { window.setInterval(rotate90, 3000); } } window.initMap = initMap;
নমুনা চেষ্টা করুন
ম্যাপ টাইপ রেজিস্ট্রি পরিবর্তন করুন
একটি মানচিত্রের mapTypeId
হল একটি স্ট্রিং শনাক্তকারী যা একটি MapType
একটি অনন্য মানের সাথে সংযুক্ত করতে ব্যবহৃত হয়। প্রতিটি Map
অবজেক্ট একটি MapTypeRegistry
বজায় রাখে যাতে সেই মানচিত্রের জন্য উপলব্ধ MapType
s এর সংগ্রহ থাকে। এই রেজিস্ট্রিটি ম্যাপের ম্যাপ টাইপ নিয়ন্ত্রণে উপলব্ধ মানচিত্রের ধরন নির্বাচন করতে ব্যবহৃত হয়, উদাহরণস্বরূপ।
আপনি ম্যাপ টাইপ রেজিস্ট্রি থেকে সরাসরি পড়েন না। পরিবর্তে, আপনি কাস্টম মানচিত্রের প্রকারগুলি যোগ করে এবং আপনার পছন্দের একটি স্ট্রিং শনাক্তকারীর সাথে সংযুক্ত করে রেজিস্ট্রিটি সংশোধন করুন৷ আপনি মৌলিক মানচিত্রের প্রকারগুলি পরিবর্তন বা পরিবর্তন করতে পারবেন না (যদিও আপনি মানচিত্রের সংশ্লিষ্ট mapTypeControlOptions
এর চেহারা পরিবর্তন করে মানচিত্র থেকে সেগুলি সরাতে পারেন)।
নিম্নলিখিত কোডটি মানচিত্রের মানচিত্রের mapTypeControlOptions
শুধুমাত্র দুটি মানচিত্র প্রকার দেখানোর জন্য মানচিত্রকে সেট করে এবং MapType
ইন্টারফেসের প্রকৃত বাস্তবায়নে এই শনাক্তকারীর সাথে অ্যাসোসিয়েশন যোগ করার জন্য রেজিস্ট্রি সংশোধন করে।
// Modify the control to only display two maptypes, the // default ROADMAP and the custom 'mymap'. // Note that because this is an association, we // don't need to modify the MapTypeRegistry beforehand. var MY_MAPTYPE_ID = 'mymaps'; var mapOptions = { zoom: 12, center: brooklyn, mapTypeControlOptions: { mapTypeIds: ['roadmap', MY_MAPTYPE_ID] }, mapTypeId: MY_MAPTYPE_ID }; // Create our map. This creation will implicitly create a // map type registry. map = new google.maps.Map(document.getElementById('map'), mapOptions); // Create your custom map type using your own code. // (See below.) var myMapType = new MyMapType(); // Set the registry to associate 'mymap' with the // custom map type we created, and set the map to // show that map type. map.mapTypes.set(MY_MAPTYPE_ID, myMapType);
স্টাইল করা মানচিত্র
StyledMapType
আপনাকে স্ট্যান্ডার্ড Google বেস ম্যাপের উপস্থাপনা কাস্টমাইজ করতে দেয়, রাস্তা, পার্ক এবং বিল্ট-আপ এলাকার মতো উপাদানগুলির ভিজ্যুয়াল ডিসপ্লে পরিবর্তন করে ডিফল্ট মানচিত্রের ধরণে ব্যবহৃত একটি ভিন্ন শৈলী প্রতিফলিত করতে। StyledMapType
শুধুমাত্র ডিফল্ট roadmap
মানচিত্র প্রকারকে প্রভাবিত করে।
StyledMapType
সম্পর্কে আরও তথ্যের জন্য, এমবেডেড JSON শৈলী ঘোষণার ব্যবহার দেখুন।
কাস্টম মানচিত্র প্রকার
মানচিত্র জাভাস্ক্রিপ্ট API কাস্টম মানচিত্র প্রকারের প্রদর্শন এবং পরিচালনা সমর্থন করে, যা আপনাকে আপনার নিজস্ব মানচিত্র চিত্র বা টাইল ওভারলে বাস্তবায়ন করতে দেয়।
মানচিত্র জাভাস্ক্রিপ্ট API-এর মধ্যে বেশ কিছু সম্ভাব্য মানচিত্র প্রকার বাস্তবায়ন বিদ্যমান:
- স্ট্যান্ডার্ড টাইল সেটে ছবি থাকে যা সম্মিলিতভাবে সম্পূর্ণ কার্টোগ্রাফিক মানচিত্র গঠন করে। এই টাইল সেটগুলি বেস মানচিত্র প্রকার হিসাবেও পরিচিত। এই মানচিত্র প্রকারগুলি বিদ্যমান ডিফল্ট মানচিত্র প্রকারের মতো কাজ করে এবং আচরণ করে:
roadmap
,satellite
,hybrid
এবংterrain
৷ আপনি মানচিত্র জাভাস্ক্রিপ্ট API-এর মধ্যে UI-কে আপনার কাস্টম মানচিত্রের ধরনটিকে একটি আদর্শmapTypes
প্রকারের অ্যারেতে আপনার কাস্টম মানচিত্রের ধরণ যোগ করতে পারেন (উদাহরণস্বরূপ, এটিকে MapType নিয়ন্ত্রণে অন্তর্ভুক্ত করে)। - ইমেজ টাইল ওভারলে যা বিদ্যমান বেস মানচিত্রের প্রকারের উপরে প্রদর্শিত হয়। সাধারণত, এই মানচিত্র প্রকারগুলিকে অতিরিক্ত তথ্য প্রদর্শনের জন্য একটি বিদ্যমান মানচিত্রের ধরন বাড়ানোর জন্য ব্যবহার করা হয় এবং প্রায়শই নির্দিষ্ট অবস্থান এবং/অথবা জুম স্তরে সীমাবদ্ধ থাকে। মনে রাখবেন যে এই টাইলগুলি স্বচ্ছ হতে পারে, যা আপনাকে বিদ্যমান মানচিত্রে বৈশিষ্ট্য যোগ করতে দেয়।
- নন-ইমেজ মানচিত্র প্রকার, যা আপনাকে মানচিত্র তথ্য প্রদর্শনের সবচেয়ে মৌলিক স্তরে ম্যানিপুলেট করতে দেয়।
এই বিকল্পগুলির প্রতিটি একটি ক্লাস তৈরির উপর নির্ভর করে যা MapType
ইন্টারফেস প্রয়োগ করে। অতিরিক্তভাবে, ImageMapType
ক্লাস চিত্রের মানচিত্র প্রকারগুলি তৈরিকে সহজ করার জন্য কিছু অন্তর্নির্মিত আচরণ প্রদান করে।
MapType
ইন্টারফেস
আপনি MapType
প্রয়োগ করে এমন ক্লাস তৈরি করার আগে, Google Maps কীভাবে স্থানাঙ্ক নির্ধারণ করে এবং মানচিত্রের কোন অংশগুলি দেখানো হবে তা নির্ধারণ করে তা বোঝা গুরুত্বপূর্ণ। যেকোন বেস বা ওভারলে মানচিত্র প্রকারের জন্য আপনাকে অনুরূপ যুক্তি প্রয়োগ করতে হবে। মানচিত্র এবং টাইল স্থানাঙ্কের নির্দেশিকা পড়ুন।
কাস্টম মানচিত্রের ধরন অবশ্যই MapType
ইন্টারফেস বাস্তবায়ন করবে। এই ইন্টারফেসটি নির্দিষ্ট বৈশিষ্ট্য এবং পদ্ধতিগুলি নির্দিষ্ট করে যা API-কে আপনার মানচিত্র প্রকার(গুলি) এর অনুরোধগুলি শুরু করার অনুমতি দেয় যখন API নির্ধারণ করে যে এটি বর্তমান ভিউপোর্ট এবং জুম স্তরের মধ্যে মানচিত্রের টাইলগুলি প্রদর্শন করতে হবে৷ কোন টাইল লোড করতে হবে তা নির্ধারণ করতে আপনি এই অনুরোধগুলি পরিচালনা করেন।
দ্রষ্টব্য : আপনি এই ইন্টারফেসটি বাস্তবায়ন করতে আপনার নিজস্ব ক্লাস তৈরি করতে পারেন। বিকল্পভাবে, আপনার যদি সামঞ্জস্যপূর্ণ চিত্র থাকে তবে আপনি ImageMapType
ক্লাস ব্যবহার করতে পারেন যা ইতিমধ্যে এই ইন্টারফেসটি প্রয়োগ করে।
MapType
ইন্টারফেস বাস্তবায়নকারী ক্লাসগুলির জন্য আপনাকে নিম্নলিখিত বৈশিষ্ট্যগুলিকে সংজ্ঞায়িত এবং পপুলেট করতে হবে:
-
tileSize
(প্রয়োজনীয়) টাইলের আকার নির্দিষ্ট করে (google.maps.Size
টাইপ)। আকারগুলি অবশ্যই আয়তক্ষেত্রাকার হতে হবে যদিও সেগুলি বর্গাকার হওয়ার দরকার নেই৷ -
maxZoom
(প্রয়োজনীয়) সর্বাধিক জুম স্তর নির্দিষ্ট করে যেখানে এই মানচিত্র প্রকারের টাইলগুলি প্রদর্শন করতে হবে৷ -
minZoom
(ঐচ্ছিক) ন্যূনতম জুম স্তর নির্দিষ্ট করে যেখানে এই মানচিত্র প্রকারের টাইল প্রদর্শন করতে হবে। ডিফল্টরূপে, এই মানটি0
ইঙ্গিত করে যে কোন ন্যূনতম জুম স্তর বিদ্যমান নেই। -
name
(ঐচ্ছিক) এই মানচিত্রের প্রকারের নাম নির্দিষ্ট করে। এই বৈশিষ্ট্যটি শুধুমাত্র তখনই প্রয়োজনীয় যদি আপনি চান যে এই মানচিত্রের ধরনটি একটি MapType নিয়ন্ত্রণের মধ্যে নির্বাচনযোগ্য। ( নিয়ন্ত্রণ বিকল্প দেখুন।) -
alt
(ঐচ্ছিক) এই মানচিত্র প্রকারের জন্য বিকল্প পাঠ্য নির্দিষ্ট করে, হোভার টেক্সট হিসাবে প্রদর্শিত। এই বৈশিষ্ট্যটি শুধুমাত্র তখনই প্রয়োজনীয় যদি আপনি চান যে এই মানচিত্রের ধরনটি একটি MapType নিয়ন্ত্রণের মধ্যে নির্বাচনযোগ্য। ( নিয়ন্ত্রণ বিকল্প দেখুন।)
উপরন্তু, MapType
ইন্টারফেস বাস্তবায়নকারী ক্লাসগুলিকে নিম্নলিখিত পদ্ধতিগুলি বাস্তবায়ন করতে হবে:
getTile()
(প্রয়োজনীয়) বলা হয় যখনই API নির্ধারণ করে যে মানচিত্রটিকে প্রদত্ত ভিউপোর্টের জন্য নতুন টাইলস প্রদর্শন করতে হবে।getTile()
পদ্ধতিতে নিম্নলিখিত স্বাক্ষর থাকতে হবে:getTile(tileCoord:Point,zoom:number,ownerDocument:Document):Node
MapType
এরtileSize
,minZoom
, এবংmaxZoom
বৈশিষ্ট্য এবং মানচিত্রের বর্তমান ভিউপোর্ট এবং জুম স্তরের উপর ভিত্তি করে এপিআই এটিকেgetTile()
কল করতে হবে কিনা তা নির্ধারণ করে। এই পদ্ধতির জন্য হ্যান্ডলারকে একটি পাস করা স্থানাঙ্ক, জুম স্তর এবং DOM উপাদান দিয়ে একটি HTML উপাদান ফেরত দেওয়া উচিত যাতে টাইল চিত্রটি যুক্ত করতে হয়।releaseTile()
(ঐচ্ছিক) বলা হয় যখনই API নির্ধারণ করে যে মানচিত্রটি একটি টাইল অপসারণ করতে হবে কারণ এটি দৃশ্যের বাইরে পড়ে যায়। এই পদ্ধতিতে নিম্নলিখিত স্বাক্ষর থাকতে হবে:releaseTile(tile:Node)
ম্যাপ যুক্ত করার সময় ম্যাপের টাইলসের সাথে সংযুক্ত যেকোন উপাদানগুলিকে অপসারণ করার জন্য আপনাকে সাধারণত পরিচালনা করতে হবে। উদাহরণস্বরূপ, যদি আপনি ইভেন্ট শ্রোতাদের ম্যাপ টাইল ওভারলেতে সংযুক্ত করেন, তাহলে আপনার সেগুলিকে এখান থেকে সরানো উচিত।
getTile()
পদ্ধতি একটি প্রদত্ত ভিউপোর্টের মধ্যে কোন টাইলগুলি লোড করতে হবে তা নির্ধারণের জন্য প্রধান নিয়ামক হিসাবে কাজ করে।
ভিত্তি মানচিত্র প্রকার
আপনি এই পদ্ধতিতে যে মানচিত্রের প্রকারগুলি তৈরি করেন সেগুলি হয় একা দাঁড়াতে পারে বা ওভারলে হিসাবে অন্যান্য মানচিত্রের প্রকারগুলির সাথে একত্রিত হতে পারে৷ স্বতন্ত্র মানচিত্রের প্রকারগুলি বেস মানচিত্র প্রকার হিসাবে পরিচিত। আপনি এপিআই-এর সাথে এমন কাস্টম MapType
গুলি ব্যবহার করতে চাইতে পারেন যেমন এটি অন্য যেকোন বিদ্যমান বেস মানচিত্র প্রকার ( ROADMAP
, TERRAIN
, ইত্যাদি)। এটি করার জন্য, আপনার কাস্টম MapType
যোগ করুন Map
mapTypes
বৈশিষ্ট্যে। এই সম্পত্তি MapTypeRegistry
ধরনের।
নিম্নলিখিত কোডটি একটি মানচিত্রের টাইল স্থানাঙ্ক প্রদর্শন করতে একটি বেস MapType
তৈরি করে এবং টাইলগুলির একটি রূপরেখা আঁকে:
টাইপস্ক্রিপ্ট
/* * This demo demonstrates how to replace default map tiles with custom imagery. * In this case, the CoordMapType displays gray tiles annotated with the tile * coordinates. * * Try panning and zooming the map to see how the coordinates change. */ class CoordMapType { tileSize: google.maps.Size; maxZoom = 19; name = "Tile #s"; alt = "Tile Coordinate Map Type"; constructor(tileSize: google.maps.Size) { this.tileSize = tileSize; } getTile( coord: google.maps.Point, zoom: number, ownerDocument: Document ): HTMLElement { const div = ownerDocument.createElement("div"); div.innerHTML = String(coord); div.style.width = this.tileSize.width + "px"; div.style.height = this.tileSize.height + "px"; div.style.fontSize = "10"; div.style.borderStyle = "solid"; div.style.borderWidth = "1px"; div.style.borderColor = "#AAAAAA"; div.style.backgroundColor = "#E5E3DF"; return div; } releaseTile(tile: HTMLElement): void {} } function initMap(): void { const map = new google.maps.Map( document.getElementById("map") as HTMLElement, { zoom: 10, center: { lat: 41.85, lng: -87.65 }, streetViewControl: false, mapTypeId: "coordinate", mapTypeControlOptions: { mapTypeIds: ["coordinate", "roadmap"], style: google.maps.MapTypeControlStyle.DROPDOWN_MENU, }, } ); map.addListener("maptypeid_changed", () => { const showStreetViewControl = (map.getMapTypeId() as string) !== "coordinate"; map.setOptions({ streetViewControl: showStreetViewControl, }); }); // Now attach the coordinate map type to the map's registry. map.mapTypes.set( "coordinate", new CoordMapType(new google.maps.Size(256, 256)) ); } declare global { interface Window { initMap: () => void; } } window.initMap = initMap;
জাভাস্ক্রিপ্ট
/* * This demo demonstrates how to replace default map tiles with custom imagery. * In this case, the CoordMapType displays gray tiles annotated with the tile * coordinates. * * Try panning and zooming the map to see how the coordinates change. */ class CoordMapType { tileSize; maxZoom = 19; name = "Tile #s"; alt = "Tile Coordinate Map Type"; constructor(tileSize) { this.tileSize = tileSize; } getTile(coord, zoom, ownerDocument) { const div = ownerDocument.createElement("div"); div.innerHTML = String(coord); div.style.width = this.tileSize.width + "px"; div.style.height = this.tileSize.height + "px"; div.style.fontSize = "10"; div.style.borderStyle = "solid"; div.style.borderWidth = "1px"; div.style.borderColor = "#AAAAAA"; div.style.backgroundColor = "#E5E3DF"; return div; } releaseTile(tile) {} } function initMap() { const map = new google.maps.Map(document.getElementById("map"), { zoom: 10, center: { lat: 41.85, lng: -87.65 }, streetViewControl: false, mapTypeId: "coordinate", mapTypeControlOptions: { mapTypeIds: ["coordinate", "roadmap"], style: google.maps.MapTypeControlStyle.DROPDOWN_MENU, }, }); map.addListener("maptypeid_changed", () => { const showStreetViewControl = map.getMapTypeId() !== "coordinate"; map.setOptions({ streetViewControl: showStreetViewControl, }); }); // Now attach the coordinate map type to the map's registry. map.mapTypes.set( "coordinate", new CoordMapType(new google.maps.Size(256, 256)), ); } window.initMap = initMap;
নমুনা চেষ্টা করুন
ওভারলে মানচিত্র প্রকার
কিছু মানচিত্রের ধরন বিদ্যমান মানচিত্রের প্রকারের উপরে কাজ করার জন্য ডিজাইন করা হয়েছে। এই ধরনের মানচিত্রের প্রকারে স্বচ্ছ স্তর থাকতে পারে যা আগ্রহের পয়েন্টগুলি নির্দেশ করে বা ব্যবহারকারীকে অতিরিক্ত ডেটা দেখায়।
এই ক্ষেত্রে, আপনি মানচিত্রের ধরনটিকে একটি পৃথক সত্তা হিসাবে বিবেচনা না করে একটি ওভারলে হিসাবে চান৷ আপনি সরাসরি Map
এর overlayMapTypes
বৈশিষ্ট্য ব্যবহার করে একটি বিদ্যমান MapType
এ মানচিত্রের প্রকার যোগ করে এটি করতে পারেন। এই সম্পত্তিতে MapType
s-এর একটি MVCArray
রয়েছে৷ সমস্ত মানচিত্র প্রকার (বেস এবং ওভারলে) mapPane
স্তরের মধ্যে রেন্ডার করা হয়। ওভারলে মানচিত্রের প্রকারগুলি তারা সংযুক্ত বেস মানচিত্রের উপরে প্রদর্শিত হবে, যে ক্রমে তারা Map.overlayMapTypes
অ্যারেতে প্রদর্শিত হবে (উচ্চ সূচক মান সহ ওভারলেগুলি নিম্ন সূচক মান সহ ওভারলেগুলির সামনে প্রদর্শিত হয়)।
নিম্নলিখিত উদাহরণটি পূর্ববর্তীটির সাথে অভিন্ন ব্যতীত যে আমরা ROADMAP
মানচিত্রের প্রকারের উপরে একটি টাইল ওভারলে MapType
তৈরি করেছি:
টাইপস্ক্রিপ্ট
/* * This demo illustrates the coordinate system used to display map tiles in the * API. * * Tiles in Google Maps are numbered from the same origin as that for * pixels. For Google's implementation of the Mercator projection, the origin * tile is always at the northwest corner of the map, with x values increasing * from west to east and y values increasing from north to south. * * Try panning and zooming the map to see how the coordinates change. */ class CoordMapType implements google.maps.MapType { tileSize: google.maps.Size; alt: string|null = null; maxZoom: number = 17; minZoom: number = 0; name: string|null = null; projection: google.maps.Projection|null = null; radius: number = 6378137; constructor(tileSize: google.maps.Size) { this.tileSize = tileSize; } getTile( coord: google.maps.Point, zoom: number, ownerDocument: Document ): HTMLElement { const div = ownerDocument.createElement("div"); div.innerHTML = String(coord); div.style.width = this.tileSize.width + "px"; div.style.height = this.tileSize.height + "px"; div.style.fontSize = "10"; div.style.borderStyle = "solid"; div.style.borderWidth = "1px"; div.style.borderColor = "#AAAAAA"; return div; } releaseTile(tile: Element): void {} } function initMap(): void { const map = new google.maps.Map( document.getElementById("map") as HTMLElement, { zoom: 10, center: { lat: 41.85, lng: -87.65 }, } ); // Insert this overlay map type as the first overlay map type at // position 0. Note that all overlay map types appear on top of // their parent base map. const coordMapType = new CoordMapType(new google.maps.Size(256, 256)) map.overlayMapTypes.insertAt( 0, coordMapType ); } declare global { interface Window { initMap: () => void; } } window.initMap = initMap;
জাভাস্ক্রিপ্ট
/* * This demo illustrates the coordinate system used to display map tiles in the * API. * * Tiles in Google Maps are numbered from the same origin as that for * pixels. For Google's implementation of the Mercator projection, the origin * tile is always at the northwest corner of the map, with x values increasing * from west to east and y values increasing from north to south. * * Try panning and zooming the map to see how the coordinates change. */ class CoordMapType { tileSize; alt = null; maxZoom = 17; minZoom = 0; name = null; projection = null; radius = 6378137; constructor(tileSize) { this.tileSize = tileSize; } getTile(coord, zoom, ownerDocument) { const div = ownerDocument.createElement("div"); div.innerHTML = String(coord); div.style.width = this.tileSize.width + "px"; div.style.height = this.tileSize.height + "px"; div.style.fontSize = "10"; div.style.borderStyle = "solid"; div.style.borderWidth = "1px"; div.style.borderColor = "#AAAAAA"; return div; } releaseTile(tile) {} } function initMap() { const map = new google.maps.Map(document.getElementById("map"), { zoom: 10, center: { lat: 41.85, lng: -87.65 }, }); // Insert this overlay map type as the first overlay map type at // position 0. Note that all overlay map types appear on top of // their parent base map. const coordMapType = new CoordMapType(new google.maps.Size(256, 256)); map.overlayMapTypes.insertAt(0, coordMapType); } window.initMap = initMap;
নমুনা চেষ্টা করুন
চিত্র মানচিত্র প্রকার
একটি বেস ম্যাপ টাইপ হিসাবে কাজ করার জন্য একটি MapType
বাস্তবায়ন করা একটি সময়সাপেক্ষ এবং শ্রমসাধ্য কাজ হতে পারে। API একটি বিশেষ শ্রেণী প্রদান করে যা সবচেয়ে সাধারণ মানচিত্র প্রকারের জন্য MapType
ইন্টারফেস প্রয়োগ করে: মানচিত্রের ধরন যা একক ইমেজ ফাইল দিয়ে তৈরি টাইলস নিয়ে গঠিত।
এই ক্লাস, ImageMapType
ক্লাস, নিম্নলিখিত প্রয়োজনীয় বৈশিষ্ট্যগুলিকে সংজ্ঞায়িত করে একটি ImageMapTypeOptions
অবজেক্ট স্পেসিফিকেশন ব্যবহার করে তৈরি করা হয়েছে:
-
tileSize
(প্রয়োজনীয়) টাইলের আকার নির্দিষ্ট করে (google.maps.Size
টাইপ)। আকারগুলি অবশ্যই আয়তক্ষেত্রাকার হতে হবে যদিও সেগুলি বর্গাকার হওয়ার দরকার নেই৷ -
getTileUrl
(প্রয়োজনীয়) ফাংশনটি নির্দিষ্ট করে, সাধারণত একটি ইনলাইন ফাংশন আক্ষরিক হিসাবে সরবরাহ করা হয়, সরবরাহ করা বিশ্ব স্থানাঙ্ক এবং জুম স্তরের উপর ভিত্তি করে সঠিক চিত্র টাইলের নির্বাচন পরিচালনা করতে।
নিম্নলিখিত কোডটি Google এর চাঁদের টাইলস ব্যবহার করে একটি মৌলিক ImageMapType
প্রয়োগ করে৷ উদাহরণটি একটি স্বাভাবিককরণ ফাংশন ব্যবহার করে তা নিশ্চিত করতে যে টাইলসগুলি x-অক্ষ বরাবর পুনরাবৃত্তি হয়, কিন্তু আপনার মানচিত্রের y-অক্ষ বরাবর নয়।
টাইপস্ক্রিপ্ট
function initMap(): void { const map = new google.maps.Map( document.getElementById("map") as HTMLElement, { center: { lat: 0, lng: 0 }, zoom: 1, streetViewControl: false, mapTypeControlOptions: { mapTypeIds: ["moon"], }, } ); const moonMapType = new google.maps.ImageMapType({ getTileUrl: function (coord, zoom): string { const normalizedCoord = getNormalizedCoord(coord, zoom); if (!normalizedCoord) { return ""; } const bound = Math.pow(2, zoom); return ( "https://mw1.google.com/mw-planetary/lunar/lunarmaps_v1/clem_bw" + "/" + zoom + "/" + normalizedCoord.x + "/" + (bound - normalizedCoord.y - 1) + ".jpg" ); }, tileSize: new google.maps.Size(256, 256), maxZoom: 9, minZoom: 0, // @ts-ignore TODO 'radius' does not exist in type 'ImageMapTypeOptions' radius: 1738000, name: "Moon", }); map.mapTypes.set("moon", moonMapType); map.setMapTypeId("moon"); } // Normalizes the coords that tiles repeat across the x axis (horizontally) // like the standard Google map tiles. function getNormalizedCoord(coord, zoom) { const y = coord.y; let x = coord.x; // tile range in one direction range is dependent on zoom level // 0 = 1 tile, 1 = 2 tiles, 2 = 4 tiles, 3 = 8 tiles, etc const tileRange = 1 << zoom; // don't repeat across y-axis (vertically) if (y < 0 || y >= tileRange) { return null; } // repeat across x-axis if (x < 0 || x >= tileRange) { x = ((x % tileRange) + tileRange) % tileRange; } return { x: x, y: y }; } declare global { interface Window { initMap: () => void; } } window.initMap = initMap;
জাভাস্ক্রিপ্ট
function initMap() { const map = new google.maps.Map(document.getElementById("map"), { center: { lat: 0, lng: 0 }, zoom: 1, streetViewControl: false, mapTypeControlOptions: { mapTypeIds: ["moon"], }, }); const moonMapType = new google.maps.ImageMapType({ getTileUrl: function (coord, zoom) { const normalizedCoord = getNormalizedCoord(coord, zoom); if (!normalizedCoord) { return ""; } const bound = Math.pow(2, zoom); return ( "https://mw1.google.com/mw-planetary/lunar/lunarmaps_v1/clem_bw" + "/" + zoom + "/" + normalizedCoord.x + "/" + (bound - normalizedCoord.y - 1) + ".jpg" ); }, tileSize: new google.maps.Size(256, 256), maxZoom: 9, minZoom: 0, // @ts-ignore TODO 'radius' does not exist in type 'ImageMapTypeOptions' radius: 1738000, name: "Moon", }); map.mapTypes.set("moon", moonMapType); map.setMapTypeId("moon"); } // Normalizes the coords that tiles repeat across the x axis (horizontally) // like the standard Google map tiles. function getNormalizedCoord(coord, zoom) { const y = coord.y; let x = coord.x; // tile range in one direction range is dependent on zoom level // 0 = 1 tile, 1 = 2 tiles, 2 = 4 tiles, 3 = 8 tiles, etc const tileRange = 1 << zoom; // don't repeat across y-axis (vertically) if (y < 0 || y >= tileRange) { return null; } // repeat across x-axis if (x < 0 || x >= tileRange) { x = ((x % tileRange) + tileRange) % tileRange; } return { x: x, y: y }; } window.initMap = initMap;
নমুনা চেষ্টা করুন
অনুমান
পৃথিবী একটি ত্রিমাত্রিক গোলক (প্রায়), যখন একটি মানচিত্র একটি সমতল দ্বি-মাত্রিক পৃষ্ঠ। আপনি মানচিত্রের জাভাস্ক্রিপ্ট API-এর মধ্যে যে মানচিত্রটি দেখতে পান, পৃথিবীর যেকোনো সমতল মানচিত্রের মতো, এটি একটি সমতল পৃষ্ঠের উপর সেই গোলকের একটি অভিক্ষেপ । এর সহজ শর্তে, একটি অভিক্ষেপকে অভিক্ষেপের মানচিত্রে স্থানাঙ্কে অক্ষাংশ/দ্রাঘিমাংশের মানগুলির ম্যাপিং হিসাবে সংজ্ঞায়িত করা যেতে পারে।
মানচিত্র জাভাস্ক্রিপ্ট এপিআই-এ প্রজেকশনগুলি অবশ্যই Projection
ইন্টারফেস বাস্তবায়ন করবে। একটি Projection
বাস্তবায়ন অবশ্যই একটি স্থানাঙ্ক সিস্টেম থেকে অন্য একটি ম্যাপিং প্রদান করবে না, তবে একটি দ্বি-নির্দেশিক ম্যাপিং প্রদান করবে। অর্থাৎ, আপনাকে অবশ্যই নির্ধারণ করতে হবে কিভাবে আর্থ কোঅর্ডিনেট ( LatLng
অবজেক্ট) থেকে Projection
ক্লাসের ওয়ার্ল্ড কোঅর্ডিনেট সিস্টেমে এবং ওয়ার্ল্ড কোঅর্ডিনেট সিস্টেম থেকে আবার আর্থ কোঅর্ডিনেটে অনুবাদ করতে হবে। Google Maps ভৌগলিক ডেটা থেকে এর মানচিত্র তৈরি করতে এবং মানচিত্রের ইভেন্টগুলিকে ভৌগলিক স্থানাঙ্কে রূপান্তর করতে Mercator প্রজেকশন ব্যবহার করে। আপনি Map
(অথবা স্ট্যান্ডার্ড বেস MapType
প্রকারের যেকোনো একটি getProjection()
কল করে এই প্রজেকশনটি পেতে পারেন, বেশিরভাগ ব্যবহারের জন্য, এই স্ট্যান্ডার্ড Projection
যথেষ্ট হবে, তবে আপনি আপনার নিজস্ব কাস্টম প্রজেকশনও সংজ্ঞায়িত করতে এবং ব্যবহার করতে পারেন।
একটি অভিক্ষেপ বাস্তবায়ন
একটি কাস্টম প্রজেকশন বাস্তবায়ন করার সময়, আপনাকে কয়েকটি জিনিস সংজ্ঞায়িত করতে হবে:
- ম্যাপিং অক্ষাংশ এবং দ্রাঘিমাংশের জন্য সূত্রগুলি একটি কার্টেসিয়ান সমতলে এবং একটি কার্টেসিয়ান সমতল থেকে অক্ষাংশ এবং দ্রাঘিমাংশ স্থানাঙ্কে ম্যাপিংয়ের জন্য সংশ্লিষ্ট সূত্রগুলি। (
Projection
ইন্টারফেস শুধুমাত্র রেক্টিলাইনার কোঅর্ডিনেটে রূপান্তরকে সমর্থন করে।) - বেস টালি আকার. All tiles must be rectangular.
- The "world size" of a map using the base tile set at zoom level 0. Note that for maps consisting of one tile at zoom 0, the world size and base tile size are identical.
Coordinate Transformations in Projections
Each projection provides two methods which translate between these two coordinate systems, allowing you to convert between geographic and world coordinates:
- The
Projection.fromLatLngToPoint()
method converts aLatLng
value into a world coordinate. This method is used to position overlays on the map (and to position the map itself). - The
Projection.fromPointToLatLng()
method converts a world coordinate into aLatLng
value. This method is used to convert events such as clicks that happen on the map into geographic coordinates.
Google Maps assumes that projections are rectilinear.
Generally, you may use a projection for two cases: to create a map of the world, or to create a map of a local area. In the former case, you should ensure that your projection is also rectilinear and normal at all longitudes. Some projections (especially conic projections) may be "locally normal" (ie point north) but deviate from true north; for example, the further the map is positioned relative to some reference longitude. You may use such a projection locally, but be aware that the projection is necessarily imprecise and transformation errors will become increasingly apparently the further away from the reference longitude you deviate.
Map Tile Selection in Projections
Projections are not only useful for determining the positions of locations or overlays, but for positioning the map tiles themselves. The Maps JavaScript API renders base maps using a MapType
interface, which must declare both a projection
property for identifying the map's projection and a getTile()
method for retrieving map tiles based on tile coordinate values. Tile coordinates are based on both your basic tile size (which must be rectangular) and the "world size" of your map, which is the pixel size of your map world at zoom level 0. (For maps consisting of one tile at zoom 0, the tile size and world size are identical.)
You define the base tile size within your MapType
's tileSize
property. You define the world size implicitly within your projection's fromLatLngToPoint()
and fromPointToLatLng()
methods.
Since image selection depends on these passed values, it is useful to name images that can be selected programmatically given those passed values, such as map _ zoom _ tileX _ tileY .png
.
The following example defines an ImageMapType
using the Gall-Peters projection:
টাইপস্ক্রিপ্ট
// This example defines an image map type using the Gall-Peters // projection. // https://en.wikipedia.org/wiki/Gall%E2%80%93Peters_projection const mapElement = document.querySelector("gmp-map") as google.maps.MapElement; let innerMap; async function initMap() { // Request the needed libraries. await google.maps.importLibrary("maps"); // Create a map. innerMap = mapElement.innerMap; innerMap.setOptions({ mapTypeControl: false, }); // Set the Gall-Peters map type. initGallPeters(); innerMap.mapTypes.set("gallPeters", gallPetersMapType); innerMap.setMapTypeId("gallPeters"); // Show the lat and lng under the mouse cursor. const coordsDiv = document.getElementById("coords") as HTMLElement; innerMap.addListener("mousemove", (event: google.maps.MapMouseEvent) => { coordsDiv.textContent = "lat: " + Math.round(event.latLng!.lat()) + ", " + "lng: " + Math.round(event.latLng!.lng()); }); // Add some markers to the map. innerMap.data.setStyle((feature) => { return { title: feature.getProperty("name") as string, optimized: false, }; }); innerMap.data.addGeoJson(cities); } let gallPetersMapType; function initGallPeters() { const GALL_PETERS_RANGE_X = 800; const GALL_PETERS_RANGE_Y = 512; // Fetch Gall-Peters tiles stored locally on our server. gallPetersMapType = new google.maps.ImageMapType({ getTileUrl: function (coord, zoom) { const scale = 1 << zoom; // Wrap tiles horizontally. const x = ((coord.x % scale) + scale) % scale; // Don't wrap tiles vertically. const y = coord.y; if (y < 0 || y >= scale) return ""; return ( "gall-peters_" + zoom + "_" + x + "_" + y + ".png" ); }, tileSize: new google.maps.Size(GALL_PETERS_RANGE_X, GALL_PETERS_RANGE_Y), minZoom: 0, maxZoom: 1, name: "Gall-Peters", }); // Describe the Gall-Peters projection used by these tiles. gallPetersMapType.projection = { fromLatLngToPoint: function (latLng) { const latRadians = (latLng.lat() * Math.PI) / 180; return new google.maps.Point( GALL_PETERS_RANGE_X * (0.5 + latLng.lng() / 360), GALL_PETERS_RANGE_Y * (0.5 - 0.5 * Math.sin(latRadians)) ); }, fromPointToLatLng: function (point, noWrap) { const x = point.x / GALL_PETERS_RANGE_X; const y = Math.max(0, Math.min(1, point.y / GALL_PETERS_RANGE_Y)); return new google.maps.LatLng( (Math.asin(1 - 2 * y) * 180) / Math.PI, -180 + 360 * x, noWrap ); }, }; } // GeoJSON, describing the locations and names of some cities. const cities = { type: "FeatureCollection", features: [ { type: "Feature", geometry: { type: "Point", coordinates: [-87.65, 41.85] }, properties: { name: "Chicago" }, }, { type: "Feature", geometry: { type: "Point", coordinates: [-149.9, 61.218] }, properties: { name: "Anchorage" }, }, { type: "Feature", geometry: { type: "Point", coordinates: [-99.127, 19.427] }, properties: { name: "Mexico City" }, }, { type: "Feature", geometry: { type: "Point", coordinates: [-0.126, 51.5] }, properties: { name: "London" }, }, { type: "Feature", geometry: { type: "Point", coordinates: [28.045, -26.201] }, properties: { name: "Johannesburg" }, }, { type: "Feature", geometry: { type: "Point", coordinates: [15.322, -4.325] }, properties: { name: "Kinshasa" }, }, { type: "Feature", geometry: { type: "Point", coordinates: [151.207, -33.867] }, properties: { name: "Sydney" }, }, { type: "Feature", geometry: { type: "Point", coordinates: [0, 0] }, properties: { name: "0°N 0°E" }, }, ], }; initMap();
জাভাস্ক্রিপ্ট
// This example defines an image map type using the Gall-Peters // projection. // https://en.wikipedia.org/wiki/Gall%E2%80%93Peters_projection const mapElement = document.querySelector("gmp-map"); let innerMap; async function initMap() { // Request the needed libraries. await google.maps.importLibrary("maps"); // Create a map. innerMap = mapElement.innerMap; innerMap.setOptions({ mapTypeControl: false, }); // Set the Gall-Peters map type. initGallPeters(); innerMap.mapTypes.set("gallPeters", gallPetersMapType); innerMap.setMapTypeId("gallPeters"); // Show the lat and lng under the mouse cursor. const coordsDiv = document.getElementById("coords"); innerMap.addListener("mousemove", (event) => { coordsDiv.textContent = "lat: " + Math.round(event.latLng.lat()) + ", " + "lng: " + Math.round(event.latLng.lng()); }); // Add some markers to the map. innerMap.data.setStyle((feature) => { return { title: feature.getProperty("name"), optimized: false, }; }); innerMap.data.addGeoJson(cities); } let gallPetersMapType; function initGallPeters() { const GALL_PETERS_RANGE_X = 800; const GALL_PETERS_RANGE_Y = 512; // Fetch Gall-Peters tiles stored locally on our server. gallPetersMapType = new google.maps.ImageMapType({ getTileUrl: function (coord, zoom) { const scale = 1 << zoom; // Wrap tiles horizontally. const x = ((coord.x % scale) + scale) % scale; // Don't wrap tiles vertically. const y = coord.y; if (y < 0 || y >= scale) return ""; return ("gall-peters_" + zoom + "_" + x + "_" + y + ".png"); }, tileSize: new google.maps.Size(GALL_PETERS_RANGE_X, GALL_PETERS_RANGE_Y), minZoom: 0, maxZoom: 1, name: "Gall-Peters", }); // Describe the Gall-Peters projection used by these tiles. gallPetersMapType.projection = { fromLatLngToPoint: function (latLng) { const latRadians = (latLng.lat() * Math.PI) / 180; return new google.maps.Point(GALL_PETERS_RANGE_X * (0.5 + latLng.lng() / 360), GALL_PETERS_RANGE_Y * (0.5 - 0.5 * Math.sin(latRadians))); }, fromPointToLatLng: function (point, noWrap) { const x = point.x / GALL_PETERS_RANGE_X; const y = Math.max(0, Math.min(1, point.y / GALL_PETERS_RANGE_Y)); return new google.maps.LatLng((Math.asin(1 - 2 * y) * 180) / Math.PI, -180 + 360 * x, noWrap); }, }; } // GeoJSON, describing the locations and names of some cities. const cities = { type: "FeatureCollection", features: [ { type: "Feature", geometry: { type: "Point", coordinates: [-87.65, 41.85] }, properties: { name: "Chicago" }, }, { type: "Feature", geometry: { type: "Point", coordinates: [-149.9, 61.218] }, properties: { name: "Anchorage" }, }, { type: "Feature", geometry: { type: "Point", coordinates: [-99.127, 19.427] }, properties: { name: "Mexico City" }, }, { type: "Feature", geometry: { type: "Point", coordinates: [-0.126, 51.5] }, properties: { name: "London" }, }, { type: "Feature", geometry: { type: "Point", coordinates: [28.045, -26.201] }, properties: { name: "Johannesburg" }, }, { type: "Feature", geometry: { type: "Point", coordinates: [15.322, -4.325] }, properties: { name: "Kinshasa" }, }, { type: "Feature", geometry: { type: "Point", coordinates: [151.207, -33.867] }, properties: { name: "Sydney" }, }, { type: "Feature", geometry: { type: "Point", coordinates: [0, 0] }, properties: { name: "0°N 0°E" }, }, ], }; initMap();
নমুনা চেষ্টা করুন
This document discusses the types of maps you can display using the Maps JavaScript API. The API uses a MapType
object to hold information about these maps. A MapType
is an interface that defines the display and usage of map tiles and the translation of coordinate systems from screen coordinates to world coordinates (on the map). Each MapType
must contain a few methods to handle retrieval and release of tiles, and properties that define its visual behavior.
The inner workings of map types within the Maps JavaScript API is an advanced topic. Most developers can use the basic map types noted below. However, you can also modify the presentation of existing map types using Styled Maps or define your own map tiles using custom map types . When providing custom map types, you will need to understand how to modify the map's Map Type Registry .
মৌলিক মানচিত্র প্রকার
There are four types of maps available within the Maps JavaScript API. In addition to the familiar "painted" road map tiles, the Maps JavaScript API also supports other maps types.
The following map types are available in the Maps JavaScript API:
-
roadmap
displays the default road map view. This is the default map type. -
satellite
displays Google Earth satellite images. -
hybrid
displays a mixture of normal and satellite views. -
terrain
displays a physical map based on terrain information.
You modify the map type in use by the Map
by setting its mapTypeId
property, either within the constructor by setting its Map options
object, or by calling the map's setMapTypeId()
method. The mapTypeID
property defaults to roadmap
.
Setting the mapTypeId
upon construction:
var myLatlng = new google.maps.LatLng(-34.397, 150.644); var mapOptions = { zoom: 8, center: myLatlng, mapTypeId: 'satellite' }; var map = new google.maps.Map(document.getElementById('map'), mapOptions);
Modifying the mapTypeId
dynamically:
map.setMapTypeId('terrain');
Note that you don't actually set the map's map type directly, but instead set its mapTypeId
to reference a MapType
using an identifier. The Maps JavaScript API uses a map type registry, explained below, to manage these references.
45° চিত্র
The Maps JavaScript API supports special 45° imagery for certain locations. This high-resolution imagery provides perspective views towards each of the cardinal direction (North, South, East, West). These images are available at higher zoom levels for supported map types.
The following image shows a 45° perspective view of New York City:
The satellite
and hybrid
map types support 45° imagery at high zoom levels (12 and greater) where available. If the user zooms into a location for which such imagery exists, these map types automatically alter their views in the following manner:
- The satellite or hybrid imagery is replaced with imagery giving a 45° perspective, centered on the current location. By default, such views are oriented towards north. If the user zooms out, the default satellite or hybrid imagery appears again. The behavior varies depending on zoom level and the value of
tilt
: - Between zoom levels 12 and 18 the top-down basemap (0°) displays by default unless
tilt
is set to 45. - At zoom levels of 18 or greater the 45° basemap displays unless
tilt
is set to 0. - The rotate control becomes visible. The rotate control provides options that enable the user to toggle tilt, and to rotate the view in 90° increments in either direction. To hide the rotate control, set
rotateControl
tofalse
.
Zooming out from a map type displaying 45° imagery reverts each of these changes, re-establishing the original map types.
Enable and Disable 45° Imagery
You can disable 45° imagery by calling setTilt(0)
on the Map
object. To enable 45° imagery for supported map types, call setTilt(45)
. The Map
's getTilt()
method will always reflect the current tilt
being shown on the map; if you set a tilt
on a map and then later remove that tilt
(by zooming the map out, for example), the map's getTilt()
method will return 0
.
Important: 45° imagery is only supported on raster maps; this imagery cannot be used with vector maps.
The following example displays a 45° view of New York City:
টাইপস্ক্রিপ্ট
function initMap(): void { const map = new google.maps.Map( document.getElementById("map") as HTMLElement, { center: { lat: 40.76, lng: -73.983 }, zoom: 15, mapTypeId: "satellite", } ); map.setTilt(45); } declare global { interface Window { initMap: () => void; } } window.initMap = initMap;
জাভাস্ক্রিপ্ট
function initMap() { const map = new google.maps.Map(document.getElementById("map"), { center: { lat: 40.76, lng: -73.983 }, zoom: 15, mapTypeId: "satellite", }); map.setTilt(45); } window.initMap = initMap;
নমুনা চেষ্টা করুন
Rotate 45° Imagery
The 45° imagery actually consists of a collection of images for each cardinal direction (North, South, East, West). Once your map is displaying 45° imagery, you can orient the imagery towards one of its cardinal directions by calling setHeading()
on the Map
object, passing a number value expressed as degrees from North.
The following example shows an aerial map and auto-rotates the map every 3 seconds when the button is clicked:
টাইপস্ক্রিপ্ট
let map: google.maps.Map; function initMap(): void { map = new google.maps.Map(document.getElementById("map") as HTMLElement, { center: { lat: 40.76, lng: -73.983 }, zoom: 15, mapTypeId: "satellite", heading: 90, tilt: 45, }); // add listener to button document.getElementById("rotate")!.addEventListener("click", autoRotate); } function rotate90(): void { const heading = map.getHeading() || 0; map.setHeading(heading + 90); } function autoRotate(): void { // Determine if we're showing aerial imagery. if (map.getTilt() !== 0) { window.setInterval(rotate90, 3000); } } declare global { interface Window { initMap: () => void; } } window.initMap = initMap;
জাভাস্ক্রিপ্ট
let map; function initMap() { map = new google.maps.Map(document.getElementById("map"), { center: { lat: 40.76, lng: -73.983 }, zoom: 15, mapTypeId: "satellite", heading: 90, tilt: 45, }); // add listener to button document.getElementById("rotate").addEventListener("click", autoRotate); } function rotate90() { const heading = map.getHeading() || 0; map.setHeading(heading + 90); } function autoRotate() { // Determine if we're showing aerial imagery. if (map.getTilt() !== 0) { window.setInterval(rotate90, 3000); } } window.initMap = initMap;
নমুনা চেষ্টা করুন
Modify the Map Type Registry
A map's mapTypeId
is a string identifier that is used to associate a MapType
with a unique value. Each Map
object maintains a MapTypeRegistry
which contains the collection of available MapType
s for that map. This registry is used to select the types of maps which are available in the Map's MapType control, for example.
You don't read directly from the map type registry. Instead, you modify the registry by adding custom map types and associating them with a string identifier of your choosing. You cannot modify or alter the basic map types (though you can remove them from the map by altering the appearance of the map's associated mapTypeControlOptions
).
The following code sets the map to show only two map types in the map's mapTypeControlOptions
and modifies the registry to add the association with this identifier to the actual implementation of the MapType
interface.
// Modify the control to only display two maptypes, the // default ROADMAP and the custom 'mymap'. // Note that because this is an association, we // don't need to modify the MapTypeRegistry beforehand. var MY_MAPTYPE_ID = 'mymaps'; var mapOptions = { zoom: 12, center: brooklyn, mapTypeControlOptions: { mapTypeIds: ['roadmap', MY_MAPTYPE_ID] }, mapTypeId: MY_MAPTYPE_ID }; // Create our map. This creation will implicitly create a // map type registry. map = new google.maps.Map(document.getElementById('map'), mapOptions); // Create your custom map type using your own code. // (See below.) var myMapType = new MyMapType(); // Set the registry to associate 'mymap' with the // custom map type we created, and set the map to // show that map type. map.mapTypes.set(MY_MAPTYPE_ID, myMapType);
Styled Maps
StyledMapType
আপনাকে স্ট্যান্ডার্ড Google বেস ম্যাপের উপস্থাপনা কাস্টমাইজ করতে দেয়, রাস্তা, পার্ক এবং বিল্ট-আপ এলাকার মতো উপাদানগুলির ভিজ্যুয়াল ডিসপ্লে পরিবর্তন করে ডিফল্ট মানচিত্রের ধরণে ব্যবহৃত একটি ভিন্ন শৈলী প্রতিফলিত করতে। StyledMapType
শুধুমাত্র ডিফল্ট roadmap
মানচিত্র প্রকারকে প্রভাবিত করে।
For more information about the StyledMapType
, see Using embedded JSON style declarations .
Custom Map Types
The Maps JavaScript API supports the display and management of custom map types, allowing you to implement your own map imagery or tile overlays.
Several possible map type implementations exist within the Maps JavaScript API:
- Standard tile sets consisting of images which collectively constitute full cartographic maps. These tile sets are also known as base map types. These map types act and behave like the existing default map types:
roadmap
,satellite
,hybrid
andterrain
. You can add your custom map type to a Map'smapTypes
array to allow the UI within the Maps JavaScript API to treat your custom map type as a standard map type (by including it in the MapType control, for example). - Image tile overlays which display on top of existing base map types. Generally, these map types are used to augment an existing map type to display additional information and are often constrained to specific locations and/or zoom levels. Note that these tiles may be transparent, allowing you to add features to existing maps.
- Non-image map types, which allow you to manipulate the display of map information at its most fundamental level.
Each of these options relies on creating a class that implements the MapType
interface. Additionally, the ImageMapType
class provides some built-in behavior to simplify the creation of imagery map types.
The MapType
Interface
Before you create classes which implement MapType
, it is important to understand how Google Maps determines coordinates and decides which parts of the map to show. You need to implement similar logic for any base or overlay map types. Read the guide to map and tile coordinates .
Custom map types must implement the MapType
interface. This interface specifies certain properties and methods that allow the API to initiate requests to your map type(s) when the API determines that it needs to display map tiles within the current viewport and zoom level. You handle these requests to decide which tile to load.
Note : You may create your own class to implement this interface. Alternatively, if you have compatible imagery you can use the ImageMapType
class which already implements this interface.
Classes implementing the MapType
interface require that you define and populate the following properties:
-
tileSize
(required) specifies the size of the tile (of typegoogle.maps.Size
). Sizes must be rectangular though they need not be square. -
maxZoom
(required) specifies the maximum zoom level at which to display tiles of this map type. -
minZoom
(optional) specifies the minimum zoom level at which to display tile of this map type. By default, this value is0
indicating that no minimum zoom level exists. -
name
(optional) specifies the name for this map type. This property is only necessary if you want this map type to be selectable within a MapType control. (See Control Options .) -
alt
(optional) specifies the alternate text for this map type, exhibited as hover text. This property is only necessary if you want this map type to be selectable within a MapType control. (See Control Options .)
Additionally, classes implementing the MapType
interface need to implement the following methods:
getTile()
(required) is called whenever the API determines that the map needs to display new tiles for the given viewport. ThegetTile()
method must have the following signature:getTile(tileCoord:Point,zoom:number,ownerDocument:Document):Node
The API determines whether it needs to call
getTile()
based on theMapType
'stileSize
,minZoom
, andmaxZoom
properties and the map's current viewport and zoom level. The handler for this method should return an HTML element given a passed coordinate, zoom level, and DOM element on which to append the tile image.releaseTile()
(optional) is called whenever the API determines that the map needs to remove a tile as it falls out of view. This method must have the following signature:releaseTile(tile:Node)
You typically should handle removal of any elements that were attached to the map tiles upon addition to the map. For example, if you attached event listeners to map tile overlays, you should remove them here.
The getTile()
method acts as the main controller for determining which tiles to load within a given viewport.
Base Map Types
Map types which you construct in this manner may either stand alone or be combined with other map types as overlays. Standalone map types are known as base map types . You may want to have the API treat such custom MapType
s as it would any other existing base map type ( ROADMAP
, TERRAIN
, etc.). To do so, add your custom MapType
to the Map
's mapTypes
property. This property is of type MapTypeRegistry
.
The following code creates a base MapType
to display a map's tile coordinates and draws an outline of the tiles:
টাইপস্ক্রিপ্ট
/* * This demo demonstrates how to replace default map tiles with custom imagery. * In this case, the CoordMapType displays gray tiles annotated with the tile * coordinates. * * Try panning and zooming the map to see how the coordinates change. */ class CoordMapType { tileSize: google.maps.Size; maxZoom = 19; name = "Tile #s"; alt = "Tile Coordinate Map Type"; constructor(tileSize: google.maps.Size) { this.tileSize = tileSize; } getTile( coord: google.maps.Point, zoom: number, ownerDocument: Document ): HTMLElement { const div = ownerDocument.createElement("div"); div.innerHTML = String(coord); div.style.width = this.tileSize.width + "px"; div.style.height = this.tileSize.height + "px"; div.style.fontSize = "10"; div.style.borderStyle = "solid"; div.style.borderWidth = "1px"; div.style.borderColor = "#AAAAAA"; div.style.backgroundColor = "#E5E3DF"; return div; } releaseTile(tile: HTMLElement): void {} } function initMap(): void { const map = new google.maps.Map( document.getElementById("map") as HTMLElement, { zoom: 10, center: { lat: 41.85, lng: -87.65 }, streetViewControl: false, mapTypeId: "coordinate", mapTypeControlOptions: { mapTypeIds: ["coordinate", "roadmap"], style: google.maps.MapTypeControlStyle.DROPDOWN_MENU, }, } ); map.addListener("maptypeid_changed", () => { const showStreetViewControl = (map.getMapTypeId() as string) !== "coordinate"; map.setOptions({ streetViewControl: showStreetViewControl, }); }); // Now attach the coordinate map type to the map's registry. map.mapTypes.set( "coordinate", new CoordMapType(new google.maps.Size(256, 256)) ); } declare global { interface Window { initMap: () => void; } } window.initMap = initMap;
জাভাস্ক্রিপ্ট
/* * This demo demonstrates how to replace default map tiles with custom imagery. * In this case, the CoordMapType displays gray tiles annotated with the tile * coordinates. * * Try panning and zooming the map to see how the coordinates change. */ class CoordMapType { tileSize; maxZoom = 19; name = "Tile #s"; alt = "Tile Coordinate Map Type"; constructor(tileSize) { this.tileSize = tileSize; } getTile(coord, zoom, ownerDocument) { const div = ownerDocument.createElement("div"); div.innerHTML = String(coord); div.style.width = this.tileSize.width + "px"; div.style.height = this.tileSize.height + "px"; div.style.fontSize = "10"; div.style.borderStyle = "solid"; div.style.borderWidth = "1px"; div.style.borderColor = "#AAAAAA"; div.style.backgroundColor = "#E5E3DF"; return div; } releaseTile(tile) {} } function initMap() { const map = new google.maps.Map(document.getElementById("map"), { zoom: 10, center: { lat: 41.85, lng: -87.65 }, streetViewControl: false, mapTypeId: "coordinate", mapTypeControlOptions: { mapTypeIds: ["coordinate", "roadmap"], style: google.maps.MapTypeControlStyle.DROPDOWN_MENU, }, }); map.addListener("maptypeid_changed", () => { const showStreetViewControl = map.getMapTypeId() !== "coordinate"; map.setOptions({ streetViewControl: showStreetViewControl, }); }); // Now attach the coordinate map type to the map's registry. map.mapTypes.set( "coordinate", new CoordMapType(new google.maps.Size(256, 256)), ); } window.initMap = initMap;
নমুনা চেষ্টা করুন
ওভারলে মানচিত্র প্রকার
Some map types are designed to work on top of existing map types. Such map types may have transparent layers indicating points of interest, or showing additional data to the user.
In these cases, you do not want the map type treated as a separate entity but as an overlay. You can do this by adding the map type to an existing MapType
directly using the Map
's overlayMapTypes
property. This property contains an MVCArray
of MapType
s. All map types (base and overlay) are rendered within the mapPane
layer. Overlay map types will display on top of the base map they are attached to, in the order in which they appear in the Map.overlayMapTypes
array (overlays with higher index values are displayed in front of overlays with lower index values).
The following example is identical to the previous one except that we've created a tile overlay MapType
on top of the ROADMAP
map type:
টাইপস্ক্রিপ্ট
/* * This demo illustrates the coordinate system used to display map tiles in the * API. * * Tiles in Google Maps are numbered from the same origin as that for * pixels. For Google's implementation of the Mercator projection, the origin * tile is always at the northwest corner of the map, with x values increasing * from west to east and y values increasing from north to south. * * Try panning and zooming the map to see how the coordinates change. */ class CoordMapType implements google.maps.MapType { tileSize: google.maps.Size; alt: string|null = null; maxZoom: number = 17; minZoom: number = 0; name: string|null = null; projection: google.maps.Projection|null = null; radius: number = 6378137; constructor(tileSize: google.maps.Size) { this.tileSize = tileSize; } getTile( coord: google.maps.Point, zoom: number, ownerDocument: Document ): HTMLElement { const div = ownerDocument.createElement("div"); div.innerHTML = String(coord); div.style.width = this.tileSize.width + "px"; div.style.height = this.tileSize.height + "px"; div.style.fontSize = "10"; div.style.borderStyle = "solid"; div.style.borderWidth = "1px"; div.style.borderColor = "#AAAAAA"; return div; } releaseTile(tile: Element): void {} } function initMap(): void { const map = new google.maps.Map( document.getElementById("map") as HTMLElement, { zoom: 10, center: { lat: 41.85, lng: -87.65 }, } ); // Insert this overlay map type as the first overlay map type at // position 0. Note that all overlay map types appear on top of // their parent base map. const coordMapType = new CoordMapType(new google.maps.Size(256, 256)) map.overlayMapTypes.insertAt( 0, coordMapType ); } declare global { interface Window { initMap: () => void; } } window.initMap = initMap;
জাভাস্ক্রিপ্ট
/* * This demo illustrates the coordinate system used to display map tiles in the * API. * * Tiles in Google Maps are numbered from the same origin as that for * pixels. For Google's implementation of the Mercator projection, the origin * tile is always at the northwest corner of the map, with x values increasing * from west to east and y values increasing from north to south. * * Try panning and zooming the map to see how the coordinates change. */ class CoordMapType { tileSize; alt = null; maxZoom = 17; minZoom = 0; name = null; projection = null; radius = 6378137; constructor(tileSize) { this.tileSize = tileSize; } getTile(coord, zoom, ownerDocument) { const div = ownerDocument.createElement("div"); div.innerHTML = String(coord); div.style.width = this.tileSize.width + "px"; div.style.height = this.tileSize.height + "px"; div.style.fontSize = "10"; div.style.borderStyle = "solid"; div.style.borderWidth = "1px"; div.style.borderColor = "#AAAAAA"; return div; } releaseTile(tile) {} } function initMap() { const map = new google.maps.Map(document.getElementById("map"), { zoom: 10, center: { lat: 41.85, lng: -87.65 }, }); // Insert this overlay map type as the first overlay map type at // position 0. Note that all overlay map types appear on top of // their parent base map. const coordMapType = new CoordMapType(new google.maps.Size(256, 256)); map.overlayMapTypes.insertAt(0, coordMapType); } window.initMap = initMap;
নমুনা চেষ্টা করুন
চিত্র মানচিত্র প্রকার
Implementing a MapType
to act as a base map type can be a time-consuming and laborious task. The API provides a special class that implements the MapType
interface for the most common map types: map types that consist of tiles made up of single image files.
This class, the ImageMapType
class, is constructed using an ImageMapTypeOptions
object specification defining the following required properties:
-
tileSize
(required) specifies the size of the tile (of typegoogle.maps.Size
). Sizes must be rectangular though they need not be square. -
getTileUrl
(required) specifies the function, usually provided as an inline function literal, to handle selection of the proper image tile based on supplied world coordinates and zoom level.
The following code implements a basic ImageMapType
using Google's moon tiles. The example makes use of a normalization function to ensure that tiles repeat along the x-axis, but not along the y-axis of your map.
টাইপস্ক্রিপ্ট
function initMap(): void { const map = new google.maps.Map( document.getElementById("map") as HTMLElement, { center: { lat: 0, lng: 0 }, zoom: 1, streetViewControl: false, mapTypeControlOptions: { mapTypeIds: ["moon"], }, } ); const moonMapType = new google.maps.ImageMapType({ getTileUrl: function (coord, zoom): string { const normalizedCoord = getNormalizedCoord(coord, zoom); if (!normalizedCoord) { return ""; } const bound = Math.pow(2, zoom); return ( "https://mw1.google.com/mw-planetary/lunar/lunarmaps_v1/clem_bw" + "/" + zoom + "/" + normalizedCoord.x + "/" + (bound - normalizedCoord.y - 1) + ".jpg" ); }, tileSize: new google.maps.Size(256, 256), maxZoom: 9, minZoom: 0, // @ts-ignore TODO 'radius' does not exist in type 'ImageMapTypeOptions' radius: 1738000, name: "Moon", }); map.mapTypes.set("moon", moonMapType); map.setMapTypeId("moon"); } // Normalizes the coords that tiles repeat across the x axis (horizontally) // like the standard Google map tiles. function getNormalizedCoord(coord, zoom) { const y = coord.y; let x = coord.x; // tile range in one direction range is dependent on zoom level // 0 = 1 tile, 1 = 2 tiles, 2 = 4 tiles, 3 = 8 tiles, etc const tileRange = 1 << zoom; // don't repeat across y-axis (vertically) if (y < 0 || y >= tileRange) { return null; } // repeat across x-axis if (x < 0 || x >= tileRange) { x = ((x % tileRange) + tileRange) % tileRange; } return { x: x, y: y }; } declare global { interface Window { initMap: () => void; } } window.initMap = initMap;
জাভাস্ক্রিপ্ট
function initMap() { const map = new google.maps.Map(document.getElementById("map"), { center: { lat: 0, lng: 0 }, zoom: 1, streetViewControl: false, mapTypeControlOptions: { mapTypeIds: ["moon"], }, }); const moonMapType = new google.maps.ImageMapType({ getTileUrl: function (coord, zoom) { const normalizedCoord = getNormalizedCoord(coord, zoom); if (!normalizedCoord) { return ""; } const bound = Math.pow(2, zoom); return ( "https://mw1.google.com/mw-planetary/lunar/lunarmaps_v1/clem_bw" + "/" + zoom + "/" + normalizedCoord.x + "/" + (bound - normalizedCoord.y - 1) + ".jpg" ); }, tileSize: new google.maps.Size(256, 256), maxZoom: 9, minZoom: 0, // @ts-ignore TODO 'radius' does not exist in type 'ImageMapTypeOptions' radius: 1738000, name: "Moon", }); map.mapTypes.set("moon", moonMapType); map.setMapTypeId("moon"); } // Normalizes the coords that tiles repeat across the x axis (horizontally) // like the standard Google map tiles. function getNormalizedCoord(coord, zoom) { const y = coord.y; let x = coord.x; // tile range in one direction range is dependent on zoom level // 0 = 1 tile, 1 = 2 tiles, 2 = 4 tiles, 3 = 8 tiles, etc const tileRange = 1 << zoom; // don't repeat across y-axis (vertically) if (y < 0 || y >= tileRange) { return null; } // repeat across x-axis if (x < 0 || x >= tileRange) { x = ((x % tileRange) + tileRange) % tileRange; } return { x: x, y: y }; } window.initMap = initMap;
নমুনা চেষ্টা করুন
অনুমান
The Earth is a three-dimensional sphere (approximately), while a map is a flat two-dimensional surface. The map that you see within the Maps JavaScript API, like any flat map of the Earth, is a projection of that sphere onto a flat surface. In its simplest terms, a projection can be defined as a mapping of latitude/longitude values into coordinates on the projection's map.
Projections in the Maps JavaScript API must implement the Projection
interface. A Projection
implementation must provide not only a mapping from one coordinate system to another, but a bi-directional mapping. That is, you must define how to translate from Earth coordinates ( LatLng
objects) to the Projection
class's world coordinate system, and from the world coordinate system back to the Earth coordinates. Google Maps uses the Mercator projection to create its maps from geographic data and convert events on the map into geographic coordinates. You can obtain this projection by calling getProjection()
on the Map
(or any of the standard base MapType
types.) For most uses, this standard Projection
will suffice, but you may also define and use your own custom projections.
Implement a Projection
When implementing a custom projection, you will need to define a few things:
- The formulae for mapping latitude and longitude coordinates into a Cartesian plane and the corresponding formulae for mapping from a Cartesian plane to latitude and longitude coordinates. (The
Projection
interface only supports transformations into rectilinear coordinates.) - The base tile size. All tiles must be rectangular.
- The "world size" of a map using the base tile set at zoom level 0. Note that for maps consisting of one tile at zoom 0, the world size and base tile size are identical.
Coordinate Transformations in Projections
Each projection provides two methods which translate between these two coordinate systems, allowing you to convert between geographic and world coordinates:
- The
Projection.fromLatLngToPoint()
method converts aLatLng
value into a world coordinate. This method is used to position overlays on the map (and to position the map itself). - The
Projection.fromPointToLatLng()
method converts a world coordinate into aLatLng
value. This method is used to convert events such as clicks that happen on the map into geographic coordinates.
Google Maps assumes that projections are rectilinear.
Generally, you may use a projection for two cases: to create a map of the world, or to create a map of a local area. In the former case, you should ensure that your projection is also rectilinear and normal at all longitudes. Some projections (especially conic projections) may be "locally normal" (ie point north) but deviate from true north; for example, the further the map is positioned relative to some reference longitude. You may use such a projection locally, but be aware that the projection is necessarily imprecise and transformation errors will become increasingly apparently the further away from the reference longitude you deviate.
Map Tile Selection in Projections
Projections are not only useful for determining the positions of locations or overlays, but for positioning the map tiles themselves. The Maps JavaScript API renders base maps using a MapType
interface, which must declare both a projection
property for identifying the map's projection and a getTile()
method for retrieving map tiles based on tile coordinate values. Tile coordinates are based on both your basic tile size (which must be rectangular) and the "world size" of your map, which is the pixel size of your map world at zoom level 0. (For maps consisting of one tile at zoom 0, the tile size and world size are identical.)
You define the base tile size within your MapType
's tileSize
property. You define the world size implicitly within your projection's fromLatLngToPoint()
and fromPointToLatLng()
methods.
Since image selection depends on these passed values, it is useful to name images that can be selected programmatically given those passed values, such as map _ zoom _ tileX _ tileY .png
.
The following example defines an ImageMapType
using the Gall-Peters projection:
টাইপস্ক্রিপ্ট
// This example defines an image map type using the Gall-Peters // projection. // https://en.wikipedia.org/wiki/Gall%E2%80%93Peters_projection const mapElement = document.querySelector("gmp-map") as google.maps.MapElement; let innerMap; async function initMap() { // Request the needed libraries. await google.maps.importLibrary("maps"); // Create a map. innerMap = mapElement.innerMap; innerMap.setOptions({ mapTypeControl: false, }); // Set the Gall-Peters map type. initGallPeters(); innerMap.mapTypes.set("gallPeters", gallPetersMapType); innerMap.setMapTypeId("gallPeters"); // Show the lat and lng under the mouse cursor. const coordsDiv = document.getElementById("coords") as HTMLElement; innerMap.addListener("mousemove", (event: google.maps.MapMouseEvent) => { coordsDiv.textContent = "lat: " + Math.round(event.latLng!.lat()) + ", " + "lng: " + Math.round(event.latLng!.lng()); }); // Add some markers to the map. innerMap.data.setStyle((feature) => { return { title: feature.getProperty("name") as string, optimized: false, }; }); innerMap.data.addGeoJson(cities); } let gallPetersMapType; function initGallPeters() { const GALL_PETERS_RANGE_X = 800; const GALL_PETERS_RANGE_Y = 512; // Fetch Gall-Peters tiles stored locally on our server. gallPetersMapType = new google.maps.ImageMapType({ getTileUrl: function (coord, zoom) { const scale = 1 << zoom; // Wrap tiles horizontally. const x = ((coord.x % scale) + scale) % scale; // Don't wrap tiles vertically. const y = coord.y; if (y < 0 || y >= scale) return ""; return ( "gall-peters_" + zoom + "_" + x + "_" + y + ".png" ); }, tileSize: new google.maps.Size(GALL_PETERS_RANGE_X, GALL_PETERS_RANGE_Y), minZoom: 0, maxZoom: 1, name: "Gall-Peters", }); // Describe the Gall-Peters projection used by these tiles. gallPetersMapType.projection = { fromLatLngToPoint: function (latLng) { const latRadians = (latLng.lat() * Math.PI) / 180; return new google.maps.Point( GALL_PETERS_RANGE_X * (0.5 + latLng.lng() / 360), GALL_PETERS_RANGE_Y * (0.5 - 0.5 * Math.sin(latRadians)) ); }, fromPointToLatLng: function (point, noWrap) { const x = point.x / GALL_PETERS_RANGE_X; const y = Math.max(0, Math.min(1, point.y / GALL_PETERS_RANGE_Y)); return new google.maps.LatLng( (Math.asin(1 - 2 * y) * 180) / Math.PI, -180 + 360 * x, noWrap ); }, }; } // GeoJSON, describing the locations and names of some cities. const cities = { type: "FeatureCollection", features: [ { type: "Feature", geometry: { type: "Point", coordinates: [-87.65, 41.85] }, properties: { name: "Chicago" }, }, { type: "Feature", geometry: { type: "Point", coordinates: [-149.9, 61.218] }, properties: { name: "Anchorage" }, }, { type: "Feature", geometry: { type: "Point", coordinates: [-99.127, 19.427] }, properties: { name: "Mexico City" }, }, { type: "Feature", geometry: { type: "Point", coordinates: [-0.126, 51.5] }, properties: { name: "London" }, }, { type: "Feature", geometry: { type: "Point", coordinates: [28.045, -26.201] }, properties: { name: "Johannesburg" }, }, { type: "Feature", geometry: { type: "Point", coordinates: [15.322, -4.325] }, properties: { name: "Kinshasa" }, }, { type: "Feature", geometry: { type: "Point", coordinates: [151.207, -33.867] }, properties: { name: "Sydney" }, }, { type: "Feature", geometry: { type: "Point", coordinates: [0, 0] }, properties: { name: "0°N 0°E" }, }, ], }; initMap();
জাভাস্ক্রিপ্ট
// This example defines an image map type using the Gall-Peters // projection. // https://en.wikipedia.org/wiki/Gall%E2%80%93Peters_projection const mapElement = document.querySelector("gmp-map"); let innerMap; async function initMap() { // Request the needed libraries. await google.maps.importLibrary("maps"); // Create a map. innerMap = mapElement.innerMap; innerMap.setOptions({ mapTypeControl: false, }); // Set the Gall-Peters map type. initGallPeters(); innerMap.mapTypes.set("gallPeters", gallPetersMapType); innerMap.setMapTypeId("gallPeters"); // Show the lat and lng under the mouse cursor. const coordsDiv = document.getElementById("coords"); innerMap.addListener("mousemove", (event) => { coordsDiv.textContent = "lat: " + Math.round(event.latLng.lat()) + ", " + "lng: " + Math.round(event.latLng.lng()); }); // Add some markers to the map. innerMap.data.setStyle((feature) => { return { title: feature.getProperty("name"), optimized: false, }; }); innerMap.data.addGeoJson(cities); } let gallPetersMapType; function initGallPeters() { const GALL_PETERS_RANGE_X = 800; const GALL_PETERS_RANGE_Y = 512; // Fetch Gall-Peters tiles stored locally on our server. gallPetersMapType = new google.maps.ImageMapType({ getTileUrl: function (coord, zoom) { const scale = 1 << zoom; // Wrap tiles horizontally. const x = ((coord.x % scale) + scale) % scale; // Don't wrap tiles vertically. const y = coord.y; if (y < 0 || y >= scale) return ""; return ("gall-peters_" + zoom + "_" + x + "_" + y + ".png"); }, tileSize: new google.maps.Size(GALL_PETERS_RANGE_X, GALL_PETERS_RANGE_Y), minZoom: 0, maxZoom: 1, name: "Gall-Peters", }); // Describe the Gall-Peters projection used by these tiles. gallPetersMapType.projection = { fromLatLngToPoint: function (latLng) { const latRadians = (latLng.lat() * Math.PI) / 180; return new google.maps.Point(GALL_PETERS_RANGE_X * (0.5 + latLng.lng() / 360), GALL_PETERS_RANGE_Y * (0.5 - 0.5 * Math.sin(latRadians))); }, fromPointToLatLng: function (point, noWrap) { const x = point.x / GALL_PETERS_RANGE_X; const y = Math.max(0, Math.min(1, point.y / GALL_PETERS_RANGE_Y)); return new google.maps.LatLng((Math.asin(1 - 2 * y) * 180) / Math.PI, -180 + 360 * x, noWrap); }, }; } // GeoJSON, describing the locations and names of some cities. const cities = { type: "FeatureCollection", features: [ { type: "Feature", geometry: { type: "Point", coordinates: [-87.65, 41.85] }, properties: { name: "Chicago" }, }, { type: "Feature", geometry: { type: "Point", coordinates: [-149.9, 61.218] }, properties: { name: "Anchorage" }, }, { type: "Feature", geometry: { type: "Point", coordinates: [-99.127, 19.427] }, properties: { name: "Mexico City" }, }, { type: "Feature", geometry: { type: "Point", coordinates: [-0.126, 51.5] }, properties: { name: "London" }, }, { type: "Feature", geometry: { type: "Point", coordinates: [28.045, -26.201] }, properties: { name: "Johannesburg" }, }, { type: "Feature", geometry: { type: "Point", coordinates: [15.322, -4.325] }, properties: { name: "Kinshasa" }, }, { type: "Feature", geometry: { type: "Point", coordinates: [151.207, -33.867] }, properties: { name: "Sydney" }, }, { type: "Feature", geometry: { type: "Point", coordinates: [0, 0] }, properties: { name: "0°N 0°E" }, }, ], }; initMap();
নমুনা চেষ্টা করুন
This document discusses the types of maps you can display using the Maps JavaScript API. The API uses a MapType
object to hold information about these maps. A MapType
is an interface that defines the display and usage of map tiles and the translation of coordinate systems from screen coordinates to world coordinates (on the map). Each MapType
must contain a few methods to handle retrieval and release of tiles, and properties that define its visual behavior.
The inner workings of map types within the Maps JavaScript API is an advanced topic. Most developers can use the basic map types noted below. However, you can also modify the presentation of existing map types using Styled Maps or define your own map tiles using custom map types . When providing custom map types, you will need to understand how to modify the map's Map Type Registry .
মৌলিক মানচিত্র প্রকার
There are four types of maps available within the Maps JavaScript API. In addition to the familiar "painted" road map tiles, the Maps JavaScript API also supports other maps types.
The following map types are available in the Maps JavaScript API:
-
roadmap
displays the default road map view. This is the default map type. -
satellite
displays Google Earth satellite images. -
hybrid
displays a mixture of normal and satellite views. -
terrain
displays a physical map based on terrain information.
You modify the map type in use by the Map
by setting its mapTypeId
property, either within the constructor by setting its Map options
object, or by calling the map's setMapTypeId()
method. The mapTypeID
property defaults to roadmap
.
Setting the mapTypeId
upon construction:
var myLatlng = new google.maps.LatLng(-34.397, 150.644); var mapOptions = { zoom: 8, center: myLatlng, mapTypeId: 'satellite' }; var map = new google.maps.Map(document.getElementById('map'), mapOptions);
Modifying the mapTypeId
dynamically:
map.setMapTypeId('terrain');
Note that you don't actually set the map's map type directly, but instead set its mapTypeId
to reference a MapType
using an identifier. The Maps JavaScript API uses a map type registry, explained below, to manage these references.
45° চিত্র
The Maps JavaScript API supports special 45° imagery for certain locations. This high-resolution imagery provides perspective views towards each of the cardinal direction (North, South, East, West). These images are available at higher zoom levels for supported map types.
The following image shows a 45° perspective view of New York City:
The satellite
and hybrid
map types support 45° imagery at high zoom levels (12 and greater) where available. If the user zooms into a location for which such imagery exists, these map types automatically alter their views in the following manner:
- The satellite or hybrid imagery is replaced with imagery giving a 45° perspective, centered on the current location. By default, such views are oriented towards north. If the user zooms out, the default satellite or hybrid imagery appears again. The behavior varies depending on zoom level and the value of
tilt
: - Between zoom levels 12 and 18 the top-down basemap (0°) displays by default unless
tilt
is set to 45. - At zoom levels of 18 or greater the 45° basemap displays unless
tilt
is set to 0. - The rotate control becomes visible. The rotate control provides options that enable the user to toggle tilt, and to rotate the view in 90° increments in either direction. To hide the rotate control, set
rotateControl
tofalse
.
Zooming out from a map type displaying 45° imagery reverts each of these changes, re-establishing the original map types.
Enable and Disable 45° Imagery
You can disable 45° imagery by calling setTilt(0)
on the Map
object. To enable 45° imagery for supported map types, call setTilt(45)
. The Map
's getTilt()
method will always reflect the current tilt
being shown on the map; if you set a tilt
on a map and then later remove that tilt
(by zooming the map out, for example), the map's getTilt()
method will return 0
.
Important: 45° imagery is only supported on raster maps; this imagery cannot be used with vector maps.
The following example displays a 45° view of New York City:
টাইপস্ক্রিপ্ট
function initMap(): void { const map = new google.maps.Map( document.getElementById("map") as HTMLElement, { center: { lat: 40.76, lng: -73.983 }, zoom: 15, mapTypeId: "satellite", } ); map.setTilt(45); } declare global { interface Window { initMap: () => void; } } window.initMap = initMap;
জাভাস্ক্রিপ্ট
function initMap() { const map = new google.maps.Map(document.getElementById("map"), { center: { lat: 40.76, lng: -73.983 }, zoom: 15, mapTypeId: "satellite", }); map.setTilt(45); } window.initMap = initMap;
নমুনা চেষ্টা করুন
Rotate 45° Imagery
The 45° imagery actually consists of a collection of images for each cardinal direction (North, South, East, West). Once your map is displaying 45° imagery, you can orient the imagery towards one of its cardinal directions by calling setHeading()
on the Map
object, passing a number value expressed as degrees from North.
The following example shows an aerial map and auto-rotates the map every 3 seconds when the button is clicked:
টাইপস্ক্রিপ্ট
let map: google.maps.Map; function initMap(): void { map = new google.maps.Map(document.getElementById("map") as HTMLElement, { center: { lat: 40.76, lng: -73.983 }, zoom: 15, mapTypeId: "satellite", heading: 90, tilt: 45, }); // add listener to button document.getElementById("rotate")!.addEventListener("click", autoRotate); } function rotate90(): void { const heading = map.getHeading() || 0; map.setHeading(heading + 90); } function autoRotate(): void { // Determine if we're showing aerial imagery. if (map.getTilt() !== 0) { window.setInterval(rotate90, 3000); } } declare global { interface Window { initMap: () => void; } } window.initMap = initMap;
জাভাস্ক্রিপ্ট
let map; function initMap() { map = new google.maps.Map(document.getElementById("map"), { center: { lat: 40.76, lng: -73.983 }, zoom: 15, mapTypeId: "satellite", heading: 90, tilt: 45, }); // add listener to button document.getElementById("rotate").addEventListener("click", autoRotate); } function rotate90() { const heading = map.getHeading() || 0; map.setHeading(heading + 90); } function autoRotate() { // Determine if we're showing aerial imagery. if (map.getTilt() !== 0) { window.setInterval(rotate90, 3000); } } window.initMap = initMap;
নমুনা চেষ্টা করুন
Modify the Map Type Registry
A map's mapTypeId
is a string identifier that is used to associate a MapType
with a unique value. Each Map
object maintains a MapTypeRegistry
which contains the collection of available MapType
s for that map. This registry is used to select the types of maps which are available in the Map's MapType control, for example.
You don't read directly from the map type registry. Instead, you modify the registry by adding custom map types and associating them with a string identifier of your choosing. You cannot modify or alter the basic map types (though you can remove them from the map by altering the appearance of the map's associated mapTypeControlOptions
).
The following code sets the map to show only two map types in the map's mapTypeControlOptions
and modifies the registry to add the association with this identifier to the actual implementation of the MapType
interface.
// Modify the control to only display two maptypes, the // default ROADMAP and the custom 'mymap'. // Note that because this is an association, we // don't need to modify the MapTypeRegistry beforehand. var MY_MAPTYPE_ID = 'mymaps'; var mapOptions = { zoom: 12, center: brooklyn, mapTypeControlOptions: { mapTypeIds: ['roadmap', MY_MAPTYPE_ID] }, mapTypeId: MY_MAPTYPE_ID }; // Create our map. This creation will implicitly create a // map type registry. map = new google.maps.Map(document.getElementById('map'), mapOptions); // Create your custom map type using your own code. // (See below.) var myMapType = new MyMapType(); // Set the registry to associate 'mymap' with the // custom map type we created, and set the map to // show that map type. map.mapTypes.set(MY_MAPTYPE_ID, myMapType);
Styled Maps
StyledMapType
আপনাকে স্ট্যান্ডার্ড Google বেস ম্যাপের উপস্থাপনা কাস্টমাইজ করতে দেয়, রাস্তা, পার্ক এবং বিল্ট-আপ এলাকার মতো উপাদানগুলির ভিজ্যুয়াল ডিসপ্লে পরিবর্তন করে ডিফল্ট মানচিত্রের ধরণে ব্যবহৃত একটি ভিন্ন শৈলী প্রতিফলিত করতে। StyledMapType
শুধুমাত্র ডিফল্ট roadmap
মানচিত্র প্রকারকে প্রভাবিত করে।
For more information about the StyledMapType
, see Using embedded JSON style declarations .
Custom Map Types
The Maps JavaScript API supports the display and management of custom map types, allowing you to implement your own map imagery or tile overlays.
Several possible map type implementations exist within the Maps JavaScript API:
- Standard tile sets consisting of images which collectively constitute full cartographic maps. These tile sets are also known as base map types. These map types act and behave like the existing default map types:
roadmap
,satellite
,hybrid
andterrain
. You can add your custom map type to a Map'smapTypes
array to allow the UI within the Maps JavaScript API to treat your custom map type as a standard map type (by including it in the MapType control, for example). - Image tile overlays which display on top of existing base map types. Generally, these map types are used to augment an existing map type to display additional information and are often constrained to specific locations and/or zoom levels. Note that these tiles may be transparent, allowing you to add features to existing maps.
- Non-image map types, which allow you to manipulate the display of map information at its most fundamental level.
Each of these options relies on creating a class that implements the MapType
interface. Additionally, the ImageMapType
class provides some built-in behavior to simplify the creation of imagery map types.
The MapType
Interface
Before you create classes which implement MapType
, it is important to understand how Google Maps determines coordinates and decides which parts of the map to show. You need to implement similar logic for any base or overlay map types. Read the guide to map and tile coordinates .
Custom map types must implement the MapType
interface. This interface specifies certain properties and methods that allow the API to initiate requests to your map type(s) when the API determines that it needs to display map tiles within the current viewport and zoom level. You handle these requests to decide which tile to load.
Note : You may create your own class to implement this interface. Alternatively, if you have compatible imagery you can use the ImageMapType
class which already implements this interface.
Classes implementing the MapType
interface require that you define and populate the following properties:
-
tileSize
(required) specifies the size of the tile (of typegoogle.maps.Size
). Sizes must be rectangular though they need not be square. -
maxZoom
(required) specifies the maximum zoom level at which to display tiles of this map type. -
minZoom
(optional) specifies the minimum zoom level at which to display tile of this map type. By default, this value is0
indicating that no minimum zoom level exists. -
name
(optional) specifies the name for this map type. This property is only necessary if you want this map type to be selectable within a MapType control. (See Control Options .) -
alt
(optional) specifies the alternate text for this map type, exhibited as hover text. This property is only necessary if you want this map type to be selectable within a MapType control. (See Control Options .)
Additionally, classes implementing the MapType
interface need to implement the following methods:
getTile()
(required) is called whenever the API determines that the map needs to display new tiles for the given viewport. ThegetTile()
method must have the following signature:getTile(tileCoord:Point,zoom:number,ownerDocument:Document):Node
The API determines whether it needs to call
getTile()
based on theMapType
'stileSize
,minZoom
, andmaxZoom
properties and the map's current viewport and zoom level. The handler for this method should return an HTML element given a passed coordinate, zoom level, and DOM element on which to append the tile image.releaseTile()
(optional) is called whenever the API determines that the map needs to remove a tile as it falls out of view. This method must have the following signature:releaseTile(tile:Node)
You typically should handle removal of any elements that were attached to the map tiles upon addition to the map. For example, if you attached event listeners to map tile overlays, you should remove them here.
The getTile()
method acts as the main controller for determining which tiles to load within a given viewport.
Base Map Types
Map types which you construct in this manner may either stand alone or be combined with other map types as overlays. Standalone map types are known as base map types . You may want to have the API treat such custom MapType
s as it would any other existing base map type ( ROADMAP
, TERRAIN
, etc.). To do so, add your custom MapType
to the Map
's mapTypes
property. This property is of type MapTypeRegistry
.
The following code creates a base MapType
to display a map's tile coordinates and draws an outline of the tiles:
টাইপস্ক্রিপ্ট
/* * This demo demonstrates how to replace default map tiles with custom imagery. * In this case, the CoordMapType displays gray tiles annotated with the tile * coordinates. * * Try panning and zooming the map to see how the coordinates change. */ class CoordMapType { tileSize: google.maps.Size; maxZoom = 19; name = "Tile #s"; alt = "Tile Coordinate Map Type"; constructor(tileSize: google.maps.Size) { this.tileSize = tileSize; } getTile( coord: google.maps.Point, zoom: number, ownerDocument: Document ): HTMLElement { const div = ownerDocument.createElement("div"); div.innerHTML = String(coord); div.style.width = this.tileSize.width + "px"; div.style.height = this.tileSize.height + "px"; div.style.fontSize = "10"; div.style.borderStyle = "solid"; div.style.borderWidth = "1px"; div.style.borderColor = "#AAAAAA"; div.style.backgroundColor = "#E5E3DF"; return div; } releaseTile(tile: HTMLElement): void {} } function initMap(): void { const map = new google.maps.Map( document.getElementById("map") as HTMLElement, { zoom: 10, center: { lat: 41.85, lng: -87.65 }, streetViewControl: false, mapTypeId: "coordinate", mapTypeControlOptions: { mapTypeIds: ["coordinate", "roadmap"], style: google.maps.MapTypeControlStyle.DROPDOWN_MENU, }, } ); map.addListener("maptypeid_changed", () => { const showStreetViewControl = (map.getMapTypeId() as string) !== "coordinate"; map.setOptions({ streetViewControl: showStreetViewControl, }); }); // Now attach the coordinate map type to the map's registry. map.mapTypes.set( "coordinate", new CoordMapType(new google.maps.Size(256, 256)) ); } declare global { interface Window { initMap: () => void; } } window.initMap = initMap;
জাভাস্ক্রিপ্ট
/* * This demo demonstrates how to replace default map tiles with custom imagery. * In this case, the CoordMapType displays gray tiles annotated with the tile * coordinates. * * Try panning and zooming the map to see how the coordinates change. */ class CoordMapType { tileSize; maxZoom = 19; name = "Tile #s"; alt = "Tile Coordinate Map Type"; constructor(tileSize) { this.tileSize = tileSize; } getTile(coord, zoom, ownerDocument) { const div = ownerDocument.createElement("div"); div.innerHTML = String(coord); div.style.width = this.tileSize.width + "px"; div.style.height = this.tileSize.height + "px"; div.style.fontSize = "10"; div.style.borderStyle = "solid"; div.style.borderWidth = "1px"; div.style.borderColor = "#AAAAAA"; div.style.backgroundColor = "#E5E3DF"; return div; } releaseTile(tile) {} } function initMap() { const map = new google.maps.Map(document.getElementById("map"), { zoom: 10, center: { lat: 41.85, lng: -87.65 }, streetViewControl: false, mapTypeId: "coordinate", mapTypeControlOptions: { mapTypeIds: ["coordinate", "roadmap"], style: google.maps.MapTypeControlStyle.DROPDOWN_MENU, }, }); map.addListener("maptypeid_changed", () => { const showStreetViewControl = map.getMapTypeId() !== "coordinate"; map.setOptions({ streetViewControl: showStreetViewControl, }); }); // Now attach the coordinate map type to the map's registry. map.mapTypes.set( "coordinate", new CoordMapType(new google.maps.Size(256, 256)), ); } window.initMap = initMap;
নমুনা চেষ্টা করুন
ওভারলে মানচিত্র প্রকার
Some map types are designed to work on top of existing map types. Such map types may have transparent layers indicating points of interest, or showing additional data to the user.
In these cases, you do not want the map type treated as a separate entity but as an overlay. You can do this by adding the map type to an existing MapType
directly using the Map
's overlayMapTypes
property. This property contains an MVCArray
of MapType
s. All map types (base and overlay) are rendered within the mapPane
layer. Overlay map types will display on top of the base map they are attached to, in the order in which they appear in the Map.overlayMapTypes
array (overlays with higher index values are displayed in front of overlays with lower index values).
The following example is identical to the previous one except that we've created a tile overlay MapType
on top of the ROADMAP
map type:
টাইপস্ক্রিপ্ট
/* * This demo illustrates the coordinate system used to display map tiles in the * API. * * Tiles in Google Maps are numbered from the same origin as that for * pixels. For Google's implementation of the Mercator projection, the origin * tile is always at the northwest corner of the map, with x values increasing * from west to east and y values increasing from north to south. * * Try panning and zooming the map to see how the coordinates change. */ class CoordMapType implements google.maps.MapType { tileSize: google.maps.Size; alt: string|null = null; maxZoom: number = 17; minZoom: number = 0; name: string|null = null; projection: google.maps.Projection|null = null; radius: number = 6378137; constructor(tileSize: google.maps.Size) { this.tileSize = tileSize; } getTile( coord: google.maps.Point, zoom: number, ownerDocument: Document ): HTMLElement { const div = ownerDocument.createElement("div"); div.innerHTML = String(coord); div.style.width = this.tileSize.width + "px"; div.style.height = this.tileSize.height + "px"; div.style.fontSize = "10"; div.style.borderStyle = "solid"; div.style.borderWidth = "1px"; div.style.borderColor = "#AAAAAA"; return div; } releaseTile(tile: Element): void {} } function initMap(): void { const map = new google.maps.Map( document.getElementById("map") as HTMLElement, { zoom: 10, center: { lat: 41.85, lng: -87.65 }, } ); // Insert this overlay map type as the first overlay map type at // position 0. Note that all overlay map types appear on top of // their parent base map. const coordMapType = new CoordMapType(new google.maps.Size(256, 256)) map.overlayMapTypes.insertAt( 0, coordMapType ); } declare global { interface Window { initMap: () => void; } } window.initMap = initMap;
জাভাস্ক্রিপ্ট
/* * This demo illustrates the coordinate system used to display map tiles in the * API. * * Tiles in Google Maps are numbered from the same origin as that for * pixels. For Google's implementation of the Mercator projection, the origin * tile is always at the northwest corner of the map, with x values increasing * from west to east and y values increasing from north to south. * * Try panning and zooming the map to see how the coordinates change. */ class CoordMapType { tileSize; alt = null; maxZoom = 17; minZoom = 0; name = null; projection = null; radius = 6378137; constructor(tileSize) { this.tileSize = tileSize; } getTile(coord, zoom, ownerDocument) { const div = ownerDocument.createElement("div"); div.innerHTML = String(coord); div.style.width = this.tileSize.width + "px"; div.style.height = this.tileSize.height + "px"; div.style.fontSize = "10"; div.style.borderStyle = "solid"; div.style.borderWidth = "1px"; div.style.borderColor = "#AAAAAA"; return div; } releaseTile(tile) {} } function initMap() { const map = new google.maps.Map(document.getElementById("map"), { zoom: 10, center: { lat: 41.85, lng: -87.65 }, }); // Insert this overlay map type as the first overlay map type at // position 0. Note that all overlay map types appear on top of // their parent base map. const coordMapType = new CoordMapType(new google.maps.Size(256, 256)); map.overlayMapTypes.insertAt(0, coordMapType); } window.initMap = initMap;
নমুনা চেষ্টা করুন
চিত্র মানচিত্র প্রকার
Implementing a MapType
to act as a base map type can be a time-consuming and laborious task. The API provides a special class that implements the MapType
interface for the most common map types: map types that consist of tiles made up of single image files.
This class, the ImageMapType
class, is constructed using an ImageMapTypeOptions
object specification defining the following required properties:
-
tileSize
(required) specifies the size of the tile (of typegoogle.maps.Size
). Sizes must be rectangular though they need not be square. -
getTileUrl
(required) specifies the function, usually provided as an inline function literal, to handle selection of the proper image tile based on supplied world coordinates and zoom level.
The following code implements a basic ImageMapType
using Google's moon tiles. The example makes use of a normalization function to ensure that tiles repeat along the x-axis, but not along the y-axis of your map.
টাইপস্ক্রিপ্ট
function initMap(): void { const map = new google.maps.Map( document.getElementById("map") as HTMLElement, { center: { lat: 0, lng: 0 }, zoom: 1, streetViewControl: false, mapTypeControlOptions: { mapTypeIds: ["moon"], }, } ); const moonMapType = new google.maps.ImageMapType({ getTileUrl: function (coord, zoom): string { const normalizedCoord = getNormalizedCoord(coord, zoom); if (!normalizedCoord) { return ""; } const bound = Math.pow(2, zoom); return ( "https://mw1.google.com/mw-planetary/lunar/lunarmaps_v1/clem_bw" + "/" + zoom + "/" + normalizedCoord.x + "/" + (bound - normalizedCoord.y - 1) + ".jpg" ); }, tileSize: new google.maps.Size(256, 256), maxZoom: 9, minZoom: 0, // @ts-ignore TODO 'radius' does not exist in type 'ImageMapTypeOptions' radius: 1738000, name: "Moon", }); map.mapTypes.set("moon", moonMapType); map.setMapTypeId("moon"); } // Normalizes the coords that tiles repeat across the x axis (horizontally) // like the standard Google map tiles. function getNormalizedCoord(coord, zoom) { const y = coord.y; let x = coord.x; // tile range in one direction range is dependent on zoom level // 0 = 1 tile, 1 = 2 tiles, 2 = 4 tiles, 3 = 8 tiles, etc const tileRange = 1 << zoom; // don't repeat across y-axis (vertically) if (y < 0 || y >= tileRange) { return null; } // repeat across x-axis if (x < 0 || x >= tileRange) { x = ((x % tileRange) + tileRange) % tileRange; } return { x: x, y: y }; } declare global { interface Window { initMap: () => void; } } window.initMap = initMap;
জাভাস্ক্রিপ্ট
function initMap() { const map = new google.maps.Map(document.getElementById("map"), { center: { lat: 0, lng: 0 }, zoom: 1, streetViewControl: false, mapTypeControlOptions: { mapTypeIds: ["moon"], }, }); const moonMapType = new google.maps.ImageMapType({ getTileUrl: function (coord, zoom) { const normalizedCoord = getNormalizedCoord(coord, zoom); if (!normalizedCoord) { return ""; } const bound = Math.pow(2, zoom); return ( "https://mw1.google.com/mw-planetary/lunar/lunarmaps_v1/clem_bw" + "/" + zoom + "/" + normalizedCoord.x + "/" + (bound - normalizedCoord.y - 1) + ".jpg" ); }, tileSize: new google.maps.Size(256, 256), maxZoom: 9, minZoom: 0, // @ts-ignore TODO 'radius' does not exist in type 'ImageMapTypeOptions' radius: 1738000, name: "Moon", }); map.mapTypes.set("moon", moonMapType); map.setMapTypeId("moon"); } // Normalizes the coords that tiles repeat across the x axis (horizontally) // like the standard Google map tiles. function getNormalizedCoord(coord, zoom) { const y = coord.y; let x = coord.x; // tile range in one direction range is dependent on zoom level // 0 = 1 tile, 1 = 2 tiles, 2 = 4 tiles, 3 = 8 tiles, etc const tileRange = 1 << zoom; // don't repeat across y-axis (vertically) if (y < 0 || y >= tileRange) { return null; } // repeat across x-axis if (x < 0 || x >= tileRange) { x = ((x % tileRange) + tileRange) % tileRange; } return { x: x, y: y }; } window.initMap = initMap;
নমুনা চেষ্টা করুন
অনুমান
The Earth is a three-dimensional sphere (approximately), while a map is a flat two-dimensional surface. The map that you see within the Maps JavaScript API, like any flat map of the Earth, is a projection of that sphere onto a flat surface. In its simplest terms, a projection can be defined as a mapping of latitude/longitude values into coordinates on the projection's map.
Projections in the Maps JavaScript API must implement the Projection
interface. A Projection
implementation must provide not only a mapping from one coordinate system to another, but a bi-directional mapping. That is, you must define how to translate from Earth coordinates ( LatLng
objects) to the Projection
class's world coordinate system, and from the world coordinate system back to the Earth coordinates. Google Maps uses the Mercator projection to create its maps from geographic data and convert events on the map into geographic coordinates. You can obtain this projection by calling getProjection()
on the Map
(or any of the standard base MapType
types.) For most uses, this standard Projection
will suffice, but you may also define and use your own custom projections.
Implement a Projection
When implementing a custom projection, you will need to define a few things:
- The formulae for mapping latitude and longitude coordinates into a Cartesian plane and the corresponding formulae for mapping from a Cartesian plane to latitude and longitude coordinates. (The
Projection
interface only supports transformations into rectilinear coordinates.) - The base tile size. All tiles must be rectangular.
- The "world size" of a map using the base tile set at zoom level 0. Note that for maps consisting of one tile at zoom 0, the world size and base tile size are identical.
Coordinate Transformations in Projections
Each projection provides two methods which translate between these two coordinate systems, allowing you to convert between geographic and world coordinates:
- The
Projection.fromLatLngToPoint()
method converts aLatLng
value into a world coordinate. This method is used to position overlays on the map (and to position the map itself). - The
Projection.fromPointToLatLng()
method converts a world coordinate into aLatLng
value. This method is used to convert events such as clicks that happen on the map into geographic coordinates.
Google Maps assumes that projections are rectilinear.
Generally, you may use a projection for two cases: to create a map of the world, or to create a map of a local area. In the former case, you should ensure that your projection is also rectilinear and normal at all longitudes. Some projections (especially conic projections) may be "locally normal" (ie point north) but deviate from true north; for example, the further the map is positioned relative to some reference longitude. You may use such a projection locally, but be aware that the projection is necessarily imprecise and transformation errors will become increasingly apparently the further away from the reference longitude you deviate.
Map Tile Selection in Projections
Projections are not only useful for determining the positions of locations or overlays, but for positioning the map tiles themselves. The Maps JavaScript API renders base maps using a MapType
interface, which must declare both a projection
property for identifying the map's projection and a getTile()
method for retrieving map tiles based on tile coordinate values. Tile coordinates are based on both your basic tile size (which must be rectangular) and the "world size" of your map, which is the pixel size of your map world at zoom level 0. (For maps consisting of one tile at zoom 0, the tile size and world size are identical.)
You define the base tile size within your MapType
's tileSize
property. You define the world size implicitly within your projection's fromLatLngToPoint()
and fromPointToLatLng()
methods.
Since image selection depends on these passed values, it is useful to name images that can be selected programmatically given those passed values, such as map _ zoom _ tileX _ tileY .png
.
The following example defines an ImageMapType
using the Gall-Peters projection:
টাইপস্ক্রিপ্ট
// This example defines an image map type using the Gall-Peters // projection. // https://en.wikipedia.org/wiki/Gall%E2%80%93Peters_projection const mapElement = document.querySelector("gmp-map") as google.maps.MapElement; let innerMap; async function initMap() { // Request the needed libraries. await google.maps.importLibrary("maps"); // Create a map. innerMap = mapElement.innerMap; innerMap.setOptions({ mapTypeControl: false, }); // Set the Gall-Peters map type. initGallPeters(); innerMap.mapTypes.set("gallPeters", gallPetersMapType); innerMap.setMapTypeId("gallPeters"); // Show the lat and lng under the mouse cursor. const coordsDiv = document.getElementById("coords") as HTMLElement; innerMap.addListener("mousemove", (event: google.maps.MapMouseEvent) => { coordsDiv.textContent = "lat: " + Math.round(event.latLng!.lat()) + ", " + "lng: " + Math.round(event.latLng!.lng()); }); // Add some markers to the map. innerMap.data.setStyle((feature) => { return { title: feature.getProperty("name") as string, optimized: false, }; }); innerMap.data.addGeoJson(cities); } let gallPetersMapType; function initGallPeters() { const GALL_PETERS_RANGE_X = 800; const GALL_PETERS_RANGE_Y = 512; // Fetch Gall-Peters tiles stored locally on our server. gallPetersMapType = new google.maps.ImageMapType({ getTileUrl: function (coord, zoom) { const scale = 1 << zoom; // Wrap tiles horizontally. const x = ((coord.x % scale) + scale) % scale; // Don't wrap tiles vertically. const y = coord.y; if (y < 0 || y >= scale) return ""; return ( "gall-peters_" + zoom + "_" + x + "_" + y + ".png" ); }, tileSize: new google.maps.Size(GALL_PETERS_RANGE_X, GALL_PETERS_RANGE_Y), minZoom: 0, maxZoom: 1, name: "Gall-Peters", }); // Describe the Gall-Peters projection used by these tiles. gallPetersMapType.projection = { fromLatLngToPoint: function (latLng) { const latRadians = (latLng.lat() * Math.PI) / 180; return new google.maps.Point( GALL_PETERS_RANGE_X * (0.5 + latLng.lng() / 360), GALL_PETERS_RANGE_Y * (0.5 - 0.5 * Math.sin(latRadians)) ); }, fromPointToLatLng: function (point, noWrap) { const x = point.x / GALL_PETERS_RANGE_X; const y = Math.max(0, Math.min(1, point.y / GALL_PETERS_RANGE_Y)); return new google.maps.LatLng( (Math.asin(1 - 2 * y) * 180) / Math.PI, -180 + 360 * x, noWrap ); }, }; } // GeoJSON, describing the locations and names of some cities. const cities = { type: "FeatureCollection", features: [ { type: "Feature", geometry: { type: "Point", coordinates: [-87.65, 41.85] }, properties: { name: "Chicago" }, }, { type: "Feature", geometry: { type: "Point", coordinates: [-149.9, 61.218] }, properties: { name: "Anchorage" }, }, { type: "Feature", geometry: { type: "Point", coordinates: [-99.127, 19.427] }, properties: { name: "Mexico City" }, }, { type: "Feature", geometry: { type: "Point", coordinates: [-0.126, 51.5] }, properties: { name: "London" }, }, { type: "Feature", geometry: { type: "Point", coordinates: [28.045, -26.201] }, properties: { name: "Johannesburg" }, }, { type: "Feature", geometry: { type: "Point", coordinates: [15.322, -4.325] }, properties: { name: "Kinshasa" }, }, { type: "Feature", geometry: { type: "Point", coordinates: [151.207, -33.867] }, properties: { name: "Sydney" }, }, { type: "Feature", geometry: { type: "Point", coordinates: [0, 0] }, properties: { name: "0°N 0°E" }, }, ], }; initMap();
জাভাস্ক্রিপ্ট
// This example defines an image map type using the Gall-Peters // projection. // https://en.wikipedia.org/wiki/Gall%E2%80%93Peters_projection const mapElement = document.querySelector("gmp-map"); let innerMap; async function initMap() { // Request the needed libraries. await google.maps.importLibrary("maps"); // Create a map. innerMap = mapElement.innerMap; innerMap.setOptions({ mapTypeControl: false, }); // Set the Gall-Peters map type. initGallPeters(); innerMap.mapTypes.set("gallPeters", gallPetersMapType); innerMap.setMapTypeId("gallPeters"); // Show the lat and lng under the mouse cursor. const coordsDiv = document.getElementById("coords"); innerMap.addListener("mousemove", (event) => { coordsDiv.textContent = "lat: " + Math.round(event.latLng.lat()) + ", " + "lng: " + Math.round(event.latLng.lng()); }); // Add some markers to the map. innerMap.data.setStyle((feature) => { return { title: feature.getProperty("name"), optimized: false, }; }); innerMap.data.addGeoJson(cities); } let gallPetersMapType; function initGallPeters() { const GALL_PETERS_RANGE_X = 800; const GALL_PETERS_RANGE_Y = 512; // Fetch Gall-Peters tiles stored locally on our server. gallPetersMapType = new google.maps.ImageMapType({ getTileUrl: function (coord, zoom) { const scale = 1 << zoom; // Wrap tiles horizontally. const x = ((coord.x % scale) + scale) % scale; // Don't wrap tiles vertically. const y = coord.y; if (y < 0 || y >= scale) return ""; return ("gall-peters_" + zoom + "_" + x + "_" + y + ".png"); }, tileSize: new google.maps.Size(GALL_PETERS_RANGE_X, GALL_PETERS_RANGE_Y), minZoom: 0, maxZoom: 1, name: "Gall-Peters", }); // Describe the Gall-Peters projection used by these tiles. gallPetersMapType.projection = { fromLatLngToPoint: function (latLng) { const latRadians = (latLng.lat() * Math.PI) / 180; return new google.maps.Point(GALL_PETERS_RANGE_X * (0.5 + latLng.lng() / 360), GALL_PETERS_RANGE_Y * (0.5 - 0.5 * Math.sin(latRadians))); }, fromPointToLatLng: function (point, noWrap) { const x = point.x / GALL_PETERS_RANGE_X; const y = Math.max(0, Math.min(1, point.y / GALL_PETERS_RANGE_Y)); return new google.maps.LatLng((Math.asin(1 - 2 * y) * 180) / Math.PI, -180 + 360 * x, noWrap); }, }; } // GeoJSON, describing the locations and names of some cities. const cities = { type: "FeatureCollection", features: [ { type: "Feature", geometry: { type: "Point", coordinates: [-87.65, 41.85] }, properties: { name: "Chicago" }, }, { type: "Feature", geometry: { type: "Point", coordinates: [-149.9, 61.218] }, properties: { name: "Anchorage" }, }, { type: "Feature", geometry: { type: "Point", coordinates: [-99.127, 19.427] }, properties: { name: "Mexico City" }, }, { type: "Feature", geometry: { type: "Point", coordinates: [-0.126, 51.5] }, properties: { name: "London" }, }, { type: "Feature", geometry: { type: "Point", coordinates: [28.045, -26.201] }, properties: { name: "Johannesburg" }, }, { type: "Feature", geometry: { type: "Point", coordinates: [15.322, -4.325] }, properties: { name: "Kinshasa" }, }, { type: "Feature", geometry: { type: "Point", coordinates: [151.207, -33.867] }, properties: { name: "Sydney" }, }, { type: "Feature", geometry: { type: "Point", coordinates: [0, 0] }, properties: { name: "0°N 0°E" }, }, ], }; initMap();