gpt4 book ai didi

javascript - 我如何在 leaflet.js 中设置 layer.control 的样式?

转载 作者:技术小花猫 更新时间:2023-10-29 11:48:49 24 4
gpt4 key购买 nike

我正在尝试更改图层控件中的默认下拉菜单图标。我想在图标旁边加上文字。有什么办法吗?也许使用 JQuery 和 CSS?

我正在基于此示例开发传单元素:http://leafletjs.com/examples/layers-control.html

代码:

<html>
<head>
<title>Leaflet Layers Control Example</title>
<meta charset="utf-8" />

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<link rel="stylesheet" href="../dist/leaflet.css" />
</head>
<body>
<div id="map" style="width: 600px; height: 400px"></div>

<script src="../dist/leaflet.js"></script>
<script>
var cities = new L.LayerGroup();

L.marker([39.61, -105.02]).bindPopup('This is Littleton, CO.').addTo(cities),
L.marker([39.74, -104.99]).bindPopup('This is Denver, CO.').addTo(cities),
L.marker([39.73, -104.8]).bindPopup('This is Aurora, CO.').addTo(cities),
L.marker([39.77, -105.23]).bindPopup('This is Golden, CO.').addTo(cities);


var cmAttr = 'Map data &copy; 2011 OpenStreetMap contributors, Imagery &copy; 2011 Clou dMade',
cmUrl = 'http://{s}.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/{styleId}/256/{z}/{x}/{y}.png';

var minimal = L.tileLayer(cmUrl, {styleId: 22677, attribution: cmAttr}),
midnight = L.tileLayer(cmUrl, {styleId: 999, attribution: cmAttr}),
motorways = L.tileLayer(cmUrl, {styleId: 46561, attribution: cmAttr});

var map = L.map('map', {
center: [39.73, -104.99],
zoom: 10,
layers: [minimal, motorways, cities]
});

var baseLayers = {
"Minimal": minimal,
"Night View": midnight
};

var overlays = {
"Motorways": motorways,
"Cities": cities
};

L.control.layers(baseLayers, overlays).addTo(map);
</script>

最佳答案

leaflet.css 之后添加此样式:

<style>
.leaflet-control-layers-toggle:after{
content:"your text";
color:#000 ;
}
.leaflet-control-layers-toggle{
width:auto;
background-position:3px 50% ;
padding:3px;
padding-left:36px;
text-decoration:none;
line-height:36px;

}
</style>

关于javascript - 我如何在 leaflet.js 中设置 layer.control 的样式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21078310/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com