Topic: Some problem extending the horizon

Hello,
I'm following your tutorial to create an horizon
https://www.youtube.com/watch?v=qDg1nsN2tp0

I have 2 problems:

1 - it seem that you use Mapbox for the horizon elevation, but I'm using Bing, because Mapbox elevation data are totally wrong (at least in my area).
Is it possible to use Bing elevation instead of Mapbox with Horizon script?

2 - I'm using ArcGIS for map texture (it's the best quality at least in my area), using Horizon script (with Mapbox elevation) when I press Play not only the horizon but also my "main" map get totally blurred, it seem that is "covered" by the blurred one.
What I'm doing wrong?

Many thanks

Re: Some problem extending the horizon

Hello.

1. Theoretically - yes.
Practically - this script was created to work with Mapbox Elevation, and it is much easier to write a new script than to modify this one.
2. Reduce Position Y Offset. For example, set "-15" instead of "-5".

Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.

3 (edited by danielesuppo 2019-05-20 00:23:18)

Re: Some problem extending the horizon

As you suggested reducing the Y Offset did the trick, but It's so different from Bing elevation that I had to reduce it to -95 (!!).
And, when I increase the map zoom level, the Mapbox horizon overlay again the "standard" map (with Bing elevation), just because it's so much different (Mapbox elevation data seem to be a lot scaled on Y axis).
Since it's really a shame not to be able to extend the horizon (it look way better), I tried again to use Mapbox, instead of Bing, for elevation but

1) with "OnlineMapsMapboxElevationManager" (instead of "OnlineMapsBingMapsElevationManager") I don't receive OnlineMapsElevationManagerBase.OnElevationUpdated" event.

I've subscribed a function in my class to "OnElevationUpdated" in this way:
private void Start()
    {
        OnlineMapsElevationManagerBase.instance.OnElevationUpdated += MyFunction;
    }

but with "OnlineMapsMapboxElevationManager" script I don't get this event (with "OnlineMapsBingMapsElevationManager" I get it).


2) since Mapbox elevation data seem to be wrong, or too scaled, I don't know, at least in my area, I'd really like to be able to use Bing elevation data for the horizon.
I gave a look to Horizon2_OM3 script, but honestly I don't know how to modify it for Bing.
I know that to write a new script is quite an effort, but... any chances to have this script for Bing?
Maybe, could you write me a private message to talk about it?


3) I'm a bit confused how to use Google for elevation data (that, maybe, would be the best solution).
All the Google scripts must derive from Monobehaviour, so... how to use Google for elevation?


Many thanks!

Re: Some problem extending the horizon

1. This script was created in the original for Online Maps v2, where elevations were only from Bing Maps.
So this requires OnlineMapsBingMapsElevationManager.

2. Yes, I will try to write for you a script using Bing Maps.
It will take some time. I think 1-2 weeks.
If you need private support, you can email me (support@infinity-code.com).

3. Google Elevation API cannot return elevations for an area.
Only for line or point.
Encode 1024 points in one request is very inconvenient.
So using Google Elevation API is a bad way.

Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.

Re: Some problem extending the horizon

1 - I see
2 - I'm really grateful for it!
3 - I see

Thanks a lot

Re: Some problem extending the horizon

Hello.

Horizon 2 for Bing Maps is attached.

Post's attachments

Attachment icon Horizon2_BingMaps.cs 12.14 kb, 124 downloads since 2019-05-29 

Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.

7 (edited by danielesuppo 2019-06-01 15:41:25)

Re: Some problem extending the horizon

Many thanks!!!!
The only issue is that does not have elevation, and if it's active at Start also the main map does not get elevation

Re: Some problem extending the horizon

Unfortunately, I did not understand what you mean.

https://i.ibb.co/zrjg0G1/img1.png

Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.

Re: Some problem extending the horizon

I have a different behaviour...
(picture in attachment)

Post's attachments

Attachment icon Untitled-1.jpg 313.76 kb, 105 downloads since 2019-06-04 

Re: Some problem extending the horizon

The problem is that you specified the key in Bing Maps Elevation Manager, and the script uses a key from Key Manager.
Improved version of the script is attached.
Now it does not matter where you specified the key, when you enabled the script, and fixed the problem with a large number of parallel requests.

Post's attachments

Attachment icon Horizon2_BingMaps.cs 13.97 kb, 121 downloads since 2019-06-04 

Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.

11 (edited by danielesuppo 2019-06-04 16:35:24)

Re: Some problem extending the horizon

Yes, now it's working!
But... I still have a couple of issue... sorry...

1 - The horizon seem to me to use a different map zoom level, indeed as you can see in the 1st picture in attachment the texture is very different. If I zoom more, then the horizon seem to get the right texture, but it seem to be not "syncronized" with the regular map. I've tried to increase the resolution of the horizon (128) to see if it could help but it turn totally wrong.

2 - the elevation of the horizon seem to me a bit unstable. I had to offset on Y axis at -200 to not have it over the map, and still when I zoom the map it overlap is some areas the map, and zooming in or out it "jump" up and down, over and under the map, very quickly a few times

P.s. I'm using "Bottom mode --> Min Value" in Elevation Manager

Thanks a lot!

Post's attachments

Attachment icon 01.jpg 126.96 kb, 99 downloads since 2019-06-04 

Re: Some problem extending the horizon

1.1. Different zoom levels are a fundamental problem for such scripts.
It is impossible to solve or work around.
You need to find the right style and / or zoom where it is not visible.
1.2. Problem with resolution fixed.
2.1. The problem that the horizon is sometimes above the map fixed.
2.2. Problem with Bottom mode - Min Value fixed.
2.3. The problem with jumping elevations is not fixed.
This script is not designed for changing zoom.
Mapbox returns 256x256 elevations of values that are not counted in the quota. Bing Maps returns only 32x32 values.
If make requests for all the tiles, you will burn your quota very quickly.
So requests are made only for the required tiles.

I have an idea how to work around this (2.3).
But it takes some time to develop.
I think 1-2 days.

Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.

Re: Some problem extending the horizon

It was difficult, but it seems like I made it work.

Post's attachments

Attachment icon Horizon2_BingMaps.cs 20.78 kb, 121 downloads since 2019-06-09 

Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.

Re: Some problem extending the horizon

Hi, There is  a script using ArcGIS for horizon elevation ? Thank you

Re: Some problem extending the horizon

Hello.

Something like that.

Post's attachments

Attachment icon Horizon2_ArcGIS.cs 22.62 kb, 124 downloads since 2019-06-14 

Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.

Re: Some problem extending the horizon

nice
thank youuuuuuuu

Re: Some problem extending the horizon

Thanks a lot for your effort, it work!
I'd have just 2 more question:

1 - is there a way to tell the script at which distance from the camera the horizon should appear?
I try to explain better: in some situations the script create more horizon tiles on the back of the camera, and not in front.
As a result panning the Camera the orizon disappear, but as you move forward a little the new horizon tile appear (see pict in attachment).
I think that's some kind of optimization, so I'm wondering if it is possible to tell ("hey, I always want an horizon tile in front of the Camera... or something like that)

2 - Is it possible to get the elevation on the horizon tiles ? I have a very long path, and the piece of the path that is outside of the map does not get elevation

Many thanks!

Post's attachments

Attachment icon Untitled-1.jpg 11.64 kb, 95 downloads since 2019-06-17 

Re: Some problem extending the horizon

1 - I've partially solved this issue increasing count to 5x5

Re: Some problem extending the horizon

1. This is the specificity of the script.
This is not to optimize, but to simplify the script.
As it is, you cannot say - I want to have a front tile.

2. Something like this:

using UnityEngine;

public class GetElevationFromHorizon : MonoBehaviour
{
    public Horizon2_BingMaps horizon;
    private OnlineMaps map;
    private OnlineMapsTileSetControl control;

    private void Start()
    {
        map = OnlineMaps.instance;
        control = OnlineMapsTileSetControl.instance;
    }

    private void Update()
    {
        Vector2 size = control.sizeInScene;
        float el = GetElevation(new Vector3(size.x / -2, 0, size.y / 2));
        Debug.Log(el);
    }

    private float GetElevation(Vector3 pos)
    {
        double lng, lat;
        control.GetCoordsByWorldPosition(out lng, out lat, pos);

        float elevation = 0;
        if (GetElevationFromTile(lng, lat, ref elevation)) return elevation;

        if (Horizon2_BingMaps.overviewElevation == null) return 0;

        double mx = lng, my = lat;
        OnlineMapsUtils.LatLongToMercat(ref mx, ref my);
        elevation = Horizon2_BingMaps.overviewElevation.GetElevation(mx, my);
        return elevation;
    }

    private bool GetElevationFromTile(double lng, double lat, ref float elevation)
    {
        double tx, ty;
        int zoom = map.zoom - horizon.zoomOffset;
        map.projection.CoordinatesToTile(lng, lat, zoom, out tx, out ty);
        OnlineMapsTile tile = OnlineMapsTile.GetTile(zoom, (int) tx, (int) ty);
        if (tile == null) return false;
        Horizon2_BingMaps.CData data = tile["cdata"] as Horizon2_BingMaps.CData;
        if (data == null) return false;
        if (!data.hasData) return false;
        elevation = data.GetElevation(tx, ty);
        return true;
    }
}

P.S. Make Horizon2_BingMaps.overviewElevation as internal.

Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.

Re: Some problem extending the horizon

Thank-you!
So if I well understand I can use "GetElevation" from this class, in place of "GetWorldPositionWithElevation", for every object I want to get elevation, for both objects onto the Map and objects onto the Horizon, isn't it?

Re: Some problem extending the horizon

Yes, it is, because this script already controls elevations of the map.

Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.

22 (edited by danielesuppo 2019-07-30 12:31:10)

Re: Some problem extending the horizon

Hello,
I'm using your script to get the elevation from the horizon but I have some issue... the points are much more over the map and the horizon, them fly in the sky.

I use this function to get XZ position, and next Y position from an array of longLat:

private Vector3[] GetWorldPositionsFromHorizon(Vector2[] _coords)
    {
        Vector3[] positions = new Vector3[_coords.Length];

        for (int ii = 0; ii < _coords.Length; ii++)
        {
            ///Get X-Z position
            Vector3 flatPosition = OnlineMapsTileSetControl.instance.GetWorldPosition
                (_coords[ii]);

            ///Get Y position (elevation)
            float elevation = GetElevationFromHorizon.instance.GetElevation(_coords[ii]);
            positions[ii] = new Vector3(flatPosition.x, elevation, flatPosition.z);
        }
        return positions;
    }

And your script just a little modified because I already have the longitude latitude of my point:

public float GetElevation(Vector2 longLat)
    {
        double lng = longLat.x;
        double lat = longLat.y;

        float elevation = 0;
        if (GetElevationFromTile(lng, lat, ref elevation)) return elevation;

        if (Horizon2_BingMaps.overviewElevation == null) return 0;

        double mx = lng, my = lat;
        OnlineMapsUtils.LatLongToMercat(ref mx, ref my);
        elevation = Horizon2_BingMaps.overviewElevation.GetElevation(mx, my);
        return elevation;
    }


As you can see in the attached picture in top view (orthographic) the shape created with my points is ok, so X and Z are right.
The elevation (Y) is wrong

Post's attachments

Attachment icon ISSUE.jpg 53.66 kb, 100 downloads since 2019-07-30 

Re: Some problem extending the horizon

Because elevation != position.y.
How to calculate position.y:

float elevationScale = OnlineMapsElevationManagerBase.GetBestElevationYScale(tlx, tly, brx, bry);

float elevationOffset = 0;
if (OnlineMapsElevationManagerBase.isActive && OnlineMapsElevationManagerBase.instance.bottomMode == OnlineMapsElevationBottomMode.minValue)
{
    elevationOffset = OnlineMapsElevationManagerBase.instance.GetMinElevation(1);
}

position.y = (elevation - elevationOffset) * elevationScale;
Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.

Re: Some problem extending the horizon

Thank-you!!
Do all these methods (GetWorldPosition, GetElevation, etc) require a lot more of CPU than just to use GetWorldPositionWithElevation?

(Since I call GetWorldPositionsFromHorizon for each vertex in my track line when the map is panned or zoomed I'm worrying about performance issue)

Re: Some problem extending the horizon

If you use these methods every time the map is updated, you will most likely have performance problems.
Here you need to use some optimization trick, for example:
You do a full update of the track only when updating elevations and changing the zoom, and when moving the map, you simply calculate the offset for the first point, and apply this offset for the remaining points.

It can also help:
- Track optimization (reducing the number of points).
- Caching values that are used in calculations.
- The use of overloaded methods, with a large number of parameters.

Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.