我正在开发我的第一个角度网络应用程序,我想介绍一些类似于谷歌地图的东西。由于新的计费策略,我不想使用最后一个,所以我尝试了 MapBox。
按照教程,我成功创建了我需要的地图;问题是,我不知道如何在角度分量上显示它。
我为地图生成了这个文件,并且当我将其直接粘贴到我的角度项目的 index.html 上时,它可以与浏览器完美配合。但是当我尝试在组件上使用它时,我不知道该怎么做。
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<title>Points on a map</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.47.0/mapbox-gl.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.47.0/mapbox-gl.css' rel='stylesheet' />
<style>
body {
margin: 0;
padding: 0;
}
#map {
position: absolute;
top: 0;
bottom: 0;
width: 100%;
}
</style>
</head>
<body>
<div id='map'></div>
<script>
mapboxgl.accessToken = 'myToken'; // replace this with your access token
var map = new mapboxgl.Map({
container: 'map',
style: 'my style URL', // replace this with your style URL
center: [-2.8662684, 43.2806562],
zoom: 15
});
// code from the next step will go here
map.on('click', function(e) {
var features = map.queryRenderedFeatures(e.point, {
layers: ['rhynux'] // replace this with the name of the layer
});
if (!features.length) {
return;
}
var feature = features[0];
var popup = new mapboxgl.Popup({ offset: [0, -15] })
.setLngLat(feature.geometry.coordinates)
.setHTML('<h3>' + feature.properties.title + '</h3><p>' + feature.properties.description + '</p>')
.setLngLat(feature.geometry.coordinates)
.addTo(map);
});
</script>
</body>
</html>
I moved <div id="map"></div>
到组件;但抛出错误“找不到地图容器”。
我还尝试安装一些 npm 软件包,例如this one https://www.npmjs.com/package/angular-mapbox但对于像我这样的新手如何使用它没有足够的信息。
这又是一个 https://www.npmjs.com/package/ngx-mapbox-gl也没有文档...
我查看了几篇 SO 帖子,但不知道如何做到这一点。
谢谢。非常感谢您的帮助