swiped and modified from https://github.com/nutiteq/hellomap3d/tree/master/AdvancedMap3D