Closed kobeyk closed 3 years ago
I tried again, and was pleasantly surprised to find that it was ok,it like this:
// pbf矢量瓦片
const vectorSourceProps = {
id: 'vectorSourceExample',
tileUrlTemplates: [
'http://localhost:8082/datamg/services/vectortile?x={x}&y={y}&l={z}&crs=EPSG:3857&serviceId=1359673693088064',
],
};
<MapboxGL.VectorSource
{...vectorSourceProps}
ref={(source) => {
this._vectorSource = source;
}}
onPress={(e) => {
console.log("geometry",e.features[0].geometry)
alert(`建筑名称: ${e.features[0].properties.name}`);
}}
>
<MapboxGL.FillLayer
id="building3D"
sourceID="vectorSourceExample"
sourceLayerID="园区" // 这个很关键,这个必须匹配上,否则图层无法显示
/>
</MapboxGL.VectorSource>
效果如下:
Up here on the Web side, it works fine,but it doesn't work on mobile
Why does this work in the example? I want to know what the URL refers to. Is it a mapbox style or TileJSON data?
I have two URLs, one is the following(please ignore the address, I want to be more realistic):
Another is : http://localhost:8080/3, The URL points to a Style style structure,like this:
Now, my question is, I've tried both and they don't work, what should I do to make VectorSource work, thank you very much!