从 Mapbox GL 中的 Geojson 数据自定义搜索
Custom search from Geojson data in Mapbox GL
我有 India Geojson file on GitHub ,from that file i want to search the state name.I have saw the mapbox GL geocoder example 但在这个例子中,我在哪里可以添加自定义 Geojson 文件进行搜索,是否可以添加自定义 json 文件,谢谢。
你在这个例子中走在了正确的轨道上。请参阅 https://github.com/mapbox/mapbox-gl-geocoder/blob/master/API.md#mapboxgeocoder 上的 API 文档,其中说:
options.localGeocoder Function? A function accepting the query string which performs local geocoding to supplement results from the Mapbox Geocoding API. Expected to return an Array of GeoJSON Features in the Carmen GeoJSON format.
因此,您只需将 GeoJSON 转换为 Carmen GeoJSON https://github.com/mapbox/carmen/blob/master/carmen-geojson.md,然后实现将您的输入查询与自定义 GeoJSON 文件的结果相匹配的功能。
Bloodhound https://github.com/twitter/typeahead.js/blob/master/doc/bloodhound.md 之类的东西可以用来提供匹配项,或者简单的正则表达式也可以。
我有 India Geojson file on GitHub ,from that file i want to search the state name.I have saw the mapbox GL geocoder example 但在这个例子中,我在哪里可以添加自定义 Geojson 文件进行搜索,是否可以添加自定义 json 文件,谢谢。
你在这个例子中走在了正确的轨道上。请参阅 https://github.com/mapbox/mapbox-gl-geocoder/blob/master/API.md#mapboxgeocoder 上的 API 文档,其中说:
options.localGeocoder Function? A function accepting the query string which performs local geocoding to supplement results from the Mapbox Geocoding API. Expected to return an Array of GeoJSON Features in the Carmen GeoJSON format.
因此,您只需将 GeoJSON 转换为 Carmen GeoJSON https://github.com/mapbox/carmen/blob/master/carmen-geojson.md,然后实现将您的输入查询与自定义 GeoJSON 文件的结果相匹配的功能。
Bloodhound https://github.com/twitter/typeahead.js/blob/master/doc/bloodhound.md 之类的东西可以用来提供匹配项,或者简单的正则表达式也可以。