คุณสามารถเพิ่มคอลเล็กชันองค์ประกอบลงในแผนที่ได้โดยตรงด้วย Map.addLayer()
เช่นเดียวกับรูปภาพ เรขาคณิต และองค์ประกอบ ภาพข้อมูลที่แสดงโดยค่าเริ่มต้นจะแสดงเวกเตอร์ด้วยเส้นสีดําทึบและสีดําทึบครึ่งหนึ่ง หากต้องการแสดงผลเวกเตอร์เป็นสี ให้ระบุพารามิเตอร์ color
ข้อมูลต่อไปนี้แสดงเขตนิเวศ "RESOLVE" (Dinerstein et al. 2017) เป็นการแสดงภาพเริ่มต้นและสีแดง
เครื่องมือแก้ไขโค้ด (JavaScript)
// Load a FeatureCollection from a table dataset: 'RESOLVE' ecoregions. var ecoregions = ee.FeatureCollection('RESOLVE/ECOREGIONS/2017'); // Display as default and with a custom color. Map.addLayer(ecoregions, {}, 'default display'); Map.addLayer(ecoregions, {color: 'FF0000'}, 'colored');
import ee import geemap.core as geemap
Colab (Python)
# Load a FeatureCollection from a table dataset: 'RESOLVE' ecoregions. ecoregions = ee.FeatureCollection('RESOLVE/ECOREGIONS/2017') # Display as default and with a custom color. m = geemap.Map() m.set_center(-76.2486, 44.8988, 8) m.add_layer(ecoregions, {}, 'default display') m.add_layer(ecoregions, {'color': 'FF0000'}, 'colored') m
หากต้องการดูตัวเลือกการแสดงผลเพิ่มเติม ให้ใช้ featureCollection.draw()
กล่าวโดยละเอียดคือพารามิเตอร์ pointRadius
และ strokeWidth
จะควบคุมขนาดของจุดและเส้นใน FeatureCollection
ที่แสดงผล ดังนี้
เครื่องมือแก้ไขโค้ด (JavaScript)
Map.addLayer(ecoregions.draw({color: '006600', strokeWidth: 5}), {}, 'drawn');
import ee import geemap.core as geemap
Colab (Python)
m.add_layer(ecoregions.draw(color='006600', strokeWidth=5), {}, 'drawn')
เอาต์พุตของ draw()
คือรูปภาพที่มีแถบสีแดง เขียว และน้ำเงินตามพารามิเตอร์ color
ที่ระบุ
หากต้องการควบคุมวิธีแสดง FeatureCollection
ได้มากขึ้น ให้ใช้ image.paint()
โดยให้ FeatureCollection
เป็นอาร์กิวเมนต์ ซึ่งแตกต่างจาก draw()
ที่แสดงผลรูปภาพ 8 บิต 3 ย่าน image.paint()
จะแสดงผลรูปภาพที่มีค่าตัวเลขที่ระบุ "วาด" ไว้ หรือจะระบุชื่อพร็อพเพอร์ตี้ใน FeatureCollection
ที่มีตัวเลขที่จะระบายสีก็ได้ พารามิเตอร์ width
จะทํางานในลักษณะเดียวกัน อาจเป็นค่าคงที่หรือชื่อพร็อพเพอร์ตี้ที่มีตัวเลขสําหรับความกว้างของเส้นก็ได้ เช่น
เครื่องมือแก้ไขโค้ด (JavaScript)
// Create an empty image into which to paint the features, cast to byte. var empty = ee.Image().byte(); // Paint all the polygon edges with the same number and width, display. var outline = empty.paint({ featureCollection: ecoregions, color: 1, width: 3 }); Map.addLayer(outline, {palette: 'FF0000'}, 'edges');
import ee import geemap.core as geemap
Colab (Python)
# Create an empty image into which to paint the features, cast to byte. empty = ee.Image().byte() # Paint all the polygon edges with the same number and width, display. outline = empty.paint(featureCollection=ecoregions, color=1, width=3) m.add_layer(outline, {'palette': 'FF0000'}, 'edges')
โปรดทราบว่าต้องแคสต์รูปภาพว่างเปล่าที่จะวาดองค์ประกอบก่อนวาด เนื่องจากรูปภาพแบบคงที่จะทำงานแบบคงที่ กล่าวคือจะยึดตามค่าเริ่มต้น หากต้องการระบายสีขอบขององค์ประกอบด้วยค่าที่ตั้งค่าจากพร็อพเพอร์ตี้ขององค์ประกอบ ให้ตั้งค่าพารามิเตอร์สีเป็นชื่อพร็อพเพอร์ตี้ที่มีค่าตัวเลข ดังนี้
เครื่องมือแก้ไขโค้ด (JavaScript)
// Paint the edges with different colors, display. var outlines = empty.paint({ featureCollection: ecoregions, color: 'BIOME_NUM', width: 4 }); var palette = ['FF0000', '00FF00', '0000FF']; Map.addLayer(outlines, {palette: palette, max: 14}, 'different color edges');
import ee import geemap.core as geemap
Colab (Python)
# Paint the edges with different colors, display. outlines = empty.paint(featureCollection=ecoregions, color='BIOME_NUM', width=4) palette = ['FF0000', '00FF00', '0000FF'] m.add_layer(outlines, {'palette': palette, 'max': 14}, 'different color edges')
คุณกำหนดทั้งสีและความกว้างของเส้นขอบได้ด้วยพร็อพเพอร์ตี้ เช่น
เครื่องมือแก้ไขโค้ด (JavaScript)
// Paint the edges with different colors and widths. var outlines = empty.paint({ featureCollection: ecoregions, color: 'BIOME_NUM', width: 'NNH' }); Map.addLayer(outlines, {palette: palette, max: 14}, 'different color, width edges');
import ee import geemap.core as geemap
Colab (Python)
# Paint the edges with different colors and widths. outlines = empty.paint( featureCollection=ecoregions, color='BIOME_NUM', width='NNH' ) m.add_layer( outlines, {'palette': palette, 'max': 14}, 'different color, width edges' )
หากไม่ได้ระบุพารามิเตอร์ width
ระบบจะทาสีภายในของสถานที่ดังนี้
เครื่องมือแก้ไขโค้ด (JavaScript)
// Paint the interior of the polygons with different colors. var fills = empty.paint({ featureCollection: ecoregions, color: 'BIOME_NUM', }); Map.addLayer(fills, {palette: palette, max: 14}, 'colored fills');
import ee import geemap.core as geemap
Colab (Python)
# Paint the interior of the polygons with different colors. fills = empty.paint(featureCollection=ecoregions, color='BIOME_NUM') m.add_layer(fills, {'palette': palette, 'max': 14}, 'colored fills')
หากต้องการแสดงผลทั้งภายในและขอบขององค์ประกอบ ให้วาดรูปภาพเปล่า 2 ครั้ง ดังนี้
เครื่องมือแก้ไขโค้ด (JavaScript)
// Paint both the fill and the edges. var filledOutlines = empty.paint(ecoregions, 'BIOME_NUM').paint(ecoregions, 0, 2); Map.addLayer(filledOutlines, {palette: ['000000'].concat(palette), max: 14}, 'edges and fills');
import ee import geemap.core as geemap
Colab (Python)
# Paint both the fill and the edges. filled_outlines = empty.paint(ecoregions, 'BIOME_NUM').paint(ecoregions, 0, 2) m.add_layer( filled_outlines, {'palette': ['000000'] + palette, 'max': 14}, 'edges and fills', )