कोरोप्लेथ मैप बनाएं

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

कोरोप्लेथ मैप, थीम वाले मैप का एक टाइप है. इसमें प्रशासनिक क्षेत्र डेटा वैल्यू के हिसाब से रंग या शेड किया जाता है. स्टाइल फ़ैक्ट्री का इस्तेमाल किया जा सकता है का इस्तेमाल, डेटा के आधार पर मैप को शैली देने के लिए किया जाता है, जहां हर राज्य जो संख्या वाली वैल्यू की रेंज से जुड़ी होती है. उदाहरण के तौर पर दिया गया मैप, अमेरिका के राज्यों के लिए कोरोप्लेथ मैप.

इस उदाहरण में, डेटा में राज्य का स्थान आईडी शामिल है. स्टाइल फ़ैक्ट्री फ़ंक्शन, राज्य के लिए जगह का आईडी.

इस स्क्रीनशॉट में, अमेरिका के राज्यों को दिखाने वाले मैप को दिखाया गया है.

  1. अगर आपने पहले से ऐसा नहीं किया है, तो इसमें दिए गए चरणों का पालन करें शुरू करना नया मैप आईडी और मैप स्टाइल बनाने के लिए. इसे चालू करना न भूलें एडमिन क्षेत्र लेवल 1 सुविधा की लेयर.

  2. व्यवस्थापकीय क्षेत्र स्तर 1 सुविधा परत का संदर्भ पाएं जब मैप शुरू हो जाता है. संयुक्त राज्य अमेरिका के लिए, ये प्रशासनिक स्तर अलग-अलग राज्यों के हिसाब से होने चाहिए.

    Java

    private FeatureLayer areaLevel1Layer;
    @Override public void onMapReady(GoogleMap map) { areaLevel1Layer = map.getFeatureLayer(new FeatureLayerOptions.Builder() .featureType(FeatureType.ADMINISTRATIVE_AREA_LEVEL_1) .build());
    // Apply style factory function to ADMINISTRATIVE_AREA_LEVEL_1 layer. styleAreaLevel1Layer(); }

    Kotlin

    private var areaLevel1Layer: FeatureLayer? = null
    override fun onMapReady(googleMap: GoogleMap) { // Get the ADMINISTRATIVE_AREA_LEVEL_1 feature layer. areaLevel1Layer = googleMap.getFeatureLayer(FeatureLayerOptions.Builder() .featureType(FeatureType.ADMINISTRATIVE_AREA_LEVEL_1) .build())
    // Apply style factory function to ADMINISTRATIVE_AREA_LEVEL_1 layer. styleAreaLevel1Layer() }

  3. एक शैली फ़ैक्ट्री फ़ंक्शन बनाएं और उसे व्यवस्थापकीय क्षेत्र स्तर 1 सुविधा परत. नीचे दिया गया उदाहरण, फ़ंक्शन के लिए पॉलीगॉन का इस्तेमाल करें.

    Java

    private void styleAreaLevel1Layer() {
      FeatureLayer.StyleFactory styleFactory = (Feature feature) -> {
        if (feature instanceof PlaceFeature) {
          PlaceFeature placeFeature = (PlaceFeature) feature;
    // Return a hueColor in the range [-299,299]. If the value is // negative, add 300 to make the value positive. int hueColor = placeFeature.getPlaceId().hashCode() % 300; if (hueColor < 0) { hueColor += 300; }
    return new FeatureStyle.Builder() // Set the fill color for the state based on the hashed hue color. .fillColor(Color.HSVToColor(150, new float[] {hueColor, 1, 1})) .build(); } return null; };
    // Apply the style factory function to the feature layer. areaLevel1Layer.setFeatureStyle(styleFactory); }

    Kotlin

    private fun styleAreaLevel1Layer() {
      val styleFactory = FeatureLayer.StyleFactory { feature: Feature ->
          if (feature is PlaceFeature) {
              val placeFeature: PlaceFeature = feature as PlaceFeature
    // Return a hueColor in the range [-299,299]. If the value is // negative, add 300 to make the value positive. var hueColor: Int = placeFeature.getPlaceId().hashCode() % 300 if (hueColor < 0) { hueColor += 300 } return@StyleFactory FeatureStyle.Builder() // Set the fill color for the state based on the hashed hue color. .fillColor(Color.HSVToColor(150, floatArrayOf(hueColor.toFloat(), 1f, 1f))) .build() } return@StyleFactory null }
    // Apply the style factory function to the feature layer. areaLevel1Layer?.setFeatureStyle(styleFactory) }