Fix #1123: 'Unexpected function' error

Error being caused because PHP5.2- don't support anonymous function. Another error being thrown when more than one "Specific area" location was used due to function re-declaration in the loop.

Moved flatten() and collapse_points() to WKT object to clean the view. Replaced flatten() code to use a recursive call instead of an anonymous function.