Skip to content

Commit adb21b2

Browse files
author
潘卓然 Parn Deedlit
authored
Merge pull request #50 from MapGIS/leaflet_animate
【标记动画图和轨迹动画图示例修改】【两个动画图markdown】【API注释】【修改动画示例截图】
2 parents 5b00c41 + 768f82e commit adb21b2

File tree

15 files changed

+370
-99
lines changed

15 files changed

+370
-99
lines changed

src/leaflet/overlay/AnimatedMarkerLayer.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ import L from "leaflet";
66
* @classdesc 基于leaflet的Layer对象进行的拓展
77
* @extends {L.Marker}
88
* @param {string} latlngs - 轨迹点
9+
* @param options - {Object} 其他参数
10+
* @param options.autoStart - {boolean},是否自动开启该marker
11+
* @param options.distance - meters,表示每帧移动的距离,越大则一秒移动的距离越远,速度越快
12+
* @param options.interval - milliseconds,每帧之间移动的时间间隔,与distance相互配合
13+
* @param options.clickable - {boolean},如果是false,注记marker则不产生鼠标事件并表现为底层地图的一部分。
14+
* @param options.onEnd() - animate结束的回调
915
*/
1016
export var AnimatedMarkerLayer = L.Marker.extend({
1117
options: {

src/leaflet/overlay/timedimension/leaflet.timedimension.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,15 @@ import { TimeDimensionUtil } from './leaflet.timedimension.util'
55
* It can be shared among different layers and it can be added to a map, and become
66
* the default timedimension component for any layer added to the map.
77
*/
8-
8+
/**
9+
* @author 基础平台/创新中心 潘卓然 ParnDeedlit
10+
* @class L.zondy.TimeDimension
11+
* @classdesc 基于leaflet的Layer对象进行的拓展
12+
* @extends {L.Layer}
13+
* @param options.loadingTimeout - {Number},加载延迟时间
14+
* @param options.currentTime - {Number},milliseconds,当前加载时间
15+
* @param options.period -{String},默认"P1D",用于构造从第一个可用时间开始的可用时间数组,格式:ISO8601持续时间
16+
*/
917
export var TimeDimension = (L.Layer || L.Class).extend({
1018

1119
includes: (L.Evented || L.Mixin.Events),

src/leaflet/overlay/timedimension/leaflet.timedimension.layer.geojson.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,19 @@ import { TimeDimensionUtil } from './leaflet.timedimension.util'
55
/*
66
* TimeDimensionLayer.GeoJson:
77
*/
8-
8+
/**
9+
* @author 基础平台/创新中心 潘卓然 ParnDeedlit
10+
* @class L.zondy.TimeDimensionLayerGeoJson
11+
* @classdesc 基于TimeDimensionLayer对象进行的拓展
12+
* @extends {L.Layer}
13+
* @param layer, L.geoJSON创建的图层
14+
* @param options.updateTimeDimension - {Boolean},用这个GeoJSON的可用时间更新附加TimeDimension的可用时间列表
15+
* @param options.updateTimeDimensionMode - {String},合并TimeDimension和图层的可用时间(相交,并集,替换或极端)的操作,默认为"extremes"
16+
* @param options.duration - 持续时间
17+
* @param options.addlastPoint -{Boolean},在LineString的最后一个有效坐标处添加一个Point。默认为false
18+
* @param options.waitForReady - {Boolean},如果为true,它将等待直到加载baseLayer来将其自身标记为就绪。默认为false
19+
* @param options.updateCurrentTime -{Boolean},自动将地图的当前时间更改为GeoJSON图层的第一个可用时间,默认为updateTimeDimension的值
20+
*/
921
export var TimeDimensionLayerGeoJson = TimeDimensionLayer.extend({
1022

1123
initialize: function(layer, options) {

src/leaflet/overlay/timedimension/leaflet.timedimension.layer.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,15 @@ import L from "leaflet";
66
* Any children class should implement `_onNewTimeLoading`, `isReady` and `_update` functions
77
* to react to time changes.
88
*/
9-
9+
/**
10+
* @author 基础平台/创新中心 潘卓然 ParnDeedlit
11+
* @class L.zondy.TimeDimensionLayer
12+
* @classdesc 基于leaflet的Layer对象进行的拓展
13+
* @extends {L.Layer}
14+
* @param options.timeDimension - 管理该TimeDimensionLayer层的timeDimension对象。
15+
* @param options.opacity - 默认为1
16+
* @param options.zIndex - 默认为1
17+
*/
1018
export var TimeDimensionLayer = (L.Layer || L.Class).extend({
1119

1220
includes: (L.Evented || L.Mixin.Events),

src/leaflet/overlay/timedimension/leaflet.timedimension.layer.wms.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,24 @@ import { TimeDimensionLayer } from './leaflet.timedimension.layer'
44
/*
55
* L.TimeDimension.Layer.WMS: wms Layer associated to a TimeDimension
66
*/
7-
7+
/**
8+
* @author 基础平台/创新中心 潘卓然 ParnDeedlit
9+
* @class L.zondy.TimeDimensionLayerWMS
10+
* @classdesc 基于leaflet的TimeDimensionLayer对象进行的拓展:为给定的WMS层实现TimeDimension层
11+
* @extends {TimeDimensionLayer}
12+
* @param options.cache - 默认为0
13+
* @param options.cacheBackward - {Number},在之前时间中被隐藏的图层数
14+
* @param options.cacheForward - {Number},在之后时间中地图上被隐藏的图层数
15+
* @param options.updateTimeDimension - 使用getCapabilities获得的可用时间来更新附加的TimeDimension的可用时间列表。
16+
* @param options.updateTimeDimensionMode - {String},默认值"intersect",合并TimeDimension和图层的可用时间(相交,并集,替换或极端)的操作。
17+
* @param options.requestTimeFromCapabilities - {Boolean},默认值false,从getCapabilities获取该层的可用时间列表
18+
* @param options.proxy - {String}用于从WMS服务器获取getCapabilities响应的代理的URL,以避免跨站点起源问题
19+
* @param options.getCapabilitiesParams - {Object},创建getCapabilities请求所需的额外参数
20+
* @param options.getCapabilitiesUrl - {String},GetCapabilities请求的备用URL(在使用诸如GeoWebCache之类的缓存服务时很有用)
21+
* @param options.getCapabilitiesLayerName - {String},GetCapabilities请求的备用层名称(如果使用诸如GeoWebCache之类的缓存服务,则很有用)
22+
* @param options.setDefaultTime - {Boolean},默认值false,如果为true,则会将当前时间更改为图层的默认时间(根据getCapabilities)
23+
* @param options.period - {String},默认为null,时间间隔之间的持续时间,该时间间隔将用于生成图层的可用时间。它会覆盖getCapabilities中收到的值(如果不为null)
24+
*/
825
export var TimeDimensionLayerWMS = TimeDimensionLayer.extend({
926

1027
initialize: function(layer, options) {

src/leaflet/overlay/timedimension/leaflet.timedimension.player.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,22 @@ import L from "leaflet";
22
/*
33
* L.TimeDimension.Player
44
*/
5+
/**
6+
* @author 基础平台/创新中心 潘卓然 ParnDeedlit
7+
* @class L.zondy.TimeDimensionPlayer
8+
* @classdesc 基于leaflet的Layer对象进行的拓展:组件使用timeDimension设置地图动画,定期更改时间。
9+
* @extends {L.Layer}
10+
* @param options.buffer - {Number},默认值:5
11+
* @param options.minBufferReady - {Number},默认值:1,如果此选项大于0,则每当下一个准备时间(下一个准备就绪的层)的数量低于此数量时,播放器就会填充缓冲区。
12+
* @param options.loop - {Boolean},循环播放,默认值:false,到达最后一个可用时间时循环播放动画
13+
* @param options.transitionTime -{Number},1000,player将等待下一次在TimeDimension中检查并启动的毫秒数
14+
* @param options.startOver - {Boolean},当播放器player位于最后一个位置时,它会从用户按下播放时重新开始,默认值:false
15+
*
16+
* player播放器的事件:start()、stop()、
17+
* pause()、release()、
18+
* getTransitionTime()-返回时间间隔,在两个动画步数之间。
19+
* setTransitionTime(<Number> transitionTime)、isLooped():返回循环的boolean值
20+
*/
521
export var TimeDimensionPlayer = (L.Layer || L.Class).extend({
622

723
includes: (L.Evented || L.Mixin.Events),
843 Bytes
Loading
1022 Bytes
Loading

website/public/static/demo/leaflet/example/client-view/common/common_line_animate.htm

Lines changed: 85 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,16 @@
22
<html xmlns="http://www.w3.org/1999/xhtml">
33

44
<head>
5-
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6-
<title>标记动画图</title>
5+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
6+
<title>轨迹动画图</title>
77
<script include="jquery,omnivore" src="./static/libs/include-lib-local.js"></script>
88
<script include="timedimension" src="./static/libs/include-leaflet-local.js"></script>
99
<style>
1010
body {
1111
margin: 0;
1212
padding: 0;
1313
}
14-
15-
#map {
14+
#test {
1615
position: absolute;
1716
top: 0;
1817
bottom: 0;
@@ -22,103 +21,104 @@
2221
</head>
2322

2423
<body>
25-
<div id="map"></div>
26-
<script>
27-
var startDate = new Date();
28-
startDate.setUTCHours(0, 0, 0, 0);
29-
30-
var map = L.map('map', {
31-
zoom: 12,
32-
fullscreenControl: true,
33-
center: [39.3, 4]
34-
});
24+
<div id="test"></div>
25+
<script>
26+
var startDate = new Date();
27+
startDate.setUTCHours(0, 0, 0, 0);
3528

36-
// start of TimeDimension manual instantiation
37-
var timeDimension = new L.zondy.TimeDimension({
38-
period: "PT5M",
39-
});
40-
// helper to share the timeDimension object between all layers
41-
map.timeDimension = timeDimension;
42-
// otherwise you have to set the 'timeDimension' option on all layers.
29+
var map = L.map('test', {
30+
crs: L.CRS.EPSG4326,
31+
fullscreenControl: true
32+
}).setView([25.29, 104.28], 10);
33+
var layer1 = new Zondy.Map.TDTLayer({
34+
layerType: 'vec',
35+
minZoom: 0,
36+
maxZoom: 15,
37+
token: "4c27d6e0e8a90715b23a989d42272fd8",
38+
noWrap: true
39+
});
40+
var layer2 = new Zondy.Map.TDTLayer({
41+
layerType: 'cva',
42+
minZoom: 0,
43+
maxZoom: 15,
44+
token: "4c27d6e0e8a90715b23a989d42272fd8",
45+
noWrap: true
46+
});
47+
var LayerG = L.layerGroup([layer1, layer2]);
48+
LayerG.addTo(map);
4349

44-
var player = new L.zondy.TimeDimensionPlayer({
45-
transitionTime: 100,
46-
loop: false,
47-
startOver: true
48-
}, timeDimension);
4950

50-
var timeDimensionControlOptions = {
51-
player: player,
52-
timeDimension: timeDimension,
53-
position: 'bottomleft',
54-
autoPlay: true,
55-
minSpeed: 1,
56-
speedStep: 0.5,
57-
maxSpeed: 15,
58-
timeSliderDragUpdate: true
59-
};
51+
// 1.开始手动实例化timeDimension
52+
var timeDimension = new L.zondy.TimeDimension({
53+
period: "PT5M",
54+
});
55+
// 2.在所有图层中共享timeDimension对象
56+
map.timeDimension = timeDimension;
57+
// 否则,必须在所有图层中设置“timeDimension”选项
58+
// 3.创建播放器
59+
var player = new L.zondy.TimeDimensionPlayer({
60+
transitionTime: 100,
61+
loop: false,
62+
startOver: true
63+
}, timeDimension);
64+
// 4.将播放器player放入timeDimensionControl控制器中
65+
var timeDimensionControlOptions = {
66+
player: player,
67+
timeDimension: timeDimension,
68+
position: 'bottomleft',
69+
autoPlay: true,
70+
minSpeed: 1,
71+
speedStep: 0.5,
72+
maxSpeed: 15,
73+
timeSliderDragUpdate: true
74+
};
75+
// 5.将timeDimensionControl添加到地图中
76+
var timeDimensionControl = new L.zondy.TimeDimensionControl(timeDimensionControlOptions);
77+
map.addControl(timeDimensionControl);
6078

61-
var timeDimensionControl = new L.zondy.TimeDimensionControl(timeDimensionControlOptions);
62-
map.addControl(timeDimensionControl);
79+
var icon = L.icon({
80+
iconUrl: './static/data/picture/marker/running.png',
81+
iconSize: [22, 22],
82+
iconAnchor: [5, 25]
83+
});
6384

64-
var icon = L.icon({
65-
iconUrl: './static/data/picture/marker/running.png',
66-
iconSize: [22, 22],
67-
iconAnchor: [5, 25]
68-
});
69-
70-
var customLayer = L.geoJson(null, {
85+
var geojson = {};
86+
$.get('./static/data/geojson/line-string.json', function (res) {
87+
geojson = initGeojson(res);
88+
var geoJSONLayer = L.geoJSON(geojson, {
7189
pointToLayer: function (feature, latLng) {
72-
if (feature.properties.hasOwnProperty('last')) {
90+
if (feature.properties.hasOwnProperty("last")) {
7391
return new L.Marker(latLng, {
74-
icon: icon
92+
icon: icon,
7593
});
7694
}
7795
return L.circleMarker(latLng);
78-
}
96+
},
7997
});
80-
81-
var gpxLayer = omnivore.gpx('../../static/data/gpx/running_mallorca.gpx', null, customLayer).on('ready', function () {
82-
map.fitBounds(gpxLayer.getBounds(), {
83-
paddingBottomRight: [40, 40]
84-
});
85-
});
86-
87-
var gpxTimeLayer = L.zondy.TimeDimensionLayerGeoJson(gpxLayer, {
98+
var gpxTimeLayer = L.zondy.TimeDimensionLayerGeoJson(geoJSONLayer, {
8899
updateTimeDimension: true,
100+
duration: "PT2M",
101+
updateTimeDimensionMode: "replace",
89102
addlastPoint: true,
90-
waitForReady: true
91103
});
92-
93-
var baseLayers = getCommonBaseLayers(map); // see baselayers.js
94104
gpxTimeLayer.addTo(map);
105+
});
95106

96-
function getCommonBaseLayers(map) {
97-
var osmLayer = L.tileLayer('https://{s}.tile.osm.org/{z}/{x}/{y}.png', {
98-
attribution: '&copy; <a href="https://osm.org/copyright">OpenStreetMap</a> contributors'
99-
});
100-
var bathymetryLayer = L.tileLayer.wms("https://ows.emodnet-bathymetry.eu/wms", {
101-
layers: 'emodnet:mean_atlas_land',
102-
format: 'image/png',
103-
transparent: true,
104-
attribution: "EMODnet Bathymetry",
105-
opacity: 0.8
106-
});
107-
var coastlinesLayer = L.tileLayer.wms("https://ows.emodnet-bathymetry.eu/wms", {
108-
layers: 'coastlines',
109-
format: 'image/png',
110-
transparent: true,
111-
attribution: "EMODnet Bathymetry",
112-
opacity: 0.8
113-
});
114-
var bathymetryGroupLayer = L.layerGroup([bathymetryLayer, coastlinesLayer]);
115-
bathymetryGroupLayer.addTo(map);
116-
return {
117-
"EMODnet Bathymetry": bathymetryGroupLayer,
118-
"OSM": osmLayer
119-
};
120-
}
121-
</script>
107+
//注意:geojson数据中要有times和播放器建立链接
108+
function initGeojson(geojson) {
109+
let date = new Date();
110+
let timestamp = date.getTime();
111+
geojson.properties.times = [];
112+
geojson.geometry.coordinates = geojson.geometry.coordinates.map(
113+
(point) => {
114+
++timestamp;
115+
geojson.properties.times.push(timestamp);
116+
return point;
117+
}
118+
);
119+
return geojson;
120+
}
121+
</script>
122122
</body>
123123

124124
</html>

0 commit comments

Comments
 (0)