Map map = editor.getCurrentMap();
int layerIndex = editor.getCurrentLayerIndex();
int totalLayers = map.getTotalLayers();
if (layerIndex >= 0) {
map.removeLayer(layerIndex);
// If the topmost layer was selected, the layer index is invalid
// after removing that layer. The right thing to do is to reset it
// to the new topmost layer.
if (layerIndex == totalLayers - 1) {