Mapbox:按属性框添加搜索? [英] Mapbox: add search by attribute box?

查看:308
本文介绍了Mapbox:按属性框添加搜索?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个约30,000个多边形的GeoJSON数据集,每个多边形都附加了名称和地址.我已将其作为磁贴集上传到Mapbox.

是否可以使用Mapbox GL JS创建一个按属性搜索"框,用户可以在其中开始键入内容,搜索框根据用户的姓名和地址提供结果供您选择?按照

在Mapbox中有可能吗?我可以通过在磁贴组上运行类似 SELECT * FROM tile的名称为LIKE'%venet%'或地址为LIKE'%venet%'的东西,然后将结果连接到我自己的下拉菜单中来做到这一点,但我不知道Mapbox JS是否支持这种Ajax查询.或Mapbox JS是否提供了用于执行此操作的小部件.

我以前在 Carto.JS 中使用自定义代码进行了此操作和一个SQL Like 查询,但是我不知道Mapbox是否可行.

解决方案

尽管卢卡斯是正确的,但您不能使用数据集来做到这一点,但您说您是以 tileset .

Mapbox-GL-JS querySourceFeatures 可能会做您想要的事情:

返回一个GeoJSON Feature对象数组,这些对象表示指定矢量图块或GeoJSON源中满足查询参数的要素.

它不支持部分匹配(即%venet%),但是您可以使用它来获取视口中的所有要素,然后自己对其进行过滤.这里有一个很好的例子: https://www.mapbox.com/mapbox-gl-js/example/filter-features-within-map-view/

I have a GeoJSON dataset of about 30,000 polygons each of which has a name and address attached. I have uploaded this to Mapbox as a tileset.

Is it possible to create a 'search by attribute' box using Mapbox GL JS, where the user can start typing and the search box provides results based on the name and address for the user to choose from? Along the lines of this Mango example:

Is this possible in Mapbox? I could do it by running something like SELECT * FROM tiles WHERE name LIKE '%venet%' or address LIKE '%venet%' against the tileset, and then wiring up the results to my own dropdown, but I don't know if Mapbox JS supports that kind of Ajax query. or whether Mapbox JS provides a widget for doing this.

I've done this before in Carto.JS using custom code and a SQL LIKE query, but I don't know if it's possible with Mapbox.

解决方案

Although Lucas is correct that you can't do this with datasets you said you uploaded the data as a tileset.

The Mapbox-GL-JS querySourceFeatures may do what you want:

Returns an array of GeoJSON Feature objects representing features within the specified vector tile or GeoJSON source that satisfy the query parameters.

It doesn't support partial matching (ie, %venet%), but you could probably use it to fetch all features within the viewport, then filter them yourself. There's a good example of this here: https://www.mapbox.com/mapbox-gl-js/example/filter-features-within-map-view/

这篇关于Mapbox:按属性框添加搜索?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆