मैप में डेटासेट जोड़ना

प्लैटफ़ॉर्म चुनें: Android iOS JavaScript

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

ज़रूरी शर्तें

आगे बढ़ने से पहले, आपके पास मैप आईडी, मैप स्टाइल, और डेटासेट आईडी होना चाहिए.

मैप स्टाइल से डेटासेट आईडी जोड़ना

अपने डेटासेट को इस्तेमाल की जा रही मैप स्टाइल से जोड़ने के लिए, यह तरीका अपनाएं:

  1. Google Cloud Console में, **डेटासेट** पेज पर जाएं.
  2. डेटासेट के नाम पर क्लिक करें. आपको डेटासेट की जानकारी पेज दिखेगा.
  3. पूर्वावलोकन टैब पर क्लिक करें.
  4. मैप स्टाइल जोड़ें पर स्क्रोल करें और क्लिक करें.
    'जुड़े हुए मैप स्टाइल' सेक्शन में दाईं ओर, 'मैप स्टाइल जोड़ें' लिखा हुआ प्लस बटन.
  5. जोड़ने के लिए, मैप स्टाइल के चेकबॉक्स पर क्लिक करें. इसके बाद, सेव करें पर क्लिक करें.

स्टाइल के सामान्य नियमों का इस्तेमाल करना

सुविधाओं को स्टाइल करने का सबसे आसान तरीका है कि FeatureStyleOptions पास किया जाए. इससे, स्टाइल एट्रिब्यूट तय किए जा सकते हैं. जैसे, रंग, ओपैसिटी, और लाइन वेट. डेटासेट की सुविधा वाली लेयर पर, सुविधा की स्टाइल के विकल्प सीधे लागू करें या उन्हें FeatureStyleFunction के साथ इस्तेमाल करें.

TypeScript

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

JavaScript

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

स्टाइल के डिक्लेरेटिव नियमों का इस्तेमाल करना

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

TypeScript

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

JavaScript

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) सेट करके स्टाइल लागू करें.

TypeScript

// Dataset ID for NYC park data.
const datasetId = 'a75dd002-ad20-4fe6-af60-27cd2ed636b4';

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

JavaScript

// Dataset ID for NYC park data.
const datasetId = 'a75dd002-ad20-4fe6-af60-27cd2ed636b4';
const datasetLayer = innerMap.getDatasetFeatureLayer(datasetId);
datasetLayer.style = styleOptions;

किसी लेयर से स्टाइलिंग हटाना

किसी लेयर से स्टाइलिंग हटाने के लिए, style को null पर सेट करें:

featureLayer.style = null;

सुविधा की स्टाइल के फ़ंक्शन से null भी दिखाया जा सकता है. उदाहरण के लिए, अगर आपको सुविधाओं के किसी सबसेट को छिपाना है.

एट्रिब्यूशन टेक्स्ट जोड़ना

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

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

<gmp-map center="40.757815, -73.933123" zoom="11" map-id="5cd2c9ca1cf05670" map-type-control="false">
  <div id="attribution" slot="control-block-end-inline-start">Data source: NYC Open Data</div>
</gmp-map>

#attribution {
  background-color: rgba(255, 255, 255, 0.7);
  font-family: "Roboto", "Arial", "sans-serif";
  font-size: 10px;
  padding: 2px;
  margin: 2px;
}