عرض معلومات الميزة

إشعار

خرائط Azure إيقاف Android SDK

تم الآن إهمال خرائط Azure Native SDK لنظام التشغيل Android وسيتم إيقافه في 3/31/25. لتجنب انقطاع الخدمة، قم بالترحيل إلى خرائط Azure Web SDK بحلول 3/31/25. لمزيد من المعلومات، راجع دليل ترحيل خرائط Azure Android SDK.

غالبًا ما يتم تمثيل البيانات المكانية باستخدام النقاط والخطوط والمضلعات. تحتوي غالبًا هذه البيانات على بيانات تعريف مرتبطة بها. على سبيل المثال، قد تمثل نقطة موقع مطعم وقد تكون بيانات تعريف حول هذا المطعم هي الاسم والعنوان ونوع الطعام الذي يقدمه. يمكن إضافة هذه بيانات التعريف كخصائص لـ GeoJSON Feature. تنشئ التعليمات البرمجية التالية ميزة نقطة بسيطة مع title خاصية بقيمة "مرحبًا بالعالم !"

//Create a data source and add it to the map.
DataSource source = new DataSource();
map.sources.add(source);

//Create a point feature.
Feature feature = Feature.fromGeometry(Point.fromLngLat(-122.33, 47.64));

//Add a property to the feature.
feature.addStringProperty("title", "Hello World!");

//Create a point feature, pass in the metadata properties, and add it to the data source.
source.add(feature);
//Create a data source and add it to the map.
val source = DataSource()
map.sources.add(source)

//Create a point feature.
val feature = Feature.fromGeometry(Point.fromLngLat(-122.33, 47.64))

//Add a property to the feature.
feature.addStringProperty("title", "Hello World!")

//Create a point feature, pass in the metadata properties, and add it to the data source.
source.add(feature)

لمزيد من المعلومات حول كيفية إنشاء البيانات وإضافتها إلى الخريطة، راجع إنشاء مصدر بيانات.

عندما يتفاعل المستخدم مع ميزة على الخريطة، يمكن استخدام الأحداث من أجل الرد على هذه الإجراءات. يمثل السيناريو الشائع عرض رسالة مكونة من خصائص بيانات التعريف لميزة تفاعل معها المستخدم. يعد الحدث OnFeatureClick هو الحدث الرئيس المستخدم لاكتشاف وقت قيام المستخدم بالنقر فوق معلم على الخريطة. يوجد هناك أيضًا حدث OnLongFeatureClick. OnFeatureClick عند إضافة الحدث إلى الخريطة، يمكن أن يقتصر على طبقة واحدة عن طريق تمرير معرف طبقة للحد منها. إذا لم يتم تمرير معرف الطبقة، فإن الضغط على أي ميزة على الخريطة، بغض النظر عن الطبقة التي يوجد بها، سيؤدي إلى إطلاق هذا الحدث. تنشئ الشفرة التالية طبقة رموز لعرض بيانات النقاط على الخريطة، ثم تضيف حدث OnFeatureClick وتقيده بطبقة الرموز هذه.

//Create a symbol and add it to the map.
SymbolLayer layer = new SymbolLayer(source);
map.layers.add(layer);

//Add a feature click event to the map.
map.events.add((OnFeatureClick) (features) -> {
    //Retrieve the title property of the feature as a string.
    String msg = features.get(0).getStringProperty("title");

    //Do something with the message.

    //Return a boolean indicating if event should be consumed or continue bubble up.
    return false;
}, layer.getId());    //Limit this event to the symbol layer.
//Create a symbol and add it to the map.
val layer = SymbolLayer(source)
map.layers.add(layer)

//Add a feature click event to the map.
map.events.add(OnFeatureClick { features: List<Feature> ->
    //Retrieve the title property of the feature as a string.
    val msg = features[0].getStringProperty("title")

    //Do something with the message.

    //Return a boolean indicating if event should be consumed or continue bubble up.
    return false
}, layer.getId()) //Limit this event to the symbol layer.

عرض رسالة منبثقة

تعتبر الرسالة المنبثقة واحدة من أسهل الطرق لعرض المعلومات للمستخدم وهي متوفرة في جميع إصدارات Android. لا يدعم أي نوع من إدخالات المستخدم ولا يتم عرضه إلا لفترة قصيرة من الوقت. إذا كنت ترغب في إخبار المستخدم بسرعة بشيء حول ما نقر عليه، فقد تكون رسالة النخب خيارًا جيدًا. توضح التعليمات البرمجية التالية كيف يمكن استخدام رسالة منبثقة مع الحدث OnFeatureClick.

//Add a feature click event to the map.
map.events.add((OnFeatureClick) (features) -> {
    //Retrieve the title property of the feature as a string.
    String msg = features.get(0).getStringProperty("title");

    //Display a toast message with the title information.
    Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();

    //Return a boolean indicating if event should be consumed or continue bubble up.
    return false;
}, layer.getId());    //Limit this event to the symbol layer.
//Add a feature click event to the map.
map.events.add(OnFeatureClick { features: List<Feature> ->
    //Retrieve the title property of the feature as a string.
    val msg = features[0].getStringProperty("title")

    //Display a toast message with the title information.
    Toast.makeText(this, msg, Toast.LENGTH_SHORT).show()

    //Return a boolean indicating if event should be consumed or continue bubble up.
    return false
}, layer.getId()) //Limit this event to the symbol layer.

رسوم متحركة لميزة يتم التنصت عليها ورسالة منبثقة يتم عرضها

بالإضافة إلى الرسائل المنبثقة، هناك العديد من الطرق الأخرى لتقديم خصائص بيانات التعريف للميزة، مثل:

  • عنصر واجهة مستخدم - Snackbars Snackbar تقديم ملاحظات خفيفة حول عملية. يعرضون رسالة موجزة في الجزء السفلي من الشاشة على الهاتف المحمول والجزء السفلي الأيسر على الأجهزة الأكبر. Snackbars يظهر فوق جميع العناصر الأخرى على الشاشة ويمكن عرض عنصر واحد فقط في كل مرة.
  • مربعات الحوار - مربع الحوار هو نافذة صغيرة تطالب المستخدم باتخاذ قرار أو إدخال معلومات إضافية. لا يقوم مربع الحوار بملء الشاشة وعادةً ما يستخدم لأحداث الوسائط التي تتطلب من المستخدمين اتخاذ إجراء قبل أن يتمكنوا من المتابعة.
  • أضف جزء إلى النشاط الحالي.
  • انتقل إلى نشاط أو طريقة عرض أخرى.

عرض نافذة منبثقة

يوفر Popup خرائط Azure Android SDK فئة تسهل إنشاء عناصر التعليق التوضيحي لواجهة المستخدم التي تم ارتساؤها إلى موضع على الخريطة. بالنسبة للنوافذ المنبثقة، يجب عليك المرور في عرض مع تخطيط نسبي إلى خيار content من النوافذ المنبثقة. فيما يلي مثال تخطيط بسيط يعرض نصا داكن أعلى خلفية حين.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:orientation="vertical"
    android:background="#ffffff"
    android:layout_margin="8dp"
    android:padding="10dp"

    android:layout_height="match_parent">

    <TextView
        android:id="@+id/message"
        android:layout_width="wrap_content"
        android:text=""
        android:textSize="18dp"
        android:textColor="#222"
        android:layout_height="wrap_content"
        android:width="200dp"/>

</RelativeLayout>

بافتراض تخزين التخطيط أعلاه في ملف يسمى popup_text.xml في مجلد res -> layout التطبيق، تنشئ التعليمات البرمجية التالية نافذة منبثقة، وتضيفها إلى الخريطة. عند النقر فوق ميزة، title يتم عرض الخاصية باستخدام popup_text.xml التخطيط، مع وضع مركز التخطيط السفلي على الموضع المحدد على الخريطة.

//Create a popup and add it to the map.
Popup popup = new Popup();
map.popups.add(popup);

map.events.add((OnFeatureClick)(feature) -> {
    //Get the first feature and it's properties.
    Feature f = feature.get(0);
    JsonObject props = f.properties();

    //Retrieve the custom layout for the popup.
    View customView = LayoutInflater.from(this).inflate(R.layout.popup_text, null);

    //Access the text view within the custom view and set the text to the title property of the feature.
    TextView tv = customView.findViewById(R.id.message);
    tv.setText(props.get("title").getAsString());

    //Get the position of the clicked feature.
    Position pos = MapMath.getPosition((Point)cluster.geometry());

    //Set the options on the popup.
    popup.setOptions(
        //Set the popups position.
        position(pos),

        //Set the anchor point of the popup content.
        anchor(AnchorType.BOTTOM),

        //Set the content of the popup.
        content(customView)

        //Optionally, hide the close button of the popup.
        //, closeButton(false)

        //Optionally offset the popup by a specified number of pixels.
        //pixelOffset(new Pixel(10, 10))
    );

    //Open the popup.
    popup.open();

    //Return a boolean indicating if event should be consumed or continue bubble up.
    return false;
});
//Create a popup and add it to the map.
val popup = Popup()
map.popups.add(popup)

map.events.add(OnFeatureClick { feature: List<Feature> ->
    //Get the first feature and it's properties.
    val f = feature[0]
    val props = f.properties()

    //Retrieve the custom layout for the popup.
    val customView: View = LayoutInflater.from(this).inflate(R.layout.popup_text, null)

    //Access the text view within the custom view and set the text to the title property of the feature.
    val tv: TextView = customView.findViewById(R.id.message)
    tv.text = props!!["title"].asString

    //Get the position of the clicked feature.
    val pos = MapMath.getPosition(f.geometry() as Point?);

    //Set the options on the popup.
    popup.setOptions( 
        //Set the popups position.
        position(pos),  

        //Set the anchor point of the popup content.
        anchor(AnchorType.BOTTOM),  

        //Set the content of the popup.
        content(customView) 

        //Optionally, hide the close button of the popup.
        //, closeButton(false)

        //Optionally offset the popup by a specified number of pixels.
        //pixelOffset(Pixel(10, 10))
    )

    //Open the popup.
    popup.open()

    //Return a boolean indicating if event should be consumed or continue bubble up.
    false
})

يظهر التقاط الشاشة التالي النوافذ المنبثقة التي تظهر عند النقر فوق الميزات والبقاء مرساة إلى موقعها المحدد على الخريطة أثناء تحركها.

رسوم متحركة لنافذة منبثقة يتم عرضها ونقل الخريطة مع تثبيت النافذة المنبثقة إلى موضع على 
الخريطة

الخطوات التالية

لإضافة المزيد من البيانات إلى الخريطة: