[英]assign data query to each Polygon with bindpopup Leaflet in Codeigniter
i wrote some codes in Codeigniter to assign query result into each polygons with $.getJSON but i found some problems.我在 Codeigniter 中编写了一些代码,用 $.getJSON 将查询结果分配给每个多边形,但我发现了一些问题。 Here is my $.getJSON code
这是我的 $.getJSON 代码
$.getJSON("<?php echo base_url(); ?>Request/showData", function(data) {
var area_data = new Array(3);
var total_data = new Array(3);
for (var i = 0; i < data.length; i++) {
area_data[i] = data[i].Area;
total_data[i] = data[i].total;
}
layer.bindPopup(area_data + ':' + total_data);
})
from this js script, i got this kind of result从这个js脚本,我得到了这种结果
The expected result is each polygon shows its alphabet and value same like the red color.预期的结果是每个多边形都显示其字母和值,就像红色一样。 but right now i have each polygon shows all alphabets and values from query.
但现在我让每个多边形显示查询中的所有字母和值。
model function模型函数
public function map()
{
$query = $this->db->query(
"SELECT Area, sum(Value) as total from ( select Area,Value from try_1 union all select Area,Value from try_2 ) view_vall group by Area"
);
return $query->result_array();
}
controller function控制器功能
public function showData()
{
$aa = $this->model_request->map();
echo json_encode($aa);
}
Thanks in advance提前致谢
turns out that i found the answer..原来我找到了答案..
it needs to add conditional with if after the looping and add variable to put value inside bindpopup.它需要在循环之后添加条件 if 并添加变量以将值放入 bindpopup 中。
$.getJSON("<?php echo base_url(); ?>Request/showData", function(data) {
var area_data = new Array(3);
var total_data = new Array(3);
for (var i = 0; i < data.length; i++) {
area_data[i] = data[i].Area;
total_data[i] = data[i].total;
}
var popup;
if (feature.properties.Area == 'A') {
popup = area_data[0] + ':' + total_data[0];
} else if (feature.properties.Area == 'B') {
popup = area_data[1] + ':' + total_data[1];
} else {
popup = area_data[2] + ':' + total_data[2];
}
layer.bindPopup(popup);
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.