天天看點

高德地圖軌迹回放

<!-- 重點參數:renderOptions -->
<!doctype html>
<html lang="zh-CN">

<head>
    <!-- 原始位址://webapi.amap.com/ui/1.0/ui/misc/PathSimplifier/examples/index.html -->
    <base href="http://webapi.amap.com/ui/1.0/ui/misc/PathSimplifier/examples/" />
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
    <title>軌迹展示&巡航</title>
    <style>
    html,
    body,
    #container {
        width: %;
        height: %;
        margin: px;
    }

    #loadingTip {
        position: absolute;
        z-index: ;
        top: ;
        left: ;
        padding: px px;
        background: red;
        color: #fff;
        font-size: px;
    }
    </style>
</head>

<body>
    <div id="container"></div>
    <script type="text/javascript" src='http://webapi.amap.com/maps?v=1.3&key=你自己的key'></script>
    <!-- UI元件庫 1.0 -->
    <script src="http://webapi.amap.com/ui/1.0/main.js"></script>
    <script type="text/javascript">
    //建立地圖
    var map = new AMap.Map('container', {
        zoom: 
    });

    AMapUI.load(['ui/misc/PathSimplifier', 'lib/$'], function(PathSimplifier, $) {

        if (!PathSimplifier.supportCanvas) {
            alert('目前環境不支援 Canvas!');
            return;
        }

        //just some colors
        var colors = [
            "#3366cc", "#dc3912", "#ff9900", "#109618", "#990099", "#0099c6", "#dd4477", "#66aa00",
            "#b82e2e", "#316395", "#994499", "#22aa99", "#aaaa11", "#6633cc", "#e67300", "#8b0707",
            "#651067", "#329262", "#5574a6", "#3b3eac"
        ];

        var pathSimplifierIns = new PathSimplifier({
            zIndex: ,
            //autoSetFitView:false,
            map: map, //所屬的地圖執行個體

            getPath: function(pathData, pathIndex) {

                return pathData.path;
            },
            getHoverTitle: function(pathData, pathIndex, pointIndex) {

                if (pointIndex >= ) {
                    //point 
                    return pathData.name + ',點:' + pointIndex + '/' + pathData.path.length;
                }

                return pathData.name + ',點數量' + pathData.path.length;
            },
            renderOptions: {
                pathLineStyle: {
                    dirArrowStyle: true
                },
                getPathStyle: function(pathItem, zoom) {

                    var color = colors[pathItem.pathIndex % colors.length],
                        lineWidth = Math.round( * Math.pow(, zoom - ));

                    return {
                        pathLineStyle: {
                            strokeStyle: color,
                            lineWidth: lineWidth
                        },
                        pathLineSelectedStyle: {
                            lineWidth: lineWidth + 
                        },
                        pathNavigatorStyle: {
                            fillStyle: color
                        }
                    };
                }
            }
        });

        window.pathSimplifierIns = pathSimplifierIns;

        $('<div id="loadingTip">加載資料,請稍候...</div>').appendTo(document.body);

        $.getJSON('http://a.amap.com/amap-ui/static/data/big-routes.json', function(d) {

            $('#loadingTip').remove();

            var flyRoutes = [];

            for (var i = , len = d.length; i < len; i++) {

                if (d[i].name.indexOf('烏魯木齊') >= ) {

                    d.splice(i, , {
                        name: '飛行 - ' + d[i].name,
                        path: PathSimplifier.getGeodesicPath(
                            d[i].path[], d[i].path[d[i].path.length - ], )
                    });

                    i++;
                    len++;
                }
            }

            d.push.apply(d, flyRoutes);

            pathSimplifierIns.setData(d);

            //initRoutesContainer(d);

            function onload() {
                pathSimplifierIns.renderLater();
            }

            function onerror(e) {
                alert('圖檔加載失敗!');
            }

            var navg2 = pathSimplifierIns.createPathNavigator(, {
                loop: true,
                speed: ,
                pathNavigatorStyle: {
                    width: ,
                    height: ,
                    content: PathSimplifier.Render.Canvas.getImageContent('./imgs/car.png', onload, onerror),
                    strokeStyle: null,
                    fillStyle: null
                }
            });

            navg2.start();
        });
    });
    </script>
</body>

</html>