首页 / 浏览问题 / 云GIS / 问题详情
为什么callbacks事件无效
23EXP 2018年11月27日
您好

为什么我用了WMTS之后,callbacks事件就无效呢?贴上所有代码,麻烦帮我看一下,谢谢

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>轨迹回放</title>
    <script src="libs/SuperMap.Include.js"></script>
    <style type="text/css">
        body {
            margin: 0;
            overflow: hidden;
            background: #fff;
            width: 100%;
            height: 100%;
            position: absolute;
            top: 0;
        }
        
        #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;
        }
        
        .editPane {
            position: absolute;
            left: 50px;
            top: 10px;
            text-align: center;
            background: #FFF;
            z-index: 1000;
        }
    </style>
</head>
<body>
    <div id="map" style="margin:0 auto;width: 100%;height: 100%"></div>
</body>
<script>
    //生成地图
    var map, layer, vectorLayer;
    var animatorVector; //车辆运动
    var x = 118.733287;
    var y = 31.991794;
    var styleCar1 = {
        externalGraphic: "./images/huoche.png",
        allowRotate: true,
        graphicWidth: 50,
        graphicHeight: 50
    }; //车辆样式
    var vectorInfoWin;
    var vectorInfoWin2;
    url = "http://172.16.241.187:8090/iserver/services/map-tianditu/rest/maps/矢量底图_经纬度";
    
    map = new SuperMap.Map("map",{ allOverlays: true });
    control = new SuperMap.Control.MousePosition();     //该控件显示鼠标移动时,所在点的地理坐标。             
    map.addControl(control);  //添加控件
    
    map.addControl(new SuperMap.Control.Navigation({ //添加Navigation控件到map
        dragPanOptions: {
            enableKinetic: true
            }
            }) );
    map.addControl(new SuperMap.Control.LayerSwitcher());
    //初始化车辆图层
    animatorVector = new SuperMap.Layer.AnimatorVector("Cars", {
        needRecordDrawedFeature: true
    }, {
        speed: 0.01,
        startTime: 0,
        //frameRate:100,
        endTime: 100
    });
    vectorLayer = new SuperMap.Layer.Vector("轨迹图层");
    addLayer();
    //设置该图层的样式
    vectorLayer.style = {
        strokeColor: "yellow",
        strokeOpacity: 0.7,
        strokeWidth: 4,
        strokeLinecap: "round",
        strokeDashstyle: "solid"
    }
    function addLayer() {
    var matrixIds = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19','20'];
    var resolutions = [0.703125, 0.3515625,0.17578125,0.087890625, 0.0439453125, 0.02197265625,0.010986328125, 0.0054931640625, 0.00274658203125, 0.001373291015625,  0.0006866455078125, 0.00034332275390625, 0.000171661376953125, 8.58306884765625e-005, 4.291534423828125e-005, 2.1457672119140625e-005, 1.0728836059570313e-005,  5.36441802978515625e-006, 2.682209014892578e-006, 1.341104507446289e-006];
    layer = new SuperMap.Layer.WMTS({
                                 name: "vec",
                                 url: "http://t0.tianditu.com/vec_c/wmts",
                                 layer: "vec",
                                 style: "default",
                                 matrixSet: "c",
                                 format: "tiles",
                                 requestEncoding: "KVP",
                                 matrixIds: matrixIds,
                                 zoomOffset: 1,
                                 buffer: 0,
                                 maxExtent: new SuperMap.Bounds(-180,-90,180,90),
                                         tileSize: new SuperMap.Size(256,256),
                                 resolutions:resolutions
                                 });                         
    var layer2 = new SuperMap.Layer.WMTS({
                                name: "cva",
                                url: "http://t0.tianditu.com/cva_c/wmts",
                                layer: "cva",
                                style: "default",
                                matrixSet: "c",
                                format: "tiles",
                                requestEncoding: "KVP"  ,
                                matrixIds: matrixIds,
                                zoomOffset: 1,
                                buffer: 0
                            });
        map.addLayers([layer,layer2,vectorLayer, animatorVector]);
        //显示地图范围
        map.setCenter(new SuperMap.LonLat(118.733287,31.991794), 14);
        map.setLayerIndex(vectorLayer,3);
            map.setLayerIndex(animatorVector,4);
            var selectFeature = new SuperMap.Control.SelectFeature(animatorVector,
                    {
                    callbacks:callbacks
                    });
            map.addControl(selectFeature);
            selectFeature.activate();
            
            console.log(map);
        getLayer(118.73771,31.98700);
    }
    //点成线、轨迹播放
    function getLayer(lon,lat) {
        animatorVector.removeAllFeatures();
        animatorVector.animator.stop();
        animatorVector.animator.start();
        var pointFeatures = [];
        var features = [];
        var ti = 100;
        var num = 1;
        for (var i = 0; i < ti; i++) {
            for (var j = 0; j < num; j++) {
                var point = new SuperMap.Geometry.Point(x, y);
                var pointFeature = new SuperMap.Feature.Vector(point, {
                    FEATUREID: j,
                    TIME: 0 + i
                }, styleCar1);
                pointFeatures.push(point);
                features.push(pointFeature);
                if (features.length >= num) {
                    x = lon;
                    y = lat;
                }
                
            }
        }
        var line = new SuperMap.Geometry.LineString(pointFeatures);
        var line_feature = new SuperMap.Feature.Vector(line);
        vectorLayer.addFeatures(line_feature);
        animatorVector.addFeatures(features);    
        
    }
    var vectorInfoWin;
    var callbacks={
        click: function(feature){
        map.events.getMousePosition(event);
        closeVectorInfoWin();
        var lonlat = map.getLonLatFromPixel(new SuperMap.Pixel(event.clientX, event.clientY));
        var popup = new SuperMap.Popup.FramedCloud("popwin",
                new SuperMap.LonLat(lonlat.lon.toFixed(5),lonlat.lat.toFixed(5)),
                null,
                "矢量图层鼠标点击事件 ",
                null,
                true);
        vectorInfoWin = popup;
        map.addPopup(popup);
        
    }
};
    
        function closeVectorInfoWin() {
            if (vectorInfoWin) {
                vectorInfoWin.hide();
                vectorInfoWin.destroy();
            }
        }
    //开始播放动画
    function startAnimator() {
        animatorVector.animator.start();
    }
    //暂停播放动画
    function pauseAnimator() {
        animatorVector.animator.pause();
    }
    //停止播放动画
    function stopAnimator() {
        animatorVector.animator.stop();
    }
</script>

</html>

1个回答

您好您这个有报什么错吗?
5,668EXP 2018年11月27日
没有任何错误,就是事件无效
上面的代码是完全可执行的代码,就是不知道为什么callbacks事件就是无效,请问您测试出原因了吗?
我这边坐标用固定值的测试的结果是正常的
...