typescript - 搜索时使用 Leaflet Geocoder 而不设置标记
问题描述
目前我正在使用传单地图并添加了这个地理编码器插件:https ://github.com/perliedman/leaflet-control-geocoder 。我的问题是,每次我搜索一个地方时,它也会在这个位置设置一个标记,但我不希望它这样做。它应该只放大而不设置标记。
有人知道如何禁用此功能或立即删除设置标记吗?
我在 Ionic/typescript 中工作,我使用地理编码器的代码是这样的:
leaflet.Control.geocoder().addTo(this.map);
根据 GitHub,defaultMarkGeocode:false 应该禁用标记。使用它时,我只是收到此错误:
无法读取未定义的属性“_leaflet_id”
我也试过
var geocoder = L.Control.geocoder({
defaultMarkGeocode: false
})
.on('markgeocode', function(e) {
var bbox = e.geocode.bbox;
var poly = L.polygon([
bbox.getSouthEast(),
bbox.getNorthEast(),
bbox.getNorthWest(),
bbox.getSouthWest()
]).addTo(map);
map.fitBounds(poly.getBounds());
})
.addTo(map);
但它只是告诉我变量地理编码器从未使用过,我收到此错误:
无法读取未定义的属性“addLayer”
如果您对如何修复它以及禁用或删除此标记有任何建议,我将不胜感激。
问候
解决方案
Could not reproduce the exact error messages you describe:
var map = L.map('map').setView([0, 0], 2);
var geocoder = L.Control.geocoder({
defaultMarkGeocode: false,
collapsed: false
})
.on('markgeocode', function(e) {
var bbox = e.geocode.bbox;
var poly = L.polygon([
bbox.getSouthEast(),
bbox.getNorthEast(),
bbox.getNorthWest(),
bbox.getSouthWest()
]).addTo(map);
map.fitBounds(poly.getBounds());
})
.addTo(map);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
html,
body,
#map {
height: 100%;
margin: 0;
}
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.3.1/dist/leaflet.css" integrity="sha512-Rksm5RenBEKSKFjgI3a41vrjkw4EVPlJ3+OiI65vTjIdo9brlAacEuKOiQ5OFh7cOI1bkDwLqdLw3Zg0cRJAAQ==" crossorigin="" />
<script src="https://unpkg.com/leaflet@1.3.1/dist/leaflet-src.js" integrity="sha512-IkGU/uDhB9u9F8k+2OsA6XXoowIhOuQL1NTgNZHY1nkURnqEGlDZq3GsfmdJdKFe1k1zOc6YU2K7qY+hF9AodA==" crossorigin=""></script>
<link rel="stylesheet" href="https://unpkg.com/leaflet-control-geocoder@1.5.8/dist/Control.Geocoder.css" />
<script src="https://unpkg.com/leaflet-control-geocoder@1.5.8/dist/Control.Geocoder.js"></script>
<div id="map"></div>
However when collapsed
option is set to false
, there is another error message:
TypeError: this.options.geocoder[mode] is not a function
…which is solved in plugin repo by PR perliedman/leaflet-control-geocoder#184, but it is not yet shipped in a released version in npm / unpkg CDN.
If you need further help on your error messages, please provide code that reproduces them.
推荐阅读
- azure - 如何禁用 Azure WAF 强制规则?
- javascript - 如何在 FlatList 中选择单个项目
- python - 在方法中复制函数签名
- docker - 想要在 localhost Kube Services 上运行 NodePort
- javascript - 从单个 javascript 数组创建 spyscroll html
- python - 根据python中的两个元素对子列表进行两次排序
- ios - 如何将数组附加到字典?
- javascript - 警告:道具类型失败:提供给“路由”的道具“组件”无效:道具不是路由中的有效 React 组件
- ios - 即使应用程序在 iOS 中终止,我们还能运行后台任务吗
- python - 我们可以在创建记录器对象时指定用户吗