إضافة طبقة بثق مضلع إلى الخريطة (Android SDK)
توضح لك هذه المقالة كيفية استخدام طبقة بثق المضلع لعرض مساحات Polygon الأشكال الهندسية والمعالم MultiPolygon كأشكال مقذوفة.
استخدام طبقة بثق مضلع
الاتصال طبقة بثق المضلع إلى مصدر بيانات. ثم ، قم بتحميله على الخريطة. تقوم طبقة بثق المضلع بعرض مساحات a Polygon وميزاتها MultiPolygon كأشكال مقذوفة. height تحدد وخصائص base طبقة بثق المضلع المسافة الأساسية من الأرض وارتفاع الشكل المبثوق بالأمتار. توضح التعليمة البرمجية التالية كيفية إنشاء مضلع وإضافته إلى مصدر بيانات وعرضه باستخدام فئة طبقة بثق المضلع.
ملاحظة
base يجب أن تكون القيمة المحددة في طبقة بثق المضلع أقل من أو تساوي قيمة height.
//Create a data source and add it to the map.
DataSource source = new DataSource();
map.sources.add(source);
//Create a polygon.
source.add(Polygon.fromLngLats(
Arrays.asList(
Arrays.asList(
Point.fromLngLat(-73.958383, 40.800279),
Point.fromLngLat(-73.981547, 40.768459),
Point.fromLngLat(-73.981246, 40.767761),
Point.fromLngLat(-73.973618, 40.764616),
Point.fromLngLat(-73.973060, 40.765128),
Point.fromLngLat(-73.972599, 40.764908),
Point.fromLngLat(-73.949446, 40.796584),
Point.fromLngLat(-73.949661, 40.797088),
Point.fromLngLat(-73.957815, 40.800523),
Point.fromLngLat(-73.958383, 40.800279)
)
)
));
//Create and add a polygon extrusion layer to the map below the labels so that they are still readable.
PolygonExtrusionLayer layer = new PolygonExtrusionLayer(source,
fillColor("#fc0303"),
fillOpacity(0.7f),
height(500f)
);
//Create and add a polygon extrusion layer to the map below the labels so that they are still readable.
map.layers.add(layer, "labels");
//Create a data source and add it to the map.
val source = DataSource()
map.sources.add(source)
//Create a polygon.
source.add(
Polygon.fromLngLats(
Arrays.asList(
Arrays.asList(
Point.fromLngLat(-73.958383, 40.800279),
Point.fromLngLat(-73.981547, 40.768459),
Point.fromLngLat(-73.981246, 40.767761),
Point.fromLngLat(-73.973618, 40.764616),
Point.fromLngLat(-73.973060, 40.765128),
Point.fromLngLat(-73.972599, 40.764908),
Point.fromLngLat(-73.949446, 40.796584),
Point.fromLngLat(-73.949661, 40.797088),
Point.fromLngLat(-73.957815, 40.800523),
Point.fromLngLat(-73.958383, 40.800279)
)
)
)
)
//Create and add a polygon extrusion layer to the map below the labels so that they are still readable.
val layer = PolygonExtrusionLayer(
source,
fillColor("#fc0303"),
fillOpacity(0.7f),
height(500f)
)
//Create and add a polygon extrusion layer to the map below the labels so that they are still readable.
map.layers.add(layer, "labels")
تعرض لقطة الشاشة التالية التعليمة البرمجية أعلاه التي تعرض مضلعا ممتدا عموديا باستخدام طبقة بثق مضلع.

إضافة مضلعات مستندة إلى البيانات
يمكن تقديم خريطة choropleth باستخدام طبقة بثق المضلع. height اضبط وخصائص fillColor طبقة البثق على قياس المتغير الإحصائي في Polygon هندسة المعالم والميزاتMultiPolygon. تعرض عينة التعليمات البرمجية التالية خريطة choropleth مقذوفة للولايات المتحدة بناء على قياس الكثافة السكانية حسب الولاية.
//Create a data source and add it to the map.
DataSource source = new DataSource();
//Import the geojson data and add it to the data source.
source.importDataFromUrl("https://azuremapscodesamples.azurewebsites.net/Common/data/geojson/US_States_Population_Density.json");
//Add data source to the map.
map.sources.add(source);
//Create and add a polygon extrusion layer to the map below the labels so that they are still readable.
PolygonExtrusionLayer layer = new PolygonExtrusionLayer(source,
fillOpacity(0.7f),
fillColor(
step(
get("density"),
literal("rgba(0, 255, 128, 1)"),
stop(10, "rgba(9, 224, 118, 1)"),
stop(20, "rgba(11, 191, 103, 1)"),
stop(50, "rgba(247, 227, 5, 1)"),
stop(100, "rgba(247, 199, 7, 1)"),
stop(200, "rgba(247, 130, 5, 1)"),
stop(500, "rgba(247, 94, 5, 1)"),
stop(1000, "rgba(247, 37, 5, 1)")
)
),
height(
interpolate(
linear(),
get("density"),
stop(0, 100),
stop(1200, 960000)
)
)
);
//Create and add a polygon extrusion layer to the map below the labels so that they are still readable.
map.layers.add(layer, "labels");
//Create a data source and add it to the map.
val source = DataSource()
//Import the geojson data and add it to the data source.
source.importDataFromUrl("https://azuremapscodesamples.azurewebsites.net/Common/data/geojson/US_States_Population_Density.json")
//Add data source to the map.
map.sources.add(source)
//Create and add a polygon extrusion layer to the map below the labels so that they are still readable.
val layer = PolygonExtrusionLayer(
source,
fillOpacity(0.7f),
fillColor(
step(
get("density"),
literal("rgba(0, 255, 128, 1)"),
stop(10, "rgba(9, 224, 118, 1)"),
stop(20, "rgba(11, 191, 103, 1)"),
stop(50, "rgba(247, 227, 5, 1)"),
stop(100, "rgba(247, 199, 7, 1)"),
stop(200, "rgba(247, 130, 5, 1)"),
stop(500, "rgba(247, 94, 5, 1)"),
stop(1000, "rgba(247, 37, 5, 1)")
)
),
height(
interpolate(
linear(),
get("density"),
stop(0, 100),
stop(1200, 960000)
)
)
)
//Create and add a polygon extrusion layer to the map below the labels so that they are still readable.
map.layers.add(layer, "labels")
تظهر لقطة الشاشة التالية خريطة choropleth للولايات الأمريكية ملونة وممتدة عموديا كمضلعات مقذوفة بناء على الكثافة السكانية.

الخطوات التالية
راجع المقالات التالية للحصول على مزيد من نماذج التعليمات البرمجية لإضافتها إلى خرائطك: