我试图在弹出窗口中添加(2)更多行属性,然后我撞墙了。我想我需要在这里使用var函数,但几乎没有json经验,我很难挣扎。下面的代码适用于(1)属性被调用并显示在我的弹出窗口中,但就像我上面提到的,我还要显示属性[1](STATE_NAME)和[2](LINK)。两者都是带有" LINK"的文本字段。是网页的URL。任何帮助将非常感激!
附带问题,我想彻底检查弹出框是否有不同颜色的文字和框。怎么会这样做?
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<title>Partner Practices</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.39.1/mapbox-gl.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.39.1/mapbox-gl.css' rel='stylesheet' />
<style>
body { margin:0; padding:0; }
#map { position:absolute; top:0; bottom:0; width:100%; }
</style>
</head>
<body>
<style>
.mapboxgl.popup {
max-width: 600px;
font: 16px/32px 'Helvetica Neue', Arial, Helvetica, sans-serif;
}
</style>
<div id='map'></div>
<script>
mapboxgl.accessToken = 'pk.eyJ1Ijoic3RlcGhlbmdhemRpayIsImEiOiJjajdocnA1OWsxbHRrMnhxdWNuMnIwOWsyIn0.C2KZHzKkNE4pTqyfctgIPQ';
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/stephengazdik/cj7hs1cs64vzz2rp999pdjx3w',
center: [-100.04, 38.907],
zoom: 3
});
map.on('load', function () {
map.addLayer({
'id': 'States',
'type': 'fill',
'source': {
'type': 'vector',
'url': 'mapbox://stephengazdik.3sk0q5rd'
},
'source-layer': 'AllStates-80jgla',
layout: {
visibility: 'visible'
},
paint: {
'fill-color': 'rgba(0,0,0,0.0)'
}
});
// When a click event occurs on a feature in the states layer, open a popup at the
// location of the click, with description HTML from its properties.
map.on('click', 'States', function (e) {
new mapboxgl.Popup()
.setLngLat(e.lngLat)
.setHTML(e.features[0].properties.CURRENT_JO)
.addTo(map);
});
// Change the cursor to a pointer when the mouse is over the states layer.
map.on('mouseenter', 'States', function () {
map.getCanvas().style.cursor = 'pointer';
});
// Change it back to a pointer when it leaves.
map.on('mouseleave', 'States', function () {
map.getCanvas().style.cursor = '';
});
});
</script>
</body>
</html>
&#13;