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) { } }); }
时间: 2024-11-05 18:44:22