zoukankan      html  css  js  c++  java
  • 高德地图-设置直线路线

    1、问题背景

         给点了地图上两个坐标,然后连接两个点,成为一条直线


    2、实现源码

    <!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>高德地图-设置直线路线</title>
    		<link rel="stylesheet" href="http://cache.amap.com/lbs/static/main1119.css"/>
        	<script src="http://webapi.amap.com/maps?v=1.3&key=c2eb520334ddc5ab2bb70a3afe6a58cc"></script>
        	<script type="text/javascript" src="http://cache.amap.com/lbs/static/addToolbar.js"></script>
        	<style>
        		html,body{
        			 100%;
        			height: 100%;
        			font-family: "微软雅黑";
        			font-size: 12px;
        			font-feature-settings: normal;
        			font-size-adjust: initial;
        			font-stretch: extra-condensed;
        			font-synthesis: initial;
        		}
        		#lineMap{
        			 100%;
        			height: 100%;
        			font-size: 12px;
        			font-family: "arial, helvetica, sans-serif";
        		}
        	</style>
    	</head>
    	<body>
    		<div id="lineMap"></div>
    		<script>
    			//实例化和初始化地图
    			var map = new AMap.Map('lineMap', {
            		resizeEnable: true,
            		center: [114.295482,30.582582],
            		zoom: 14
        		});
        		
        		//选定两个坐标
        		var line = [
        			[114.254283,30.567507],
        			[114.328098,30.54489]
        		];
        		
        		//设置连接线样式
        		var polyline = new AMap.Polyline({
            		path: line,          //设置线覆盖物路径
            		strokeColor: "#FF0000", //线颜色
            		strokeOpacity: 0.8,       //线透明度
            		strokeWeight: 1,        //线宽
            		strokeStyle: "dashed",   //线样式
            		strokeDasharray: [10, 10] //补充线样式
        		});
        		
        		polyline.setMap(map);
    		</script>
    	</body>
    </html>
    

    3、实现结果


  • 相关阅读:
    软件版本具体代表什么意思
    面向接口的编程
    MySQL mysqldump用法
    常见问答解答
    Perl 语言笔记
    JAVA 基础知识
    面向接口编程的基本原则
    判断文件存在与否【Linux】
    Gtk Label设置字体颜色
    解压缩路径设置【Linux】
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13314176.html
Copyright © 2011-2022 走看看