• openlayers轨迹回放


      var vectorLayer, markers, lineFeature;
            var px, py;
            var x = 0;
            function startReplay() {
                //feature style
                var style_green = {
                    strokeColor: "#339933",
                    strokeOpacity: 1,
                    strokeWidth: 3,
                    pointRadius: 6,
                    pointerEvents: "visiblePainted"
                };


                px = Math.random() * (122 - 121 + 0.001) + 121;
                py = Math.random() * (30 - 29 + 0.001) + 29;
                var lonlat = new OpenLayers.LonLat(px, py);
                var zoom = map.getZoom();
                map.setCenter(lonlat, zoom);

                vectorLayer = new OpenLayers.Layer.Vector("route");
                map.addLayer(vectorLayer);

                markers = new OpenLayers.Layer.Markers("marker");
                map.addLayer(markers);


                var imgUrl = "Images/car.png";
                var icon = new OpenLayers.Icon(imgUrl);
                var marker = new OpenLayers.Marker(lonlat, icon);
                markers.addMarker(marker);


                lineFeature = new OpenLayers.Feature.Vector(
                    new OpenLayers.Geometry.LineString(lonlat.lon, lonlat.lat), null, style_green);
                vectorLayer.addFeatures([lineFeature]);

                fn();

            }

            function fn() {
                if (x < 20) {
                    px = Math.random() * (122 - 121 + 0.001) + 121;
                    py = Math.random() * (30 - 29 + 0.001) + 29;
                    var lonlat = new OpenLayers.LonLat(px, py);
                    var zoom = map.getZoom();
                    map.setCenter(lonlat, zoom);

                    var newPoint = new OpenLayers.Geometry.Point(lonlat.lon, lonlat.lat);
                    lineFeature.geometry.addPoint(newPoint);
                    vectorLayer.drawFeature(lineFeature);


                    markers.clearMarkers();
                    var imgUrl = "Images/car.png";
                    var icon = new OpenLayers.Icon(imgUrl);
                    var marker = new OpenLayers.Marker(lonlat, icon);
                    markers.addMarker(marker);
                    x++;
                    setTimeout(fn, 1000);
                }
            }

  • 相关阅读:
    2019.10.25 csp-s模拟测试87 反思总结
    2020.7.13
    2020.7.12 5. 最长回文子串
    全序列匹配(java)
    2020.7.10 刷题
    Matlab可视化小结
    C-means
    银行家算法(java swing)界面
    完全数——多线程 (Java)
    SIR模型实现(matlab)
  • 原文地址:https://www.cnblogs.com/ruoshui/p/2157369.html
Copyright © 2020-2023  润新知