• 百度 用户自定义地图 无觉


    View Code
     var tileLayer = new BMap.TileLayer();
        tileLayer.getTilesUrl = function (tileCoord, zoom) {
            var x = tileCoord.x;
            var y = tileCoord.y;
            var url = GetPyPx(x, y, zoom);
            return url;
        }
        var MyMap = new BMap.MapType('MyMap', tileLayer, { minZoom: 1, maxZoom: 3 });//定义缩放级别(目前到3级)
        var map = new BMap.Map('container', { mapType: MyMap });
        map.addControl(new BMap.NavigationControl());
        map.centerAndZoom(new BMap.Point(0,0), 1);
        /*添加标注*/
        map.addEventListener("click", showInfo);
        var ptY, ptX = '';
        var marker = new BMap.Marker(new BMap.Point(ptY, ptX));
        function showInfo(e) {
            document.getElementById("info").innerHTML = e.point.lng + ", " + e.point.lat;
            //var marker = new BMap.Marker(new BMap.Point(e.point.lng, e.point.lat));
    
            //collectClick = e;
            marker.point.lng = e.point.lng;
            marker.point.lat = e.point.lat;
           
            map.addOverlay(marker);
        }
    ///坐标系坐标转化为矩阵坐标
    function GetPyPx(x, y, zoom) {
        var level = map["zoomLevel"];
        var px, py = '';
        var url = '';
        if (level == 1) {
            if (x >= -2 && x <= 1 && y >= -2 && y <= 1) {
                px = Math.abs(y - 1);
                py = Math.abs(x + 2);
                if (px >= 0 && px <= 3 && py >= 0 && py <= 3) {
                    url = '...图层地址/Images/flw/' + zoom + '/' + zoom + '_' + px + '_' + py + '.jpg';
                } else {
                    url = '';
                }
            }
            return url;
        }
        if (level == 2) {
            if (x >= -4 && x <= 3 && y >= -4 && y <= 3) {
                px = Math.abs(y - 3);
                py = Math.abs(x + 4);
                if (px >= 0 && px <= 7 && py >= 0 && py <= 7) {
                    url = '...图层地址/Images/flw/' + zoom + '/' + zoom + '_' + px + '_' + py + '.jpg';
                } else {
                    url = '';
                }
            }
            return url;
        }
        if (level == 3) {
            if (x >= -8 && x <= 7 && y >= -8 && y <= 7) {
                px = Math.abs(y - 7);
                py = Math.abs(x + 8);
                if (px >= 0 && px <= 15 && py >= 0 && py <= 15) {
                    url = '..图层地址/Images/flw/' + zoom + '/' + zoom + '_' + px + '_' + py + '.jpg';
                } else {
                    url = '';
                }
            }
            return url;
        }
    }
    GetPyPx(x, y, zoom) 这个是用来将谷歌的切图工具转为 百度的坐标系 可以将图完整的展现.
  • 相关阅读:
    node.js简单的服务器
    简单的分页1
    定时跳转
    初始化多个vue实例对象
    js获取验证码的方法
    [z]Java代理(jdk静态代理、动态代理和cglib动态代理)
    .net操作word lib DocX
    git常用命令
    [z]查表空间使用情况
    [z]oracle job
  • 原文地址:https://www.cnblogs.com/LiMin/p/2519074.html
Copyright © 2020-2023  润新知