车辆监控模拟示例报错

0 投票

只改了示例里面的url,数据集名称,其他的和示例完全一样,为什么会出现以下错误呢?

7月 30, 2017 分类:  641次浏览 | 用户: 咻咻咻 初出茅庐 (24 分)

2 个回答

0 投票
 
已采纳
检查有没有查询到数据,建议输出feature看看。
报错的意思是feature是undefined,不能获取feature.style属性。
8月 1, 2017 用户: 毛瑞 名扬四海 (1,780 分)
采纳于 8月 9, 2017 用户:咻咻咻

<!DOCTYPE>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>车辆监控模拟</title>
    <style type="text/css">
        body{
            margin: 0;
            overflow: hidden;
            background: #fff;
        }
        #map{
            position: relative;
            height: 610px;
            border:1px solid #3473b7;
        }
        #toolbar{
            position: relative;
            padding-top:5px;
            padding-bottom: 10px;
        }
    </style>
    <link rel="stylesheet" href="../../static/css/bootstrap.css">
    <link rel="stylesheet" href="../../static/css/bootstrap-responsive.css">
    <script src="../../static/libs/SuperMap.Include.js"></script>
    <script type="text/javascript">
        var map, layer, BusLineLayer, features, cars, carVector,
            //定义公交线路的样式。
            styleLine = {
                strokeColor: "black",
                strokeWidth: 1,
                fill: false
            },
            styleCar1=
                {
                    externalGraphic:"../theme/images/marker.png",
                    allowRotate:true,
                    graphicWidth:32,
                    graphicHeight:32
                },
           
            url1="http://localhost:8090/iserver/services/map-bike-sharing/rest/maps/SupermapCloud";
        function init(){

            map = new SuperMap.Map("map",{allOverlays:true,
                controls: [
                new SuperMap.Control.LayerSwitcher(),
                new SuperMap.Control.ScaleLine(),
                new SuperMap.Control.Zoom(),
                new SuperMap.Control.Navigation({
                    dragPanOptions: {
                        enableKinetic: true
                    }
                })], units: "m"
            });

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


        function addLayer() {
            map.addLayers([layer, BusLineLayer, carVector]);
            map.setCenter(new SuperMap.LonLat(12963487.7761907, 4852179.97174134),12);
            map.addControl(new SuperMap.Control.MousePosition()) ;
        }

        //定义查询汽车线路。
        function queryBySQL() {
            carVector.removeAllFeatures();
            var queryParam, queryBySQLParams, queryBySQLService;
            queryParam = new SuperMap.REST.FilterParameter({
                name: "BusLine@北京市",
                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, result = queryEventArgs.result;
            var feature=1;
            features = [];
            cars = [];
            BusLineLayer.removeAllFeatures();
            carVector.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);
                            }
                        }
                    }
                }
            }
            BusLineLayer.addFeatures(features);
            carVector.addFeatures(cars);
        }

        function processFailed(e) {
            alert(e.error.errorMsg);
        }

        //开始播放动画
        function startAnimator(){
            carVector.animator.start();
        }
        //暂停播放动画
        function pauseAnimator(){
            carVector.animator.pause();
        }
        //停止播放动画
        function stopAnimator(){
            carVector.animator.stop();
        }
    </script>
</head>
<body onload="init()">

<div id="toolbar">
    <input type="button" class="btn" value="查询车辆" onclick="queryBySQL()" />
    <input type="button" class="btn" value="开始监控" onclick="startAnimator()" />
    <input type="button" class="btn" value="暂停监控" onclick="pauseAnimator()" />
    <input type="button" class="btn" value="停止监控" onclick="stopAnimator()" />
</div>
<div id="map"></div>
</body>
</html>

你能帮我看一下哪里有问题吗?

这个问题贴代码没用,代码看不出有问题。你得先检查有没有查到数据、数据是否正确,比如,数据的坐标系与当前地图是否一致等;当然,你需要先检查有没有查询到数据,再根据返回结果去写代码完成接下来的逻辑。建议下打断点进行调试,查看返回结果及返回结果对象的结构。
0 投票
您好,您是做二维,还是三维?
7月 31, 2017 用户: 郭宇杰 才疏学浅 (11 分)
我做的是二维。
...