123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252 |
- <!--********************************************************************
- * Copyright© 2000 - 2021 SuperMap Software Co.Ltd. All rights reserved.
- *********************************************************************-->
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <title data-i18n="resources.title_animatorWeatherMonitor"></title>
- <script src='./data/sampleData1.js'></script>
- <script src='./data/sampleData2.js'></script>
- <script src='./data/sampleData3.js'></script>
- <script src='./data/sampleData4.js'></script>
- <script src='./data/sampleData5.js'></script>
- <script src='./data/sampleData6.js'></script>
- <script src='./data/sampleData7.js'></script>
- <script src='./data/sampleData8.js'></script>
- <style type="text/css">
- body {
- margin: 0;
- overflow: hidden;
- background: #fff;
- width: 100%;
- height: 100%
- }
- #map {
- position: absolute;
- width: 100%;
- height: 100%;
- }
- #toolbar {
- position: absolute;
- top: 50px;
- right: 10px;
- text-align: center;
- z-index: 100;
- border-radius: 4px;
- }
- </style>
- </head>
- <body>
- <div id="toolbar" class="panel panel-primary">
- <div class='panel-heading'>
- <h5 class='panel-title text-center' data-i18n="resources.title_animatorWeatherMonitor"></h5></div>
- <div class='panel-body content'>
- <input type="button" class="btn btn-default" data-i18n="[value]resources.btn_play" onclick="startAnimator()"/>
- <input type="button" class="btn btn-default" data-i18n="[value]resources.btn_pause" onclick="pauseAnimator()"/>
- </div>
- </div>
- <div id="map"></div>
- <script type="text/javascript" include="bootstrap,widgets.alert" src="../js/include-web.js"></script>
- <script type="text/javascript" exclude="iclient-classic" src="../../dist/classic/include-classic.js"></script>
- <script>
- var map, layer, animatorVector, features, select, tempLayer,
- drag, delIndex = 0, editEnable = false, dataIndex = 0, timerID = null,
- weatherDatas = [],
- //设置图层样式
- transformControl,
- style = {
- strokeColor: "#cccccc",
- strokeWidth: 1,
- fillColor: "#ccfffa",
- fillOpacity: "0.5"
- },
- style2 = {
- strokeColor: "#cccccc",
- strokeWidth: 1,
- fillColor: "#a3f8b4",
- fillOpacity: "0.5"
- },
- style1 = {
- strokeColor: "#cccccc",
- strokeWidth: 1,
- fillColor: "#79f26f",
- fillOpacity: "0.5"
- },
- style3 = {
- strokeColor: "#cccccc",
- strokeWidth: 1,
- fillColor: "#2dd90b",
- fillOpacity: "0.5"
- },
- style4 = {
- strokeColor: "#cccccc",
- strokeWidth: 1,
- fillColor: "#8aee1e",
- fillOpacity: "0.5"
- },
- style6 = {
- strokeColor: "#cccccc",
- strokeWidth: 1,
- fillColor: "#c5ef0f",
- fillOpacity: "0.5"
- },
- style5 = {
- strokeColor: "#cccccc",
- strokeWidth: 1,
- fillColor: "#fff100",
- fillOpacity: "0.5"
- },
- style7 = {
- strokeColor: "#cccccc",
- strokeWidth: 1,
- fillColor: "#fcbd10",
- fillOpacity: "0.5"
- },
- style8 = {
- strokeColor: "#cccccc",
- strokeWidth: 1,
- fillColor: "#fb8722",
- fillOpacity: "0.5"
- },
- style9 = {
- strokeColor: "#cccccc",
- strokeWidth: 1,
- fillColor: "#d53b3b",
- fillOpacity: "1"
- },
- host = window.isLocal ? window.server : "https://iserver.supermap.io",
- url1 = host + "/iserver/services/map-world/rest/maps/World";
- init();
- function init() {
- /*
- * 不支持canvas的浏览器不能运行该范例
- * android 设备也不能运行该范例*/
- var broz = SuperMap.Util.getBrowser();
- if (!document.createElement('canvas').getContext) {
- widgets.alert.showAlert(resources.msg_supportCanvas, false);
- return;
- } else if (broz.device === 'android') {
- widgets.alert.showAlert(resources.msg_supportEquipment, false);
- return;
- }
- //加载map控件
- map = new SuperMap.Map("map", {
- controls: [
- new SuperMap.Control.ScaleLine(),
- new SuperMap.Control.Zoom(),
- new SuperMap.Control.Navigation({
- dragPanOptions: {
- enableKinetic: true
- }
- })], units: "m"
- });
- map.addControl(new SuperMap.Control.LayerSwitcher(), new SuperMap.Pixel(42, 80));
- //初始化图层
- layer = new SuperMap.Layer.TiledDynamicRESTLayer("China400", url1, {
- transparent: true,
- cacheEnabled: true
- }, {maxResolution: "auto"});
- //初始化动画矢量图层
- animatorVector = new SuperMap.Layer.AnimatorVector("Polygon", {smooth: false}, {
- //设置速度为每帧播放1小时的数据
- speed: 1,
- //开始时间为0点
- startTime: 0,
- //每秒渲染1次
- frameRate: 1,
- //结束时间为7点
- endTime: 7
- });
- layer.events.on({"layerInitialized": addLayer});
- }
- //添加图层
- function addLayer() {
- map.addLayers([layer, animatorVector]);
- map.setCenter(new SuperMap.LonLat(106, 34), 2);
- map.addControl(new SuperMap.Control.MousePosition());
- monitor();
- };
- //添加数据
- function monitor() {
- //初始化数据
- if (weatherDatas.length == 0) {
- weatherDatas[0] = SuperMap.REST.Recordset.fromJson(sampleData1);
- weatherDatas[1] = SuperMap.REST.Recordset.fromJson(sampleData2);
- weatherDatas[2] = SuperMap.REST.Recordset.fromJson(sampleData3);
- weatherDatas[3] = SuperMap.REST.Recordset.fromJson(sampleData4);
- weatherDatas[4] = SuperMap.REST.Recordset.fromJson(sampleData5);
- weatherDatas[5] = SuperMap.REST.Recordset.fromJson(sampleData6);
- weatherDatas[6] = SuperMap.REST.Recordset.fromJson(sampleData7);
- weatherDatas[7] = SuperMap.REST.Recordset.fromJson(sampleData8);
- }
- animatorVector.removeAllFeatures();
- var features = [];
- for (var index = 0; index < weatherDatas.length; index++) {
- var result = weatherDatas[index];
- var len = result.features.length;
- for (var i = 0; i < len; i++) {
- var feature = result.features[i];
- var data = feature.attributes;
- data['TIME'] = index;
- data['FEATUREID'] = index + "_" + i;
- var value = data['DMAXVALUE'];
- if (value < -24) {
- feature.style = style;
- }
- else if (value < -18) {
- feature.style = style1;
- }
- else if (value < -12) {
- feature.style = style2;
- }
- else if (value < -6) {
- feature.style = style3;
- }
- else if (value < 0) {
- feature.style = style4;
- }
- else if (value < 6) {
- feature.style = style5;
- }
- else if (value < 12) {
- feature.style = style6;
- }
- else if (value < 18) {
- feature.style = style7;
- }
- else if (value < 24) {
- feature.style = style8;
- }
- else {
- features.style = style9;
- }
- features.push(feature);
- }
- }
- animatorVector.addFeatures(features);
- };
- //开始播放动画
- function startAnimator() {
- animatorVector.animator.start();
- }
- //暂停播放动画
- function pauseAnimator() {
- animatorVector.animator.pause();
- }
- </script>
- </body>
- </html>
|