在Angular 8应用中,如果Mapbox的标记样式(Marker Style)或CSS不起作用,可以尝试以下解决方法:
确保在angular.json文件中的styles数组中也引入了Mapbox CSS文件:
"styles": [
"src/styles.css",
"node_modules/mapbox-gl/dist/mapbox-gl.css"
],
import * as mapboxgl from 'mapbox-gl';
import 'mapbox-gl/dist/mapbox-gl.css';
const marker = new mapboxgl.Marker({color: 'red'})
.setLngLat([longitude, latitude])
.addTo(map);
或者使用内联样式:
const marker = new mapboxgl.Marker()
.setLngLat([longitude, latitude])
.getElement().style.backgroundColor = 'red';
.mapboxgl-marker {
/* 添加!important关键字 */
background-color: red !important;
}
通过上述方法,应该能够解决在Angular 8应用中Mapbox标记样式或CSS不起作用的问题。
上一篇:Angular 8应用在控制台中产生与ng-bootstrap相关的运行时错误。
下一篇:Angular 8有没有办法在每次按键时停止触发按钮上的[disabled] = "somefunc()"函数?