这是使用Flask和OpenLayer3在地图中显示某些功能的代码:
<script type="text/javascript">
var map = new ol.Map({
target: 'map',
layers: [
new ol.layer.Tile({
source: new ol.source.MapQuest({layer: 'sat'})
})
],
view: new ol.View({
center: ol.proj.fromLonLat([-105.269487,40.016026]),
zoom: 10
})
});
var vectorSource = new ol.source.Vector({
//create empty vector
});
{% for row in geodata %}
var iconFeature = new ol.Feature({
geometry: new ol.geom.Point(ol.proj.transform([{{row['lat'],row['lon']}}], 'EPSG:4326', 'EPSG:3857')),
name: {{row['id_tweet']}}
});
vectorSource.addFeature(iconFeature);
{% endfor %}
var iconStyle = new ol.style.Style({
image: new ol.style.Icon(/** @type {olx.style.IconOptions} */ ({
anchor: [0.5, 46],
anchorXUnits: 'fraction',
anchorYUnits: 'pixels',
opacity: 0.75,
src: 'http://openlayers.org/en/v3.9.0/examples/data/icon.png'
}))
});
var vectorLayer = new ol.layer.Vector({
source: vectorSource,
style: iconStyle
});
map.addLayer(vectorLayer)
这是python代码:
@app.route('/map', methods=['GET', 'POST'])
def display_geodata():
f_obj = open(PROJECT_ROOT+'/data.csv', "rt")
return render_template('map.html', geodata = read_data_from_csv(f_obj))
def read_data_from_csv(file):
return csv.DictReader(file)
为什么 for 块没有显示任何内容? 在调试时, geodata 我可以看到它不是空的,并且包含data.csv文件的所有数据! 哪里错了?
答案 0 :(得分:0)
我不知道如何找到错误,作为临时解决方案,我使用DictReader构建元组列表,现在可以正常工作