Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
edited tags
Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345
Source Link

Label shapefile by attribute in Google Earth Engine

I have imported a shapefile of points into Google Earth Engine but am unable to find information on how to label them by their assigned number in the attribute table. I saw a related thread but the code provided was not successful. This is what I have tried:

// Step 7) Add GRTs points to map
var styling = {color: 'orange', fillColor: '00000000'};
Map.addLayer(HCSR_MgmtGRTs.style(styling), HCSR_MgmtGRTs, "HCSR GRTS");

// Step 8) Label points
var text = require('users/gena/packages:text')
// scale text font relative to the current map scale
var scale = Map.getScale() * 1

var labels = HCSR_MgmtGRTs.map(function(feat) {
  feat = ee.Feature(feat)
  var number = ee.String(feat.get("NUMBER"))
  var centroid = feat.geometry().centroid()
  var t = text.draw(number, centroid, scale, {
    fontSize:18, 
    textColor:'orange',
    outlineWidth: 1,
    outlineColor: 'orange'
  })
  return t
})

labels = ee.ImageCollection(labels)
Map.addLayer(labels)

It runs without error, but I am not seeing any labels on my points. I am a beginner, so an easy explanation would be helpful!