我如何才能在 javascript 的函数中从数据库的值中引入列表对象,以便在 map openlayer 中绘制点?

How i can doing for introducing a list objects from database's values in a function of javascript for draw points in map openlayer?

我的问题是,如果这是 javascript 中地图中的不同变量,我可以绘制一个或多个点,但是当我使用 {{mission_template}} 时,它是一个列表来自数据库的对象我不能在这迭代!!...

我在 javascript 中的功能是这样的:

  function AddMakers(){
     for (var i=0; i<50; i++){
        var x={{mission_template.GPSlongitude}};
        var y={{mission_template.GPSlatitude}};
        var iconFeature = new ol.Feature({
        geometry: new ol.geom.Point(ol.proj.transform([x,y], 'EPSG:4326', 'EPSG:3857')),
       name: 'Marker ' + i
        });
        markers[i]= [x,y];
        vectorSource.addFeature(iconFeature);
      }
  }
 .... rest scripts....

并使用 Django 和 Python 进行编程。 我只能在我的模板中对此进行迭代,但不能将该数据用于迭代以在 map 中使用。 我使用:

 {% for mission_template  in mission_template %}
  ...rows and cols for html...
  {{mission_template.GPSlongitude}}
  {{mission_template.GPSlongitude}}
 {%endfor%}

所有信息都在这个变量中。

我想在这个变量 {{mission_template}} 中迭代 javascript 谢谢!!

问候^^

使用模板循环创建 javascript 列表,然后使用 javascript 循环遍历此列表:

var points = [
    {% for mt in mission_template %}
       [{{ mt.GPSlongitude }}, {{ mt.GPSlatitude }}]
       {% if not forloop.last %},{% endif %}
    {% endfor %}
];

for (var i = 0, len = points.length; i < len; i++) {
    var x = points[i][0];
    var y = points[i][1];
    ...
}