Mapbox:在传单Omnivore KML层中过滤出标记 [英] Mapbox: Filtering out markers in a Leaflet Omnivore KML layer

查看:213
本文介绍了Mapbox:在传单Omnivore KML层中过滤出标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将Google Directions路线导出为KML,并通过使用Omnivore读取它们并将其添加到地图中的方式将其显示在Mapbox地图上,

I am exporting Google Directions routes as KML and displaying them on a Mapbox map by reading them with Omnivore and adding them to the map,

Google KML将每条路线存储为两个 Places (起点和终点)和一个 LineString (路线).在Mapbox中,我只想显示路线,即以某种方式过滤掉标记.我正在从我自己的数据库中显示标记,而Google标记却将其弄乱了.

The Google KML stores each route as two Places (the start and end points) and one LineString (the route). In Mapbox I would like to show only the routes, that is to filter out the markers somehow. I'm displaying markers out of my own database and the Google markers clutter it up.

这是我的代码.我更改LineString的样式只是为了表明可以,但不知道要进行什么魔术调用才能不显示点. 谢谢.

Here is my code. I change the styling of the LineStrings just to show that I can, but do not know what magic call(s) to make to not display the Points. Thanks.

runLayer = omnivore.kml('data/xxxx.kml')
  .on('ready', function() {
    var llBnds = runLayer.getBounds();
    map.fitBounds(llBnds);

    this.eachLayer(function (layer) {

      if (layer.feature.geometry.type == 'LineString') {
        layer.setStyle({
          color: '#4E3508', 
          weight: 4
        });
      }

      if (layer.feature.geometry.type == 'Point') {
        //
        // Do something useful here to not display these items!!
        //
      }                 
    });
  })
  .addTo(map);

推荐答案

欢迎使用!

许多可能的解决方案:

  • Most straight forward from the code you provided, just use the removeLayer method on your runLayer Layer Group when you get a 'Point' feature.

更干净的解决方案是通过自定义GeoJSON图层组作为omnivore.kml的第三个参数传递,并带有指定的

Cleaner solution would be to filter out those features before they are even converted into Leaflet layers, through a custom GeoJSON Layer Group passed as 3rd argument of omnivore.kml, with a specified filter option:

var customLayer = L.geoJSON(null, {
  filter: function(geoJsonFeature) {
    // my custom filter function: do not display Point type features.
    return geoJsonFeature.geometry.type !== 'Point';
  }
}).addTo(map);

var runLayer = omnivore.kml('data/xxxx.kml', null, customLayer);

您还可以使用 style 和/或customLayer上的 onEachFeature 选项可直接应用所需的样式在您的LineString上.

You can also use the style and/or onEachFeature options on customLayer to directly apply your desired style on your LineString.

这篇关于Mapbox:在传单Omnivore KML层中过滤出标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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