mapbox - 如何在 Mapbox 中通过 url 添加自定义标记?
问题描述
我的地图基于 mapbox 示例。那里的标记设置为“圆圈”。如果出现以下代码,如何通过 url 添加自定义标记?
function makeGeoJSON(csvData) {
csv2geojson.csv2geojson(
csvData,
{
latfield: "Latitude",
lonfield: "Longitude",
delimiter: ","
},
function(err, data) {
data.features.forEach(function(data, i) {
data.properties.id = i;
});
geojsonData = data;
// Add the the layer to the map
map.addLayer({
id: "locationData",
type: "circle",
source: {
type: "geojson",
data: geojsonData
},
paint: {
"circle-radius": 5, // size of circles
"circle-color": "green", // color of circles
"circle-stroke-color": "white",
"circle-stroke-width": 1,
"circle-opacity": 0.7
}
});
}
);
解决方案
您需要使用map.loadImage
并map.addImage
添加自定义图标,如以下 Mapbox 示例所示:
map.loadImage('http://placekitten.com/50/50', function(error, image) {
if (error) throw error;
// Add the loaded image to the style's sprite with the ID 'kitten'.
map.addImage('kitten', image);
});
然后,您需要使用引用该图标的符号层kitten
(在本例中)。
推荐阅读
- javascript - 语句未在 if 语句内触发
- javascript - Webpack:获取目录中所有文件名的地图
- excel - 怎么抢
- android - 在 TextView 中显示 ArrayMap 的对象
- c - 检查命令行输入是否为数字
- pandas - 数据框每一行的 Pandas 调用函数
- swift - 使用 json 和 swift 文件对 Next/Previous 有任何想法
- google-sheets - Google 表格 - 通过唯一字符串查找
- azure-api-management - Azure API 管理服务自定义域
- android - 如果我使用 ViewModelFactory,为什么会出现错误“e:错误:无法访问数据源”?