Local electronic and optical phenomena in two-dimensional materials