একটি মানচিত্রে একটি ডেটাসেট যোগ করুন

FeatureStyleFunction , যেখানে আপনি একটি ডেটাসেটে বেছে বেছে স্টাইল বৈশিষ্ট্যের জন্য যুক্তি সংজ্ঞায়িত করেন। এটি এই যুক্তির উপর ভিত্তি করে FeatureStyleOptions প্রদান করে। স্টাইলিং যুক্তির প্রয়োজন না হলে, আপনি সরাসরি শৈলী সেট করতে FeatureStyleOptions ব্যবহার করতে পারেন। এই পৃষ্ঠাটি আপনাকে দেখায় কিভাবে একটি মানচিত্রে একটি ডেটাসেট যোগ করতে হয় এবং স্টাইলিং প্রয়োগ করতে হয়।

পূর্বশর্ত

এগিয়ে যাওয়ার আগে, আপনার একটি মানচিত্র আইডি এবং মানচিত্র শৈলী এবং একটি ডেটাসেট আইডি থাকা উচিত৷

একটি মানচিত্র শৈলীর সাথে একটি ডেটাসেট আইডি সংযুক্ত করুন৷

আপনি যে মানচিত্র শৈলী ব্যবহার করছেন তার সাথে আপনার ডেটাসেট সংযুক্ত করতে নিম্নলিখিত পদক্ষেপগুলি নিন:

  1. Google ক্লাউড কনসোলে, ডেটাসেট পৃষ্ঠায় যান
  2. ডেটাসেটের নামে ক্লিক করুন। ডেটাসেট বিশদ পৃষ্ঠা প্রদর্শিত হবে।
  3. প্রিভিউ ট্যাবে ক্লিক করুন।
  4. নীচে স্ক্রোল করুন, এবং মানচিত্র শৈলী যোগ করুন ক্লিক করুন।
    অ্যাড ম্যাপ স্টাইল বোতামের স্ক্রিনশট।
  5. সংযুক্ত করতে মানচিত্র শৈলী(গুলি) এর চেকবক্সে ক্লিক করুন এবং তারপর সংরক্ষণ করুন ক্লিক করুন৷

সহজ শৈলী নিয়ম ব্যবহার করুন

শৈলী বৈশিষ্ট্যগুলির সবচেয়ে সহজ উপায় হল রঙ, অস্বচ্ছতা এবং লাইনের ওজনের মতো শৈলী বৈশিষ্ট্যগুলিকে সংজ্ঞায়িত করার জন্য একটি FeatureStyleOptions পাস করা। একটি ডেটাসেট বৈশিষ্ট্য স্তরে সরাসরি বৈশিষ্ট্য শৈলী বিকল্পগুলি প্রয়োগ করুন, অথবা একটি FeatureStyleFunction এর সাথে একত্রে ব্যবহার করুন৷

টাইপস্ক্রিপ্ট

const styleOptions = {
    strokeColor: 'green',
    strokeWeight: 2,
    strokeOpacity: 1,
    fillColor: 'green',
    fillOpacity: 0.3,
};

জাভাস্ক্রিপ্ট

const styleOptions = {
  strokeColor: "green",
  strokeWeight: 2,
  strokeOpacity: 1,
  fillColor: "green",
  fillOpacity: 0.3,
};

ঘোষণামূলক শৈলী নিয়ম ব্যবহার করুন

বর্ণনামূলকভাবে শৈলী নিয়ম সেট করতে FeatureStyleFunction ব্যবহার করুন এবং আপনার সমগ্র ডেটাসেট জুড়ে প্রয়োগ করুন। ডেটাসেট অ্যাট্রিবিউট মানের উপর ভিত্তি করে একটি বৈশিষ্ট্যে FeatureStyleOptions প্রয়োগ করুন। আপনি আপনার বৈশিষ্ট্য শৈলী ফাংশন থেকে null ফেরত দিতে পারেন, উদাহরণস্বরূপ যদি আপনি বৈশিষ্ট্যগুলির একটি উপসেট অদৃশ্য থাকতে চান। এই উদাহরণটি একটি শৈলী ফাংশন দেখায় যা ডেটা বৈশিষ্ট্যের উপর ভিত্তি করে পয়েন্টগুলির একটি সেটকে রঙ করে:

টাইপস্ক্রিপ্ট

function setStyle(/* FeatureStyleFunctionOptions */ params) {
    // Get the dataset feature, so we can work with all of its attributes.
    const datasetFeature = params.feature;
    // Get all of the needed dataset attributes.
    const furColors = datasetFeature.datasetAttributes['CombinationofPrimaryandHighlightColor'];

    // Apply styles. Fill is primary fur color, stroke is secondary fur color.
    switch (furColors) {
        case 'Black+':
            return /* FeatureStyleOptions */ { fillColor: 'black', pointRadius: 8 };
            break;
        case 'Cinnamon+':
            return /* FeatureStyleOptions */ { fillColor: '#8b0000', pointRadius: 8 };
            break;
        case 'Cinnamon+Gray':
            return /* FeatureStyleOptions */ { fillColor: '#8b0000', strokeColor: 'gray', pointRadius: 6 };
            break;
        case 'Cinnamon+White':
            return /* FeatureStyleOptions */ { fillColor: '#8b0000', strokeColor: 'white', pointRadius: 6 };
            break;
        case 'Gray+':
            return /* FeatureStyleOptions */ { fillColor: 'gray', pointRadius: 8 };
            break;
        case 'Gray+Cinnamon':
            return /* FeatureStyleOptions */ { fillColor: 'gray', strokeColor: '#8b0000', pointRadius: 6 };
            break;
        case 'Gray+Cinnamon, White':
            return /* FeatureStyleOptions */ { fillColor: 'silver', strokeColor: '#8b0000', pointRadius: 6 };
            break;
        case 'Gray+White':
            return /* FeatureStyleOptions */ { fillColor: 'gray', strokeColor: 'white', pointRadius: 6 };
            break;
        default: // Color not defined.
            return /* FeatureStyleOptions */ { fillColor: 'yellow', pointRadius: 8 };
            break; 
    }
}

জাভাস্ক্রিপ্ট

function setStyle(/* FeatureStyleFunctionOptions */ params) {
  // Get the dataset feature, so we can work with all of its attributes.
  const datasetFeature = params.feature;
  // Get all of the needed dataset attributes.
  const furColors =
    datasetFeature.datasetAttributes["CombinationofPrimaryandHighlightColor"];

  // Apply styles. Fill is primary fur color, stroke is secondary fur color.
  switch (furColors) {
    case "Black+":
      return /* FeatureStyleOptions */ { fillColor: "black", pointRadius: 8 };
      break;
    case "Cinnamon+":
      return /* FeatureStyleOptions */ { fillColor: "#8b0000", pointRadius: 8 };
      break;
    case "Cinnamon+Gray":
      return /* FeatureStyleOptions */ {
        fillColor: "#8b0000",
        strokeColor: "gray",
        pointRadius: 6,
      };
      break;
    case "Cinnamon+White":
      return /* FeatureStyleOptions */ {
        fillColor: "#8b0000",
        strokeColor: "white",
        pointRadius: 6,
      };
      break;
    case "Gray+":
      return /* FeatureStyleOptions */ { fillColor: "gray", pointRadius: 8 };
      break;
    case "Gray+Cinnamon":
      return /* FeatureStyleOptions */ {
        fillColor: "gray",
        strokeColor: "#8b0000",
        pointRadius: 6,
      };
      break;
    case "Gray+Cinnamon, White":
      return /* FeatureStyleOptions */ {
        fillColor: "silver",
        strokeColor: "#8b0000",
        pointRadius: 6,
      };
      break;
    case "Gray+White":
      return /* FeatureStyleOptions */ {
        fillColor: "gray",
        strokeColor: "white",
        pointRadius: 6,
      };
      break;
    default: // Color not defined.
      return /* FeatureStyleOptions */ { fillColor: "yellow", pointRadius: 8 };
      break;
  }
}

ডেটাসেট বৈশিষ্ট্য স্তরে শৈলী প্রয়োগ করুন

বৈশিষ্ট্য শৈলী ফাংশনে শৈলী প্রয়োগ করতে:

  1. map.getDatasetFeatureLayer() কল করে, ডেটাসেট আইডি পাস করে ডেটাসেট বৈশিষ্ট্য স্তর পান৷
  2. ডেটাসেট স্তরে বৈশিষ্ট্য শৈলী বিকল্পগুলি (যেমন styleOptions ) বা ফাংশন (যেমন setStyle ) সেট করে শৈলী প্রয়োগ করুন৷

টাইপস্ক্রিপ্ট

const datasetLayer = map.getDatasetFeatureLayer(datasetId);
datasetLayer.style = styleOptions;

জাভাস্ক্রিপ্ট

const datasetLayer = map.getDatasetFeatureLayer(datasetId);

datasetLayer.style = styleOptions;

একটি স্তর থেকে স্টাইলিং সরান

একটি স্তর থেকে স্টাইলিং অপসারণ করতে, style null সেট করুন:

featureLayer.style = null;

আপনি আপনার বৈশিষ্ট্য শৈলী ফাংশন থেকে null ফেরত দিতে পারেন, উদাহরণস্বরূপ যদি আপনি বৈশিষ্ট্যগুলির একটি উপসেট অদৃশ্য থাকতে চান।

অ্যাট্রিবিউশন টেক্সট যোগ করুন

Google মানচিত্রে আপলোড করা ডেটাসেটগুলি প্রদর্শন করার সময় আপনার মানচিত্র অবশ্যই যেকোন প্রয়োজনীয় বৈশিষ্ট্য(গুলি) প্রদর্শন করবে৷ অ্যাট্রিবিউশন টেক্সট অবশ্যই অস্পষ্ট বা Google লোগোতে হস্তক্ষেপ করবে না।

অ্যাট্রিবিউশন টেক্সট যোগ করার একটি উপায় হল মানচিত্র মানক অবস্থানে নির্বিচারে HTML স্থাপন করতে কাস্টম নিয়ন্ত্রণ ব্যবহার করে। নিম্নলিখিত কোডের উদাহরণটি এমন একটি ফাংশন দেখায় যা প্রোগ্রাম্যাটিকভাবে এমন একটি কাস্টম নিয়ন্ত্রণ তৈরি করে:

টাইপস্ক্রিপ্ট

function createAttribution(map) {
    const attributionLabel = document.createElement('div');
    // Define CSS styles.
    attributionLabel.style.backgroundColor = '#fff';
    attributionLabel.style.opacity = '0.7';
    attributionLabel.style.fontFamily = 'Roboto,Arial,sans-serif';
    attributionLabel.style.fontSize = '10px';
    attributionLabel.style.padding = '2px';
    attributionLabel.style.margin = '2px';
    attributionLabel.textContent = 'Data source: NYC Open Data';
    return attributionLabel;
}

জাভাস্ক্রিপ্ট

function createAttribution(map) {
  const attributionLabel = document.createElement("div");

  // Define CSS styles.
  attributionLabel.style.backgroundColor = "#fff";
  attributionLabel.style.opacity = "0.7";
  attributionLabel.style.fontFamily = "Roboto,Arial,sans-serif";
  attributionLabel.style.fontSize = "10px";
  attributionLabel.style.padding = "2px";
  attributionLabel.style.margin = "2px";
  attributionLabel.textContent = "Data source: NYC Open Data";
  return attributionLabel;
}

একবার নিয়ন্ত্রণ সংজ্ঞায়িত করা হলে, আপনি এটিকে প্রারম্ভিক সময়ে মানচিত্রে যোগ করতে পারেন, যেমনটি এখানে দেখানো হয়েছে:

টাইপস্ক্রিপ্ট

// Create an attribution DIV and add the attribution to the map.
const attributionDiv = document.createElement('div');
const attributionControl = createAttribution(map);
attributionDiv.appendChild(attributionControl);
map.controls[google.maps.ControlPosition.LEFT_BOTTOM].push(attributionDiv);

জাভাস্ক্রিপ্ট

// Create an attribution DIV and add the attribution to the map.
const attributionDiv = document.createElement("div");
const attributionControl = createAttribution(map);

attributionDiv.appendChild(attributionControl);
map.controls[google.maps.ControlPosition.LEFT_BOTTOM].push(attributionDiv);