LeaFlet學習之地圖文字標註

在地圖上進行一些文字的標註有些場景咱們會用到,在這裏咱們文字標註用到了DivICon圖標,經過與mark相結合,將mark的圖標設置爲DivICon圖標,進行文字標註,放張圖看看效果:javascript

1、所有代碼css

<!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="Script/leaflet/leaflet.css" rel="stylesheet" />
    <style>
        #map
        {
            width:1000px;
            height:1000px;
        }
        .my-div-icon{
            font-size:15px;
            /*background:red;*/
            /*width:5px;*/
            color:red;
        }
    </style>
    <script src="Script/leaflet/leaflet.js"></script>
</head>
<body>
    <div id="map"></div>
    <script type="text/javascript">
        var map = new L.Map('map');
        var osmUrl = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
        var osm = new L.TileLayer(osmUrl, { minZoom: 1, maxZoom: 18 });
        map.addLayer(osm);
        map.setView(new L.LatLng(31.864942016, 117.2882028929), 11);
        var myIcon = L.divIcon({
            html: "狗子",
            className: 'my-div-icon',
            iconSize:30
        });
        L.marker([31.864942016,117.2882028929], { icon: myIcon }).addTo(map);
    </script>
</body>
</html>

2、總結html

html是標註的內容,iconSize是圖標大小是個正方形概念,className這是div設置類名,進行css樣式設置所用,leaflet的圖標本質上就是div容器,因此會有這個屬性,關於樣式的設置,幾乎全部的文字css樣式都能設置看你須要。地圖是加載的OSMjava

相關文章
相關標籤/搜索