简体   繁体   English

传单圈标记不显示

[英]Leaflet circleMarkers don´t show up

I am trying to draw hundres of circleMarker in a Leaflet map, I am using flask and foundation.js, the same code work in different app built with bootstrap.js我正在尝试在 Leaflet 地图中绘制数百个 circleMarker,我正在使用 Flask 和 Foundation.js,相同的代码在使用 bootstrap.js 构建的不同应用程序中工作

This is my code:这是我的代码:

<script src="http://cdn.leafletjs.com/leaflet-0.5.1/leaflet.js"></script>
  <script>
    var map = L.map('map').setView([40,-4], 6);

    L.tileLayer('https://{s}.tiles.mapbox.com/v3/examples.map-cnkhv76j/{z}/{x}/{y}.png', {
            attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery  <a href="http://cloudmade.com">CloudMade</a>',
            maxZoom: 18
        }).addTo(map);

    var geojsonMarkerOptions = {
    radius: 100,
    fillColor: "#FFF803",
    color: "#DDFF03",
    weight: 1,
    opacity: 0.8,
    fillOpacity: 0.8
    };

    {% for item in data['data'] %}        
    L.circleMarker([{{item[0]}},{{item[1]}}],geojsonMarkerOptions).addTo(map);
    {% endfor %} 

    var marker = L.marker([41.5, -0.09]).addTo(map);
    marker.bindPopup("I am a circle.");
    var circle = L.circle([51.508, -0.11], 500, {color: 'red',
                                                fillColor: '#f03',
                                                fillOpacity: 1
                                                }).addTo(map); 
</script>

At the bottom I tried a fixed marker which appears and fixed circle which doesn´t, could it be a problem with foundation.js?在底部,我尝试了一个出现的固定标记和没有出现的固定圆圈,这是foundation.js 的问题吗? Because in a previous project with other framework worked perfectly.因为在以前的项目中使用其他框架完美地工作。

I tried your code , replacing 51.508 with 41.508 (so the red circle is near the marker) and adding just a single circleMarker.尝试了您的代码,将51.508替换为41.508 (因此红色圆圈靠近标记)并仅添加一个 circleMarker。 It works.有用。 So the problem is not in the code.所以问题不在代码中。

Please check that you have included leaflet.css from the same locations as leaflet.js .请检查您是否已经包括leaflet.css从作为同一位置leaflet.js Also check there are no errors in a javascript console (Ctrl+Shift+J in Firefox).还要检查 javascript 控制台中没有错误(Firefox 中的 Ctrl+Shift+J)。 Check that coordinates from {{item[0/1]}} are properly formatted (decimal separator is a dot, no extra symbols).检查{{item[0/1]}}中的坐标格式是否正确(十进制分隔符是一个点,没有额外的符号)。 Try using more recent version of Leaflet library, 0.7.3.尝试使用更新版本的 Leaflet 库,0.7.3。

Ilja, many thanks.伊利亚,非常感谢。 You were right the circles were pushed behind the map by a css.你是对的,圆圈被 css 推到了地图后面。 In this case, I was also using d3.js for some chart, and as soon as I got rid of nvd3's css the circles showed up.在这种情况下,我还在一些图表中使用了 d3.js,一旦我摆脱了 nvd3 的 css,圆圈就会出现。

I've been having the same issue, and it turns out that it is the nv.d3.css file.我遇到了同样的问题,结果是 nv.d3.css 文件。 I found that commenting out these lines will allow you to draw a circle:我发现注释掉这些行可以让你画一个圆圈:

display: block; 
width: 100%; 
height: 100%;'

I don't know what potential side effects this might have on your page, but I think the main issue is that d3 decides to hijack any svgs that you put on the page.我不知道这可能对您的页面有什么潜在的副作用,但我认为主要问题是 d3 决定劫持您放在页面上的任何 svg。

EDIT: my case was with circles, but I wouldn't be surprised if it is the same problem between circles and circle markers.编辑:我的情况是圆圈,但如果圆圈和圆圈标记之间存在相同的问题,我不会感到惊讶。

EDIT 2: It's been a while, but someone just liked this, so I feel like I should inform you that in the end, these didn't play nice together.编辑 2:已经有一段时间了,但有人喜欢这个,所以我觉得我应该告诉你,最后,这些并没有很好地配合。 I didn't have the time to really tinker with it, so I was forced to remove the leaflet circles and pass on the project with a recommendation that it might just be easier to plug in Google Maps.我没有时间真正修改它,所以我被迫删除传单圆圈并传递该项目,并建议插入谷歌地图可能更容易。 Hope that's helpful.希望这有帮助。

That question was posted long ago.这个问题很久以前就发过了。 But May my answer helps someone.但愿我的回答对某人有所帮助。

When we instanciate L.CircleMarker(...) , the circle is created, but not showing.当我们实例化L.CircleMarker(...) 时,圆被创建,但不显示。 In my case, i noticed that it wait for the window resize event in order to display.就我而言,我注意到它等待窗口调整大小事件才能显示。 So juste trigger that event after L.CircleMarker(...).addTo(map) and the circle will appear like a charm.所以justeL.CircleMarker(...).addTo(map)之后触发该事件,圆圈将看起来像一个魅力。

With JS用JS

 window.dispatchEvent(new Event('resize'));

With Jquery使用jQuery

$(window).trigger('resize');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM