使用传单滑块隐藏标记

Hiding markers using LeafletSlider?

本文关键字:隐藏 单滑块      更新时间:2023-09-26

我使用LeafletSlider插件在地图上显示难民营的时间范围。营地根据我的 GEOJSON 对象中名为 DATE_START 的属性出现在地图上。正如你在我的JSFIDDLE中看到的,滑块工作得很好。

当我正在清理时间线

时,我想根据当前时间线清理的日期和DATE_CLOSED属性的日期删除具有DATE_CLOSED属性的标记。

看起来这个时间滑块插件只显示标记。有谁知道如何在日期关闭后隐藏标记?

示例数据:

var camps = {"type":"FeatureCollection","features":[{"type":"Feature","properties":{"STATUS":"UNOCCUPIED","DATE_START":"2015-06-23","DATE_CLOSED":"2016-01-23"},"geometry":{"type":"Point","coordinates":[64.6875,34.97600151317591]}},{"type":"Feature","properties":{"STATUS":"OCCUPIED","DATE_START":"2014-01-21","DATE_CLOSED":"2015-05-25"},"geometry":{"type":"Point","coordinates":[65.335693359375,36.26199220445664]}},{"type":"Feature","properties":{"STATUS":"UNOCCUPIED","DATE_START":"2015-09-13","DATE_CLOSED":""},"geometry":{"type":"Point","coordinates":[67.587890625,35.969115075774845]}}]};

法典:

var map = L.map('map', {
center: [33.67406853374198, 66.9287109375],
zoom: 7
}).addLayer(new L.TileLayer("http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"));

//Create a marker layer (in the example done via a GeoJSON FeatureCollection)
var testlayer = L.geoJson(camps, {
onEachFeature: function(feature, layer) {
    layer.bindPopup(feature.properties.DATE_START);
    }
});
var sliderControl = L.control.sliderControl({
position: "topright",
layer: testlayer,
timeAttribute: 'DATE_START'
});
//Make sure to add the slider to the map ;-)
map.addControl(sliderControl);
sliderControl.options.markers.sort(function(a, b) {
return (a.feature.properties.DATE_START > b.feature.properties.DATE_START);
});
//And initialize the slider
sliderControl.startSlider();
$('#slider-timestamp').html(options.markers[ui.value].feature.properties.DATE_START.substr(0, 10));
我希望

这算作一个答案,但我发现有一个替代的时间线插件可以满足我的需求:https://github.com/skeate/Leaflet.timeline