Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Time controller issue #234

Open
GeoTuxMan opened this issue Jan 17, 2025 · 0 comments
Open

Time controller issue #234

GeoTuxMan opened this issue Jan 17, 2025 · 0 comments

Comments

@GeoTuxMan
Copy link

I have a map with Black Sea currents https://syroco.rmri.ro/earth/index.html

When I click on Black Sea Currents layer, the map it's ok, but when I click on play button (from time controller) the map it's empty.

I have a function for split data into 24 parts (one per hour), so when I click on play button, the map need to change content (loop through all 24 parts).

             ` 
            function splitDataInto24Parts(data) {
                const numParts = 24;
                const partSize = Math.floor(data.length / numParts);
                const splitData = [];

                for (let i = 0; i < numParts; i++) {
                  const start = i * partSize;
                  const end = (i + 1) * partSize;
                  splitData.push(data.slice(start, end));
               }

                return splitData;
          }`

My currents data it's in json format:
[
{"header": {"parameterUnit":"m/","parameterNumber":2,"dx":0.02500000000000001,"dy":0.025000000000000015,"time":"2024-12-17T00:00:00.000Z","parameterCategory":2,"nx":578,"ny":258,"la1":47.325,"lo1":27.4,"sign":1}, "data": [0.0,....]
,
{"header": {"parameterUnit":"m/","parameterNumber":3,"dx":0.02500000000000001,"dy":0.025000000000000015,"time":"2024-12-17T00:00:00.000Z","parameterCategory":2,"nx":578,"ny":258,"la1":47.325,"lo1":27.4,"sign":1}, "data": [0.0,....]
]
Code for load json file:

                        `
                          $.getJSON(fileName, function(data) {
                           const splitData = splitDataInto24Parts(data);

                           var velocityLayer = L.velocityLayer({
                             displayValues: true,
                            displayOptions: {
                            velocityType: "Currents",
                            position: "bottomleft",
                             emptyString: "No water data"
                             },
                         velocityOptions: {
                             particleMultiplier: 1
                              },
                             data: data,
                         minVelocity: -0.44,
                             maxVelocity: 0.26,
                         velocityScale: 0.3

                          });

                          layerControl.addOverlay(velocityLayer, "Black Sea Currents");

                          // Update the data when the time changes
                         map.timeDimension.on("timeload", function(event) {
                        const currentTimeIndex = map.timeDimension.getCurrentTimeIndex();
                        velocityLayer.setData(splitData[currentTimeIndex]);
                        });
                       });`

I am looking forward to any advice or ideas.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant