会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 128778个问题
WEB前端全系列/第九阶段:HTML5新特性模块/HTML5新特性 18楼

index.zip

老师这个整体画布跟着在旋转颜色还都变成秒针的颜色了

WEB前端全系列/第九阶段:HTML5新特性模块/HTML5新特性 19楼
WEB前端全系列/第九阶段:HTML5新特性模块/HTML5新特性 20楼
WEB前端全系列/第九阶段:HTML5新特性模块/HTML5新特性 22楼
WEB前端全系列/第九阶段:HTML5新特性模块/(旧)H5新特性 25楼

<!DOCTYPE html>
<html lang="en">

<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" />
    <script type="text/javascript"
        src="https://api.map.baidu.com/api?v=2.0&ak=FbonyatSbRvrD6W2ApVIpz5BGT9wE18a"></script>

    <title>Document</title>
    <style type="text/css">
        html {
            height: 100%
        }

        body {
            height: 100%;
            margin: 0px;
            padding: 0px
        }

        #container {
            height: 500px;
            width: 700px;
            border: 1px solid black;
            margin: 30px;
        }
    </style>
</head>

<body>
    <div id="container"></div> <br>
    <label for="startPoint">
        起点:<input type="text" id="startPoint" value="广东省广州市越秀区环市西路179号">
    </label>
    <label for="endPoint">
        终点:<input type="text" id="endPoint" value="广东省广州市白云区广园西路133号">
    </label>
    <select>
        <option value="bus">公交</option>
        <option value="car">自驾</option>
        <option value="step">不行</option>
    </select><br>
    <button class="route">规划路线</button>
    <button class="load">加载</button>
    <script>
        var startPoint_input = document.querySelector('#startPoint');
        var endPoint_input = document.querySelector('#endPoint');
        var routeBtn = document.querySelector('.route')
        var map = null;
        document.querySelector('.load').onclick = function () {
            map = new BMap.Map("container");
            var point = new BMap.Point(113.26512290418745, 23.154485582798717);//设置中心点 经纬度
            map.centerAndZoom(point, 15);//地图初始化,同时设置地图展示级别 登记1-21  数值越大 
            map.addControl(new BMap.NavigationControl());//平移缩放
            //加载时所在地点标注
            var centerMarker = new BMap.Marker(point);
            map.addOverlay(centerMarker);
            centerMarker.addEventListener('click', function (eve) {
                var opts = {
                    width: 250,     // 信息窗口宽度    
                    height: 100,     // 信息窗口高度    
                    title: '你现在地址在:'  // 信息窗口标题   
                }

                var geoc = new BMap.Geocoder()
                geoc.getLocation(eve.point, function (info) {
                    var addressStr = info.address;
                    var infoWindow = new BMap.InfoWindow(addressStr, opts);  // 创建信息窗口对象    
                    map.openInfoWindow(infoWindow, map.getCenter());
                    event.stopPropagation();
                })

            })

            map.addEventListener('click', function (eve) {
                var geoc = new BMap.Geocoder()
                geoc.getLocation(eve.point, function (info) {
                    console.log(info);
                })

                var Marker = new BMap.Marker(eve.point);
                map.addOverlay(Marker);

            })
        }
        routeBtn.onclick = function () {
            startPoint_input_value = startPoint_input.value;
            endPoint_input_value = endPoint_input.value;
            var router_value = document.querySelector('select').value;
            switch (router_value) {
                case'bus':
                    {
                        var transit = new BMap.TransitRoute(map, {
                            renderOptions: {
                                map: map,
                                autoViewport: true
                            }
                        });
                        transit.search(startPoint_input_value, endPoint_input_value)
                    }

                    break;
                case 'car': {
                    var driving = new BMap.DrivingRoute(map, {
                        renderOptions: {
                            map: map,
                            autoViewport: true//自动切换视野
                        }
                    });
                    driving.search(startPoint_input_value, endPoint_input_value);//绘制路线图
                }
                    break;
                case 'step': {
                    var walk = new BMap.WalkingRoute(map, {
                        renderOptions: { map: map }
                    });
                    walk.search(startPoint_input_value, endPoint_input_value);//绘制路线图
                }
                    break;
            }

        }
    </script>
</body>

</html>

老师  我为啥公交那个方案不会显示   为啥汇报这些错 

image.png

WEB前端全系列/第九阶段:HTML5新特性模块/(旧)H5新特性 26楼

<!DOCTYPE html>
<html lang="en">
<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" /> 
    <script type="text/javascript" src="https://api.map.baidu.com/api?v=3.0&ak=FbonyatSbRvrD6W2ApVIpz5BGT9wE18a"></script>

    <title>Document</title>
    <style type="text/css">  
        html{height:100%}    
        body{height:100%;margin:0px;padding:0px}    
        #container{height:500px;width: 700px; border: 1px solid black;}    
    </style> 
</head>
<body>
    <div id="container"></div> 
    <button>加载</button>
    <script>
        var btn=document.querySelector('button');
        btn.onclick=function(){
            var map = new BMap.Map("container");    
var point = new BMap.Point(113.26512290418745, 23.154485582798717);    
map.centerAndZoom(point, 15);    
map.addControl(new BMap.NavigationControl());//平移缩放
//默认标注
// map.addEventListener('click',function(eve){
//     var tempMarker = new BMap.Marker(eve.point);        // 创建标注    
// map.addOverlay(tempMarker);  
// }


//------------------------自定义图标-------------------
var temPoint = new BMap.Point(113.26552290418745, 23.154485582798717);
var myIcon = new BMap.Icon("imgs/标注.gif", new BMap.Size(50, 50), {    
        // 指定定位位置。   
        // 当标注显示在地图上时,其所指向的地理位置距离图标左上    
        // 角各偏移10像素和25像素。您可以看到在本例中该位置即是   
        // 图标中央下端的尖角位置。    
        anchor: new BMap.Size(10, 25),    
        // 设置图片偏移。   
        // 当您需要从一幅较大的图片中截取某部分作为标注图标时,您   
        // 需要指定大图的偏移位置,此做法与css sprites技术类似。    
        imageOffset: new BMap.Size(-30, 10)   // 设置图片偏移    
    });      
    // 创建标注对象并添加到地图   
    var Mymarker = new BMap.Marker(temPoint, {icon: myIcon});    
    map.addOverlay(Mymarker);    
        }
    </script>
</body>
</html>

我的自定义图片怎么加载不了出来

WEB前端全系列/第九阶段:HTML5新特性模块/(旧)H5新特性 27楼

<!DOCTYPE html>
<html lang="en">
<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" />  
    <script type="text/javascript" src="https://api.map.baidu.com/api?v=1.0&&type=webgl&ak=FbonyatSbRvrD6W2ApVIpz5BGT9wE18a"></script>
    <title>百度地图</title>
    <style type="text/css">  
        html{height:100%}    
        body{height:100%;margin:0px;padding:0px}    
        #container{height:500px;width: 700px; border: 1px solid black;}    
    </style> 
</head>
<body>
    <div id="container"></div> 
    <button>加载</button>
    <script>
      var btn=document.querySelector('button');
      btn.onclick=function(){
        var map = new BMapGL.Map("container");
        var point = new BMapGL.Point(116.404, 39.915);//设置中心点 经纬度
        map.centerAndZoom(point, 15);//地图初始化,同时设置地图展示级别 登记1-21  数值越大 
        /*地球模式*/
        // map.centerAndZoom(new BMapGL.Point(118.5, 27.5), 15);  // 初始化地图,设置中心点坐标和地图级别
        // map.enableScrollWheelZoom(true);     //开启鼠标滚轮缩放
        // map.setMapType(BMAP_EARTH_MAP);      // 设置地图类型为地球模式
     //添加控件(系统)
//      map.addControl(new BMapGL.ScaleControl())//比例尺

//      map.addControl(new BMap.OverviewMapControl()); //缩略图
// //      var cityCtrl = new BMapGL.CityListControl();  // 添加城市列表控件
// // map.addControl(cityCtrl);
// map.addControl(new BMapGL.MapTypeControl())

/*自定义插件
自定义摆放位置
anchor:自定义摆放位置
offset:自定义偏移量offset(x,y)
type:控件加载类型
*/
var options={
    anchor:BMAP_ANCHOR_BOTTOM_RIGHT,
    offset:BMAP_ANCHOR_BOTTOM_RIGHT,

}
map.addControl(new BMap.NavigationControl(options));

      }
    </script>
</body>
</html>

老师 是不是现在百度地图这个api没写出来的控件类型就用不了了  好像这个平移缩放和缩略图控件

image.png

image.png

WEB前端全系列/第九阶段:HTML5新特性模块/(旧)H5新特性 28楼

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>

    <video src="" height="500px" width="500px" id="video"></video>
    <canvas id="canvas" width="500px" height="500px"></canvas>
    <button class="btn1" onclick="getMedia()">视频</button>
    <button class="btn2" onclick="takePhone()">拍照</button>
    <script>
      /*调用用户设备
      *调用摄像头  移动端会给用户选择 1打开相册 2打开摄像头  pc端直接调用摄像头

      *调用麦克风  直接调用

      *调用方法getUserMedia();
      * Navigator.mediaDevices.getUserMedia(constraints,successCallback,errorCallback)
      
      * constraints 设备类型
      {
      video:true  //s摄像头
      Audio: true //麦克风 
      }
      */
     function getMedia(){
         var video=document.getElementById('video');
         /*
         Navigator.mediaDevices.getUserMedia  该方法返回一个promise对象
         当该方法对象成功返回后 的回掉函数会带有一个MediaStream对象作为其参数
         then()是promise的异步方法,当then()前的所有方法执行完毕后在执行then()方法避免数据没有获取到
          */
         var constraints={
             video:{height:500,width:500},
             audio:true
         }
        var promise=navigator.mediaDevices.getUserMedia(constraints)
        promise.then(function(MediaStream){
            video.srcObject=MediaStream;
            video.play();
        })
     }

    </script>
</body>
</html>

老师不行喔 报错  是因为我电脑没摄像头吗  但是手机打不开

image.png

WEB前端全系列/第九阶段:HTML5新特性模块/(旧)H5新特性 29楼
WEB前端全系列/第九阶段:HTML5新特性模块/(旧)H5新特性 30楼

百战程序员微信公众号

百战程序员微信小程序

©2014-2024 百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备18060230号-3    营业执照    经营许可证:京B2-20212637