melowntech / vts-browser-js

JavaScript WebGL 3D map rendering engine
BSD 2-Clause "Simplified" License
220 stars 42 forks source link

How to decide the exact altitude of custom objects? #182

Closed SukanyaGavhane closed 4 years ago

SukanyaGavhane commented 4 years ago

I found that currently, we can give a hardcoded altitude (height) value to the object to be drawn on the surface of the earth, and we need to change the altitude value every time from code.

Is there Any API which provide the rough height to draw the object just above the earth surface? For Example-if we give some height to the objects at one location and if we let's say changed the location and there is a mountain and our geometry goes inside the mountain but we want it on top of the mountain. Please find the below link as a reference: https://jsfiddle.net/2ox3wkb4/11/

If no, could you please suggest some method to achieve the same? Any inputs would be really appreciated!

davidmtech commented 4 years ago

API provides concept of height modes. There are two height modes: fixed and float. Fixed means absolute height. Float means relative height above terrain. Several API functions which works with position or conversion of coordinates support this height modes. So when you use coordinate with zero height and float height mode, then resulting coordinates should lay on the ground. But this method is far from perfect, because we only have low resolution height map for determination of the height of the terrain. So resulting height may be little bit above or below rendered terrain. Other drawback is that height map is loaded gradually and this can lead to the effect that model is jumping on the terrain until best resolution height map is loaded (when float height mode is used). Unfortunately there is no easy way how to fix it.

There are API functions which can be useful: https://github.com/melowntech/vts-browser-js/wiki/VTS-Browser-Map-API#methods-for-conversions

These examples use float height mode for conversion of coordinates: https://jsfiddle.net/Lrtz5bem/ https://jsfiddle.net/Lzb2o5uj/ https://jsfiddle.net/me4od59f/