在 Leaflet 中以特定值启动 JQuery UI Slider
Posted
技术标签:
【中文标题】在 Leaflet 中以特定值启动 JQuery UI Slider【英文标题】:start JQuery UI Slider at specific value in Leaflet 【发布时间】:2017-10-05 22:47:04 【问题描述】:我正在使用这个 LeafletSlider 库在 Leaflet 中滑过多个层,每个层都有一个最接近半小时的关联时间。我想在最接近最近时间的数据点启动滑块。
在SliderControl.js,我替换了
var index_start = _options.minValue;
与
var now = new Date();
var hour = now.getHours();
var minutes = now.getMinutes();
if (minutes < 15)
minutes = "00";
else if (minutes < 45)
minutes = "30";
else
minutes = "00";
++hour;
var time = hour + minutes;
var times = ["000", "030", "100", "130", "200", "230", "300", "330", "400", "430", "500", "530", "600", "630", "700", "730", "800", "830", "900", "930", "1000", "1030", "1100", "1130", "1200", "1230", "1300", "1330", "1400", "1430", "1500", "1530", "1600", "1630", "1700", "1730", "1800", "1830", "1900", "1930", "2000", "2030", "2100", "2130", "2200", "2230", "2300", "2330"];
var index_start = times.indexOf(time);
但是,这不起作用。如何以特定值启动滑块?
【问题讨论】:
【参考方案1】:不知道你为什么用字符串而不是整数来做。无论哪种方式,您都可以这样做:
JavaScript
var now = new Date();
var hour = now.getHours() * 100;
var minutes = now.getMinutes();
var index_start = 0;
if (minutes < 15)
minutes = 0;
else if (minutes < 45)
minutes = 30;
else
minutes = 100;
var t = hour + minutes;
var times = [0, 30, 100, 130, 200, 230, 300, 330, 400, 430, 500, 530, 600, 630, 700, 730, 800, 830, 900, 930, 1000, 1030, 1100, 1130, 1200, 1230, 1300, 1330, 1400, 1430, 1500, 1530, 1600, 1630, 1700, 1730, 1800, 1830, 1900, 1930, 2000, 2030, 2100, 2130, 2200, 2230, 2300, 2330];
index_start = times.indexOf(t);
测试示例:https://jsfiddle.net/Twisty/qmsux550/
【讨论】:
以上是关于在 Leaflet 中以特定值启动 JQuery UI Slider的主要内容,如果未能解决你的问题,请参考以下文章
在鼠标悬停时突出显示L.divIcon或在Leaflet地图中以编程方式突出显示
(Apache Wicket) 从 js 函数设置 java 属性