OpenLayers 3 实现轨迹回放

  function PathBack() {
        var PVLayer = new ol.layer.Vector({
            source: new ol.source.Vector({})
        });
        var pointList = new Array();
        map.addLayer(PVLayer);
        $.ajax({
            type: "get",
            url: "images/zb.json",
            async: false,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (data) {
                var obj = data.T_Project;
                for (var i = 0; i < obj.length; i++) {
                    var pointFeature = new ol.Feature({
                        geometry: new ol.geom.Point(ol.proj.transform([parseFloat(obj[i].x), parseFloat(obj[i].y)], 'EPSG:4326', 'EPSG:3857'))
                    })
                    var propertieList = new Array();
                    //     propertieList.push(obj[i].ID, obj[i].x, obj[i].y, obj[i].Note);
                    propertieList.push(obj[i].ID, obj[i].x, obj[i].y);
                    pointFeature.setProperties(propertieList);
                    if (pointFeature != null) {
                        pointList.push(pointFeature);
                    }
                }

                var stoptime = setInterval(function () {
                    if (j + 1 <= pointList.length) {
                        if (j > 0) {
                            var twoCoordinatePoint = new Array();
                            var coordinateFirst = pointList[j - 1].getGeometry().getCoordinates();
                            var coordinateSecond = pointList[j].getGeometry().getCoordinates();
                            twoCoordinatePoint.push(coordinateFirst);
                            twoCoordinatePoint.push(coordinateSecond);
                            var lineString = new ol.geom.LineString(twoCoordinatePoint);

                            var lineFeature = new ol.Feature({
                                geometry: lineString
                            });

                            PVLayer.getSource().addFeature(lineFeature);
                            pointList[j - 1].setStyle(null);
                        }
                        pointList[j].setStyle(iconstyle);
                        PVLayer.getSource().addFeature(pointList[j]);
                    }
                    else {
                        clearInterval(stoptime);
                    }
                    j++;
                }, 300);

            },
            error: function (result) {

            }
        });
    }

 

转载于:https://www.cnblogs.com/sjfsjf/p/6565638.html

你可能感兴趣的:(OpenLayers 3 实现轨迹回放)