Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 传单中的数据循环_Javascript_Loops_Leaflet - Fatal编程技术网

Javascript 传单中的数据循环

Javascript 传单中的数据循环,javascript,loops,leaflet,Javascript,Loops,Leaflet,我有1000个地理数据点和一张美国地图。我想在这1000个地理数据点中的每个点上创建一个小圆圈。我的数据是geojson格式的。 我可以一次在一个点上创建一个圆。但是如何在数据集上循环以在每个点上创建圆呢 这是我的圆圈代码: var circle = L.circle([64.837778, -147.716389], 500, { color: 'black', fillColor: '#000', fillOpacity: 0.8 })

我有1000个地理数据点和一张美国地图。我想在这1000个地理数据点中的每个点上创建一个小圆圈。我的数据是geojson格式的。 我可以一次在一个点上创建一个圆。但是如何在数据集上循环以在每个点上创建圆呢

这是我的圆圈代码:

var circle = L.circle([64.837778, -147.716389], 500, {
        color: 'black',
        fillColor: '#000',
        fillOpacity: 0.8
    }).addTo(map);
您应该使用来呈现数据。它用于呈现GeoJSON数据。它有一个pointToLayer函数,您可以使用该函数将点渲染为圆、圆标记或任何您想要的。事实上,传单网站上的“示例”部分有一个您正试图实现的确切示例:

L.geoJson(someGeojsonFeature, {
    pointToLayer: function (feature, latlng) {
        return L.circleMarker(latlng, geojsonMarkerOptions);
    }
}).addTo(map);
您可以使用GeoJSON层渲染单个要素或整个要素集合,请查看网站上的示例:

编辑:根据请求,完整示例如下:

首先从GeoJSON featureCollection开始:

var featureCollection = [{
    "type": "Feature",
    "properties": {},
    "geometry": {
        "type": "Point",
        "coordinates": [-104.99, 39.73]
    }
},{
    "type": "Feature",
    "properties": {},
    "geometry": {
        "type": "Point",
        "coordinates": [-104.96, 39.73]
    }
}];
var geoJsonLayer = L.geoJson(featureCollection, {
    pointToLayer: function (feature, latlng) {
        return L.circleMarker(latlng, {
            radius: 8,
            fillColor: "#ff7800",
            color: "#000",
            weight: 1,
            opacity: 1,
            fillOpacity: 0.8
        });
    }
});
使用featureCollection实例化GeoJSON层:

var featureCollection = [{
    "type": "Feature",
    "properties": {},
    "geometry": {
        "type": "Point",
        "coordinates": [-104.99, 39.73]
    }
},{
    "type": "Feature",
    "properties": {},
    "geometry": {
        "type": "Point",
        "coordinates": [-104.96, 39.73]
    }
}];
var geoJsonLayer = L.geoJson(featureCollection, {
    pointToLayer: function (feature, latlng) {
        return L.circleMarker(latlng, {
            radius: 8,
            fillColor: "#ff7800",
            color: "#000",
            weight: 1,
            opacity: 1,
            fillOpacity: 0.8
        });
    }
});
将图层添加到地图实例:

geoJsonLayer.addTo(map);

plunker上的工作示例:

我尝试过这样做:
var-latlng=L.latlng(ufodata);var geojsonMarkerOptions={radius:8,fillColor:#ff7800,color:#000,weight:1,opacity:1,fillOpacity:0.8};L.geoJson(latlng,{pointToLayer:function(feature,latlng){返回L.circleMarker(latlng,geojsonMarkerOptions);}}).addTo(map)我建议阅读整个GeoJSON示例和参考。创建实例时的第一个参数用于GeoJSON功能或featureCollections,而不是latlng对象。再次感谢你。我已经看过了,但我不完全理解。你能帮我开始吗?这段代码中的数据去哪里了?当你说geojson特性时,你指的是来自数据的特性吗?不用谢我,欢迎你:)如果你发现这是正确的答案,就接受这个答案。这样,寻找类似解决方案的其他用户也可以找到它。见: