首页 / 浏览问题 / 云GIS / 问题详情
animatorVector事件问题
23EXP 2018年11月19日
您好:

 我想请问下在animatorVector中,怎样去获取动画在每一帧的时候的事件,我看在js的API上显示的是用drawFrame,但是没有用,有没有其他的方法?

1个回答

您好,我这边测试了一下这个功能是可以正常实现的,您那边是监听后没有效果吗?
5,668EXP 2018年11月19日
您好

animatorVector.events.on({"drawFrame":drawFrame});

function drawFrame(feature) {
        console.log("test");
        //console.log(feature);
    }

监听后没有任何效果,console.log("test")这段代码都无法执行
您是在咱们官网上看的么?我这边在官网的话是正常的
您好
官网上是这样的例子

{Array(String)} 此类支持的事件类型。

  • drawfeaturestart 每次绘制在当前时间节点内的feature时触发。
  • drawFrame 绘制帧,动画的每一帧都会触发此事件,传回的参数即为当前渲染的要素
  • featurerendered 要素渲染事件,当要素被渲染后发触发,返回一个当前补间动画中真实被渲染的要素,这样可记录运动的轨迹 例如:
//使用下面的方法将图层添加到map
var animatorVector = new SuperMap.Layer.AnimatorVector("animatorVector", {}, {
    //设置速度为每帧播放0.05的数据
    speed:0.05,
    //开始时间为0
    startTime:0,
    //每秒渲染12帧
    frameRate:12,
    //结束时间设置为10
    endTime:10
});
layer.events.on({"drawfeaturestart": drawfeaturestart});


function drawfeaturestart(feature) {

}

但是我把drawfeaturestart": drawfeaturestart换成"drawFrame":drawFrame就无法监听执行

您私信我一个联系方式,然后方便的话我远程看一下您那边的情况
您好

请问方便提供一下你的测试DEMO吗
我这边就是用的官网的执行的
<!--********************************************************************
* Copyright© 2000 - 2018 SuperMap Software Co.Ltd. All rights reserved.
*********************************************************************-->
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title data-i18n="resources.title_animatorCar"></title>
    <style type="text/css">
        body {
            margin: 0;
            overflow: hidden;
            background: #fff;
            width: 100%;
            height: 100%
        }

        #map {
            position: absolute;
            width: 100%;
            height: 100%;
            border: 1px solid #3473b7;
        }

        #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_animatorCar"></h5></div>
    <div class='panel-body content'>
        <input type="button" class="btn btn-default" data-i18n="[value]resources.btn_queryCar" onclick="queryBySQL()"/>&nbsp;
        <input type="button" class="btn btn-default" data-i18n="[value]resources.btn_startAnimator" onclick="startAnimator()"/>&nbsp;
        <input type="button" class="btn btn-default" data-i18n="[value]resources.btn_pauseAnimator" onclick="pauseAnimator()"/>&nbsp;
        <input type="button" class="btn btn-default" data-i18n="[value]resources.btn_stopAnimator" onclick="stopAnimator()"/>
    </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, vectorLayer, features, cars, animatorVector,
        //定义公交线路的样式。
        styleLine = {
            strokeColor: "black",
            strokeWidth: 1,
            fill: false
        },
        styleCar1 =
            {
                externalGraphic: "./images/blueCar.png",
                allowRotate: true,
                graphicWidth: 32,
                graphicHeight: 32
            },
        styleCar2 =
            {
                externalGraphic: "./images/redCar.png",
                allowRotate: true,
                graphicWidth: 32,
                graphicHeight: 32
            },
        host = window.isLocal ? window.server : "http://support.supermap.com.cn:8090",
        url1 = host + "/iserver/services/map-changchun/rest/maps/长春市区图";

    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 = 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("changchun", url1, {
            transparent: true,
            cacheEnabled: true
        }, {maxResolution: "auto"});
        layer.events.on({"layerInitialized": addLayer});
        //初始化公交车路线图层。
        vectorLayer = new SuperMap.Layer.Vector("Vector Layer", {
            styleMap: new SuperMap.StyleMap({
                "default": styleLine
            })
        });
        //初始化汽车图层。
        animatorVector = new SuperMap.Layer.AnimatorVector("Cars", {}, {
            //设置速度为每帧播放0.05小时的数据
            speed: 0.05,
            //开始时间为0晨
            startTime: 0,
            //结束时间设置为最后运行结束的汽车结束时间
            endTime: 55
        });
    }

    function addLayer() {
        map.addLayers([layer, vectorLayer, animatorVector]);
        map.setCenter(new SuperMap.LonLat(5935, -3580), 1);
        map.addControl(new SuperMap.Control.MousePosition());
    }

    //定义查询汽车线路。
    function queryBySQL() {

        animatorVector.removeAllFeatures();
        var queryParam, queryBySQLParams, queryBySQLService;
        queryParam = new SuperMap.REST.FilterParameter({
            name: "BusLine@Changchun#1",
            attributeFilter: "SmID > 0"
        }),
            queryBySQLParams = new SuperMap.REST.QueryBySQLParameters({
                queryParams: [queryParam]
            }),
            queryBySQLService = new SuperMap.REST.QueryBySQLService(url1, {
                eventListeners: {"processCompleted": processCompleted, "processFailed": processFailed}
            });
        queryBySQLService.processAsync(queryBySQLParams);
    }

    function processCompleted(queryEventArgs) {
        var i, j, feature,
            result = queryEventArgs.result;
        features = [];
        cars = [];
        vectorLayer.removeAllFeatures();
        animatorVector.removeAllFeatures();
        var orientation = 1;
        if (result && result.recordsets) {
            for (i = 0; i < result.recordsets.length; i++) {
                if (result.recordsets[i].features) {
                    for (j = 0, len = result.recordsets[i].features.length; j < len; j++) {
                        feature = result.recordsets[i].features[j];
                        feature.style = null;
                        features.push(feature);
                        var style = styleCar1;
                        var featureComps = feature.geometry.components;
                        for (var k = 0, len = featureComps.length; k < len; k++) {
                            var car = new SuperMap.Feature.Vector(featureComps[k].clone(),
                                {
                                    FEATUREID: feature.id,
                                    //根据节点生成时间
                                    TIME: k
                                }, style
                            );
                            cars.push(car);
                        }
                    }
                }
            }
        }
        vectorLayer.addFeatures(features);
        animatorVector.addFeatures(cars);
        animatorVector.events.on({"drawFrame":drawFrame});
    }
    function drawFrame(feature) {
        console.log("test");
        //console.log(feature);
    }
    function processFailed(e) {
        widgets.alert.showAlert(e.error.errorMsg, false);
    }

    //开始播放动画
    function startAnimator() {
        animatorVector.animator.start();
    }

    //暂停播放动画
    function pauseAnimator() {
        animatorVector.animator.pause();
    }

    //停止播放动画
    function stopAnimator() {
        animatorVector.animator.stop();
    }

</script>

</body>
</html>

那麻烦你帮我看下我的代码里面为什么不能执行,谢谢
...