第一次更新:
代码说明:
html中是页面的基本骨架
- 添加checkbox标签,用户可以选择 Vector Label 或 Overlay Label 类型;
- 添加text标签,输入想要添加的文字标记;
- 添加button按钮,用来启动文字标注功能和清除地图上的标注;
- 添加map的div
- 添加标注点的div
js代码实现功能
- 创建ONE类,添加Map属性,并指定相应的默认值;
- 在类中添加DrawingAndTextAnnotation属性,在其中声明相应的变量;
- 创建标签的样式;
- ······
 在代码注释中都有具体的解释
html:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>添加图文标注</title>
    <link href="./css/ol.css" rel="stylesheet" type="text/css"/>
    <script src="./js/ol.js" type="text/javascript"></script>
    <script src="./externalJS/index.js" type="text/javascript"></script>
    <!--  引入第三方插件库 -->
    <script src="./libs/jquery.min.js" type="text/javascript"></script>
    <style type="text/css">
        #menu {
            width: 100%;
            height: 20px;
            padding: 5px 10px;
            left: 10px;
            font-size: 14px;
            font-family: "微软雅黑";
        }
        .checkbox {
            margin: 5px 15px;
        }
        .marker {
            width: 20px;
            height: 20px;
            border: 1px solid #088;
            border-radius: 10px;
            /*background-color:#0FF;*/
            background-color: #000000;
            opacity: 0.5;
        }
        .address {
            text-decoration: none;
            color: #566F89;
            font-size: 14px;
            font-weight: bold;
            text-shadow: #E4F1FF 1em 1em 1em ;
            background: #C5DFF8;
        }
    </style>
</head>
<body>
<div id="menu">
    <label class="checkbox">
        <input type="radio" name="label" value="vector" checked="checked"/>
        Vector Label
    </label>
    <label class="checkbox">
        <input type="radio" name="label" value="overlay"/>
        Overlay Label
    </label>
      
    <label>请输入需要添加的文字:</label>
    <input type="text" id="DrawingAndTextAnnotationInputText" value=""/>
    <input type="button