reactjs - mapbox-gl-directions(插件)如何更改标记 A 和 B
问题描述
我使用这个名为 mapbox-gl-directions 的插件,有没有办法更改标记 A 和 B?我没有看到任何关于如何编辑这些标记的文档或教程,如果有感谢,请帮助我。
import { useEffect, useRef } from "react";
import mapboxgl from "mapbox-gl";
import MapboxDirection from "@mapbox/mapbox-gl-directions/dist/mapbox-gl-directions";
import * as Styles from "./styled";
import "mapbox-gl/dist/mapbox-gl.css";
import "@mapbox/mapbox-gl-directions/dist/mapbox-gl-directions.css";
mapboxgl.accessToken = process.env.REACT_APP_MAPBOX;
const Map = () => {
const mapContainer = useRef(null);
useEffect(() => {
const map = new mapboxgl.Map({
container: mapContainer.current,
style: "mapbox://styles/mystyle",
center: [121.0503, 14.5547],
zoom: 17,
});
const directions = new MapboxDirection({
accessToken: mapboxgl.accessToken,
unit: "metric",
profile: "mapbox/walking",
alternatives: true,
geometries: false,
controls: { instructions: true },
flyTo: false,
});
map.addControl(directions, "top-left");
map.scrollZoom.enable();
}, []);
return (
<div>
<Styles.Mapcontainer
ref={mapContainer}
className="map-container"
></Styles.Mapcontainer>
</div>
);
};
export default Map;
解决方案
我有另一个问题。如何更改此部分以制作自定义标记,我只能更改其颜色和文本字段
谢谢 :)
{
id: "directions-origin-point",
type: "circle",
source: "directions",
paint: {
"circle-radius": 18,
"circle-color": "#3bb2d0",
},
filter: ["all", ["in", "$type", "Point"], ["in", "marker-symbol", "A"]],
},
{
id: "directions-origin-label",
type: "symbol",
source: "directions",
layout: {
"text-field": "A",
"text-font": ["Open Sans Bold", "Arial Unicode MS Bold"],
"text-size": 12,
},
paint: {
"text-color": "#fff",
},
filter: ["all", ["in", "$type", "Point"], ["in", "marker-symbol", "A"]],
},
推荐阅读
- javascript - 如何格式化对象数组数据?(循环中的重复值,存储在数组中)
- go - Revel 框架的完全清晰的会话
- .htaccess - Htaccess 导致子域 '404 not found' 错误
- ios - 如何在 swift 中将 JSON `null` 值传递给`nil` 值?
- git - 当我只提交小的更改时,为什么 git 会压缩和写入所有项目文件?
- android - 如何将位图转换为 RoundRect 位图?
- asp.net-mvc - 如何将未经授权的用户重定向到登录页面
- c++ - 如何在 netpbm 图像中绘制平滑像素?
- html - 上传 WordPress 静态 HTML 站点后在 GitHub 上显示 404 错误
- swift - 我如何禁用在 ipad 中的 iphone 中工作的按钮,因为 ipad 具有这些功能