How do I query the current layer sorting in the map and change it?
Aside from a couple exceptions, the order in which layers are drawn is the same as the order in which layers are found in the Map.allLayers property. Changing the order of layers is made possible through the Map.reorder method,
As for the exceptions, see the notes in the documentation for the allLayers property and the reorder method, both of which are hyperlinked above.