Leaflet.TimeDimension icon indicating copy to clipboard operation
Leaflet.TimeDimension copied to clipboard

How to get the timestamp for the given slider event so that I can show the weather?

Open maddan opened this issue 6 years ago • 2 comments

Hi, I'm using Leaflet framework. For weather data, I'm using Open Weather Map api. However, for the slider I'm using nowCoast (NOAA). I'm using the Leaflet.TimeDimension and while dragging the slider, I have to update the marker metadata in my map. How do I do that? Did I miss any important documentation? Please help.

Here's my Leaflet map instance:

var map = L.map('map', {
				layers: [osmMap], // only add one!
				fullscreenControl: true,	// Fullscreen map
				timeDimension: true,
				timeDimensionControl: true,
				timeDimensionOptions:{
					//timeInterval: "PT4H/" + endDate.toISOString(),
					timeInterval: "2019-05-16/2019-05-20",
					period: "PT4M",
					currentTime: endDate
				},    
				
				timeDimensionControlOptions: {
					autoPlay: false,
					playerOptions: {
						buffer: 10,
						transitionTime: 250,
						loop: true,
					}
				},
		    })
			.setView([latVal, lngVal], 10);

Based on where the user slides, I need to update my marker (weather data) as I slide the slider given that timestamp.

maddan avatar May 16 '19 21:05 maddan

If I understood your question correctly, you need to extract the exact time on the display bar?

It's a simple need, intuitively, but made me ponder over it for a few days. The timeDimension is super attractive but anything slightly out of the ordinary comes with a price.

Anyways, try the following: (1) use the moment js lib for formatting purposes You may find on CDN or drop me an email cdnjs.cloudflare.com/ajax/libs/moment.js/2.7.0/moment.min.js

(2) extract/format the date as suited to your needs: map.timeDimension.on('timeload', function (data) { var nowTime = map.timeDimension.getCurrentTime(); var tzoffset = (new Date()).getTimezoneOffset() * 60000; var localISOTime = (new Date(new Date(nowTime) - tzoffset)).toISOString().slice(0, -1); _this_YYYY_MM_DD_stamp = moment(localISOTime).format(returnDateFormat_YYYY_MM_DD_dataFetch);}, this);

BTW, I am also conceptualizing an Ocean Viewer for NOAA.

Hope this helps.

DrPDash avatar May 18 '19 21:05 DrPDash

You are right! It looks great to use it but really hard to customize it. Let me try your suggestion. Thanks!

maddan avatar May 20 '19 17:05 maddan