ডেটা বৈশিষ্ট্যগুলিকে click ইভেন্টগুলিতে সাড়া দিন এবং ব্যবহারকারীর মিথস্ক্রিয়া উপর ভিত্তি করে একটি বৈশিষ্ট্যের চেহারা পরিবর্তন করতে ব্যবহার করুন৷
একটি ক্লিক ইভেন্ট হ্যান্ডলার লিখুন
যখন একটি বৈশিষ্ট্য স্তরে একটি ক্লিক ইভেন্ট ঘটে, তখন Android এর জন্য Maps SDK একটি FeatureClickEvent অবজেক্ট ইভেন্ট হ্যান্ডলারকে পাস করে৷
ক্লিক দ্বারা প্রভাবিত বৈশিষ্ট্যের তালিকা পেতে FeatureClickEvent.getFeatures() পদ্ধতি ব্যবহার করুন।
বৈশিষ্ট্য স্তর ইভেন্ট পরিচালনা করুন
ডেটাসেট স্তরে ইভেন্টগুলি পরিচালনা করতে নিম্নলিখিত পদক্ষেপগুলি নিন। এই উদাহরণে, আপনি নির্বাচিত বৈশিষ্ট্যের প্রতিনিধিত্বকারী বহুভুজে একটি নীল ফিল এবং সীমানা প্রয়োগ করেন।
আপনি যখন FeatureLayer.setFeatureStyle() কল করেন, স্টাইল ফ্যাক্টরি ফাংশন ডেটাসেটের সমস্ত বৈশিষ্ট্যের বৈশিষ্ট্য শৈলী সেট করে। ইভেন্ট হ্যান্ডলারে একটি ডেটাসেটের শৈলী আপডেট করতে, আপনাকে অবশ্যই FeatureLayer.setFeatureStyle() কল করে সমস্ত ডেটাসেট বৈশিষ্ট্যগুলিতে আপডেট করা শৈলী সেট করতে হবে৷
যদি আপনি ইতিমধ্যে এটি না করে থাকেন, তাহলে একটি নতুন মানচিত্র ID এবং মানচিত্রের শৈলী তৈরি করতে শুরু করুন -এর ধাপগুলি অনুসরণ করুন৷ Datasets বৈশিষ্ট্য স্তর সক্রিয় করতে ভুলবেন না.
privatevardatasetLayer:FeatureLayer?=null// The globalid of the clicked dataset feature.varlastGlobalId:String?=null overridefunonMapReady(googleMap:GoogleMap){// Get the DATASET feature layer.datasetLayer=googleMap.getFeatureLayer(FeatureLayerOptions.Builder().featureType(FeatureType.DATASET)// Specify the dataset ID..datasetId(YOUR_DATASET_ID).build()) // Register the click event handler for the Datasets layer.datasetLayer?.addOnFeatureClickListener(this) // Apply default style to all features on load to enable clicking.styleDatasetsLayer()} // Define the click event handler to set lastGlobalId to globalid of selected feature.overridefunonFeatureClick(event:FeatureClickEvent){// Get the dataset feature affected by the click.valclickFeatures:MutableList<Feature>=event.featureslastGlobalId=nullif(clickFeatures.get(0)isDatasetFeature){lastGlobalId=((clickFeatures.get(0)asDatasetFeature).getDatasetAttributes().get("globalid"))// Remember to reset the Style Factory.styleDatasetsLayer()}}
জাভা
privateFeatureLayerdatasetLayer;// The globalid of the clicked dataset feature.Stringlastgobalid=null; @OverridepublicvoidonMapReady(GoogleMapmap){ // Get the DATASET feature layer.datasetLayer=map.getFeatureLayer(newFeatureLayerOptions.Builder().featureType(FeatureType.DATASET)// Specify the dataset ID..datasetId(YOUR_DATASET_ID).build()); // Register the click event handler for the Datasets layer.datasetLayer.addOnFeatureClickListener(this); // Apply default style to all features on load to enable clicking.styleDatasetsLayer();} @Override// Define the click event handler.publicvoidonFeatureClick(FeatureClickEventevent){// Get the dataset feature affected by the click.List<Feature>clickFeatures=event.getFeatures();lastgobalid=null;if(clickFeatures.get(0)instanceofDatasetFeature){lastgobalid=((DatasetFeature)clickFeatures.get(0)).getDatasetAttributes().get("globalid");// Remember to reset the Style Factory.styleDatasetsLayer();}}
নির্বাচিত বৈশিষ্ট্যে নীল এবং অন্যান্য সমস্ত বৈশিষ্ট্যগুলিতে সবুজ রঙের একটি পূরণ করুন। শুধুমাত্র দৃশ্যমান বৈশিষ্ট্য ক্লিকযোগ্য.
কোটলিন
// Set fill and border for all features.privatefunstyleDatasetsLayer(){// Create the style factory function.valstyleFactory=FeatureLayer.StyleFactory{feature:Feature-> // Check if the feature is an instance of DatasetFeature.if(featureisDatasetFeature){valglobalIDs:MutableMap<String,String>=feature.getDatasetAttributes()// Determine globalid attribute.valglobalID=globalIDs!!["globalid"]// Set default colors to to green.varfillColor=0x800000ffvarstrokeColor=0xff0000ffif(globalID==lastGlobalId){// Color selected area blue.fillColor=0x8000ff00strokeColor=0xff00ff00}return@StyleFactoryFeatureStyle.Builder().fillColor(fillColor).strokeColor(strokeColor).build()}return@StyleFactorynull} // Apply the style factory function to the dataset feature layer.datasetLayer?.setFeatureStyle(styleFactory)}
জাভা
// Set default green fill and border for all features.privatevoidstyleDatasetsLayer(){// Create the style factory function.FeatureLayer.StyleFactorystyleFactory=(Featurefeature)->{ // Check if the feature is an instance of DatasetFeature.if(featureinstanceofDatasetFeature){ // Check if "globalid" attribute of feature is the "globalid" of clicked feature.Map<String,String>globalIDs=((DatasetFeature)feature).getDatasetAttributes();StringglobalID=globalIDs.get("globalid");// Set default colors to green.intfillColor=0x4000ff00;intstrokeColor=0xff00ff00;if(Objects.equals(globalID,lastgobalid)){// Color selected area blue.fillColor=0x400000ff;strokeColor=0xff0000ff;}returnnewFeatureStyle.Builder().fillColor(fillColor).strokeColor(strokeColor).strokeWidth(2).build();}returnnull;}; // Apply the style factory function to the feature layer.datasetLayer.setFeatureStyle(styleFactory);}
[null,null,["2025-09-03 UTC-তে শেষবার আপডেট করা হয়েছে।"],[[["\u003cp\u003eThis guide explains how to make data features on your map clickable and responsive to user interaction, allowing you to change a feature's appearance upon click.\u003c/p\u003e\n"],["\u003cp\u003eIt involves writing a click event handler that captures the clicked feature's information and uses it to apply styling changes.\u003c/p\u003e\n"],["\u003cp\u003eYou will learn to use the \u003ccode\u003eFeatureClickEvent\u003c/code\u003e to get the clicked features and \u003ccode\u003eFeatureLayer.setFeatureStyle()\u003c/code\u003e to update their appearance, highlighting the selected feature.\u003c/p\u003e\n"],["\u003cp\u003eThe guide includes Android code examples demonstrating how to register the event handler and apply a blue fill to the selected feature, while keeping others green.\u003c/p\u003e\n"]]],["The core content explains how to make data features clickable and dynamically change their appearance upon user interaction within the Android Maps SDK. Key actions include: registering a click event handler via `FeatureLayer.addOnFeatureClickListener()`, retrieving the affected features through `FeatureClickEvent.getFeatures()`, and using `FeatureLayer.setFeatureStyle()` with a custom style factory to apply visual changes. The `globalid` is used to identify and update the style of a selected feature, changing it from a default green to blue.\n"],null,["Select platform: [Android](/maps/documentation/android-sdk/dds-datasets/make-data-features-clickable \"View this page for the Android platform docs.\") [iOS](/maps/documentation/ios-sdk/dds-datasets/make-data-features-tappable \"View this page for the iOS platform docs.\") [JavaScript](/maps/documentation/javascript/dds-datasets/make-data-features-clickable \"View this page for the JavaScript platform docs.\")\n\n\u003cbr /\u003e\n\nMake data features respond to `click` events, and use them to\nchange the appearance of a feature based on user interaction.\n\nWrite a click event handler\n\nWhen a click event occurs on a feature layer, the Maps SDK for Android passes a\n[`FeatureClickEvent`](/android/reference/com/google/android/gms/maps/model/FeatureClickEvent)\nobject to the event handler.\n\nUse the `FeatureClickEvent.getFeatures()` method to get the list of features\naffected by the click.\n\nHandle feature layer events\n\nTake the following steps to handle events on the Datasets layer. In this\nexample, you apply a blue fill and border to the polygon representing the\nselected feature.\n| **Note:** In this example, the `globalid` attribute of the dataset contains a unique identifier for each polygon. You can then examine the `globalid` of the polygon that was clicked to apply the blue styling only to that polygon.\n\nWhen you call\n[`FeatureLayer.setFeatureStyle()`](/android/reference/com/google/android/gms/maps/model/FeatureLayer#setFeatureStyle(com.google.android.gms.maps.model.FeatureLayer.StyleFactory)),\nthe style factory function sets the feature style on all features in the\ndataset. To update the style of a dataset in the event handler, you must\ncall `FeatureLayer.setFeatureStyle()` to set the updated style on all dataset\nfeatures.\n\n1. If you haven't already done so, follow the steps in\n [Get Started](/maps/documentation/android/dds-datasets/start)\n to create a new map ID and map style. Be sure to enable the **Datasets**\n feature layer.\n\n2. Make sure your class implements\n [`FeatureLayer.OnFeatureClickListener`](/android/reference/com/google/android/gms/maps/model/FeatureLayer.OnFeatureClickListener).\n\n3. Register an event handler for feature click events by calling\n [`FeatureLayer.addOnFeatureClickListener()`](/android/reference/com/google/android/gms/maps/model/FeatureLayer#addOnFeatureClickListener(com.google.android.gms.maps.model.FeatureLayer.OnFeatureClickListener)).\n\n Kotlin\n\n\n ```java\n private var datasetLayer: FeatureLayer? = null\n // The globalid of the clicked dataset feature.\n var lastGlobalId: String? = null\n\n override fun onMapReady(googleMap: GoogleMap) {\n // Get the DATASET feature layer.\n datasetLayer = googleMap.getFeatureLayer(FeatureLayerOptions.Builder()\n .featureType(FeatureType.DATASET)\n // Specify the dataset ID.\n .datasetId(YOUR_DATASET_ID)\n .build())\n\n // Register the click event handler for the Datasets layer.\n datasetLayer?.addOnFeatureClickListener(this)\n\n // Apply default style to all features on load to enable clicking.\n styleDatasetsLayer()\n }\n\n // Define the click event handler to set lastGlobalId to globalid of selected feature.\n override fun onFeatureClick(event: FeatureClickEvent) {\n // Get the dataset feature affected by the click.\n val clickFeatures: MutableList\u003cFeature\u003e = event.features\n lastGlobalId = null\n if (clickFeatures.get(0) is DatasetFeature) {\n lastGlobalId = ((clickFeatures.get(0) as DatasetFeature).getDatasetAttributes().get(\"globalid\"))\n // Remember to reset the Style Factory.\n styleDatasetsLayer()\n }\n }\n ```\n\n \u003cbr /\u003e\n\n Java\n\n\n ```java\n private FeatureLayer datasetLayer;\n // The globalid of the clicked dataset feature.\n String lastgobalid = null;\n\n @Override\n public void onMapReady(GoogleMap map) {\n\n // Get the DATASET feature layer.\n datasetLayer = map.getFeatureLayer(new FeatureLayerOptions.Builder()\n .featureType(FeatureType.DATASET)\n // Specify the dataset ID.\n .datasetId(YOUR_DATASET_ID)\n .build());\n\n // Register the click event handler for the Datasets layer.\n datasetLayer.addOnFeatureClickListener(this);\n\n // Apply default style to all features on load to enable clicking.\n styleDatasetsLayer();\n }\n\n @Override\n // Define the click event handler.\n public void onFeatureClick(FeatureClickEvent event) {\n // Get the dataset feature affected by the click.\n List\u003cFeature\u003e clickFeatures = event.getFeatures();\n lastgobalid = null;\n if (clickFeatures.get(0) instanceof DatasetFeature) {\n lastgobalid = ((DatasetFeature) clickFeatures.get(0)).getDatasetAttributes().get(\"globalid\");\n // Remember to reset the Style Factory.\n styleDatasetsLayer();\n }\n }\n ```\n\n \u003cbr /\u003e\n\n4. Apply a fill color of blue to the selected feature and green to all other\n features. Only visible features are clickable.\n\n Kotlin\n\n\n ```java\n // Set fill and border for all features.\n private fun styleDatasetsLayer() {\n // Create the style factory function.\n val styleFactory = FeatureLayer.StyleFactory { feature: Feature -\u003e\n\n // Check if the feature is an instance of DatasetFeature.\n if (feature is DatasetFeature) {\n val globalIDs: MutableMap\u003cString, String\u003e = feature.getDatasetAttributes()\n // Determine globalid attribute.\n val globalID = globalIDs!![\"globalid\"]\n // Set default colors to to green.\n var fillColor = 0x800000ff\n var strokeColor = 0xff0000ff\n if (globalID == lastGlobalId) {\n // Color selected area blue.\n fillColor = 0x8000ff00\n strokeColor = 0xff00ff00\n }\n return@StyleFactory FeatureStyle.Builder()\n .fillColor(fillColor)\n .strokeColor(strokeColor)\n .build()\n }\n return@StyleFactory null\n }\n\n // Apply the style factory function to the dataset feature layer.\n datasetLayer?.setFeatureStyle(styleFactory)\n }\n ```\n\n \u003cbr /\u003e\n\n Java\n\n\n ```java\n // Set default green fill and border for all features.\n private void styleDatasetsLayer() {\n // Create the style factory function.\n FeatureLayer.StyleFactory styleFactory = (Feature feature) -\u003e {\n\n // Check if the feature is an instance of DatasetFeature.\n if (feature instanceof DatasetFeature) {\n\n // Check if \"globalid\" attribute of feature is the \"globalid\" of clicked feature.\n Map\u003cString, String\u003e globalIDs = ((DatasetFeature) feature).getDatasetAttributes();\n String globalID = globalIDs.get(\"globalid\");\n // Set default colors to green.\n int fillColor = 0x4000ff00;\n int strokeColor = 0xff00ff00;\n if (Objects.equals(globalID, lastgobalid)) {\n // Color selected area blue.\n fillColor = 0x400000ff;\n strokeColor = 0xff0000ff;\n }\n return new FeatureStyle.Builder()\n .fillColor(fillColor)\n .strokeColor(strokeColor)\n .strokeWidth(2)\n .build();\n }\n return null;\n };\n\n // Apply the style factory function to the feature layer.\n datasetLayer.setFeatureStyle(styleFactory);\n }\n ```\n\n \u003cbr /\u003e"]]