إنشاء خريطة لـ Chro لديهم

اختيار النظام الأساسي: 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) }