高德地图 JS API示例-自有数据图层- ›img作为切片

高德地图 JS API示例-自有数据图层- ›img作为切片

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
    <title>TileLayer.Flexible</title>
    <style>
        html,
        body,
        #container {
            margin: 0;
            padding: 0;
            width: 100%;
            height: 100%;
        }
    </style>
</head>
<body>
<div id="container"></div>
<script src="//webapi.amap.com/maps?v=1.4.15&key=您申请的key值"></script>
<script>
    var map = new AMap.Map('container', {
        resizeEnable: true,
        zoom: 14,
        zooms: [3, 20],
        expandZoomRange: true
    });

    //该demo可模拟水印效果
    var layer = new AMap.TileLayer.Flexible({
        cacheSize: 30,
        opacity: 0.3,
        createTile: function (x, y, z, success, fail) {
            if ((x + y) % 3) {
                fail();
                return;
            }

            var img = document.createElement('img');
            img.onload = function () {
                success(img)
            };
            // img.crossOrigin = "anonymous";//3D 的时候添加,同时图片要有跨域头
            img.onerror = function () {
                fail()
            };

            img.src = 'https://a.amap.com/jsapi_demos/static/images/amap.png';
        }
    });

    layer.setMap(map);

</script>
</body>
</html>
0 0 投票数
文章评分
订阅评论
提醒
0 评论
内联反馈
查看所有评论
0
希望看到您的想法,请您发表评论x