sakitam-fdd / wind-layer

:flags: :rocket: wind-layer | a openlayers && maptalks && amap && bmap && leaflet && mapbox-gl && maplibre-gl extension like windy.com for weather visualization
https://sakitam-fdd.github.io/wind-layer/
Other
510 stars 139 forks source link

wind layer bounds decrease as zoom increases #185

Open crawld opened 10 months ago

crawld commented 10 months ago

I'm using wind-layer with mapbox-gl to draw a wind field over a small area. At low zoom levels, it looks correct, but when I increase the zoom, the layer is not drawn at the bottom.

This image shows the layer over the correct area, and is covering the black polygon: image

But once I zoom in, the layer no longer covers the area. Here the layer does not cover the bottom of the black polygon: image

The layer seems to shrink the more I zoom in.

sakitam-fdd commented 10 months ago

@crawld It would be a good idea to provide an example, in fact the example in the example file has had some other processing done to avoid example rendering problems when zooming in on the map,See https://blog.sakitam.com/wind-layer/guide/#windcore-%E5%8F%82%E6%95%B0%E8%AF%B4%E6%98%8E for details on the velocityScale parameter

https://codepen.io/sakitam-fdd/pen/GRpeeGG?editors=1010

crawld commented 10 months ago

Here's how I create wind-layer:

this._windLayer = new WindLayer('wind', [
                {
                    "header": {
                        "parameterCategory": 1,
                        "parameterNumber": 2,
                        "dx": dx,
                        "dy": dy,
                        "nx": 1,
                        "ny": 1,
                        "la1": bounds[3],
                        "la2": bounds[1],
                        "lo1": bounds[0],
                        "lo2": bounds[2],
                    },
                    "data": [
                        wind_u,
                    ]
                },
                {
                    "header": {
                        "parameterCategory": 1,
                        "parameterNumber": 3,
                        "dx": dx,
                        "dy": dy,
                        "nx": 1,
                        "ny": 1,
                        "la1": bounds[3],
                        "la2": bounds[1],
                        "lo1": bounds[0],
                        "lo2": bounds[2]
                    },
                    "data": [
                        wind_v,
                    ]
                }
            ],
            {
                windOptions: {
                    frameRate: 16,
                    maxAge: 60,
                    globalAlpha: 0.9,
                    velocityScale: () => {
                        const zoom = parseInt(this._map.getZoom());
                        return this._velocityScales[zoom] || 1 / 40;
                    },
                    paths: 200,
                },
            });

There is only a single value in the u/v data since I want a constant wind direction and speed over the domain.

crawld commented 10 months ago

I'm using mapbox-gl 2.8.0. When I switch to 1.8.0 (used by @sakitam-gis/mapbox-wind) the problem does not occur. Have you tested with mapbox-gl 2.x?

sakitam-fdd commented 10 months ago

@crawld I haven't tested mapbox-gl 2.x in detail, but I'm guessing that you want the particle velocity to be moving at a constant rate, so you should configure velocityScale to be a fixed value (since constant velocity * time per unit = geographic distance traveled is fixed in the normal case, then the map will see the particles moving faster when zoomed in), configured as a function This is for demonstration purposes, as the movement of the example will be linear at a large level.

crawld commented 10 months ago

Thanks @sakitam-fdd. The particle velocity is not important at different zoom levels for my use case. It's much more important that particles are drawn over the area for all zoom levels.

sakitam-fdd commented 10 months ago

@crawld Can you easily attach a minimal example? it seems to look fine when I test it under 2.15.0 https://codepen.io/sakitam-fdd/pen/gOZMEXb

crawld commented 4 months ago

Did this get fixed? I found it only seem to occur when 3d terrain was enabled.

sakitam-fdd commented 4 months ago

@crawld Very sorry, currently all layers in Mapbox cannot be used with terrain or non Mercator projections;Before the mapbox official release of more APIs, all implementations were very difficult