zoukankan      html  css  js  c++  java
  • 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);
                }
            }

  • 相关阅读:
    dede list调用 内容模型 附件
    dedecms list标签调用附加表字段--绝对成功
    织梦系统站点首页、列表、文章页等页面点击数调用方法
    apache include 文件包含引用的方法 报错 [an error occurred while processing this directive]
    windows 2008 中IIS7.0以上如何设置404错误页面
    织梦Fatal error: Call to a member function GetInnerText()
    dedecms清空栏目后,新建ID不从1开始的解决方法
    js禁止
    AngularJs表单验证
    submile 安装,汉化,插件
  • 原文地址:https://www.cnblogs.com/ruoshui/p/2157369.html
Copyright © 2011-2022 走看看