0
我需要製作包含一些多邊形的地圖小冊子,並且我想根據來自MYSQL的數據爲我的poygons着色。但是,當我嘗試此代碼時,我的多邊形不顯示。 這是我對我的map.php代碼:將數據從mysql加載到小冊子
<?php
include 'koneksi.php';
$sql="select sum(skor_bobot) as hasilnya from penilaian where bulan=1 and id_kelurahan=1";
$data=mysql_query($sql);
$js='';
while ($row=mysql_fetch_array($data)) {
$js .='L.geoJson(states, {
style: function(feature) {
if ((feature.properties.party=='.'Republican'.')&&('.$row['hasilnya'].'=='.'10'.')) {
return {color: "#ffff89"};
} else {
return {color: "#ff0000"};
};
}
}).addTo(mymap);';
}
echo $js; ?>
以下是我的map.php我GeoJSON的代碼:
var states = [{
"type": "Feature",
"properties": {"party": "Republican"},
"geometry": {
"type": "Polygon",
"coordinates": [[
[-104.05, 48.99],
[-97.22, 48.98],
[-96.58, 45.94],
[-104.03, 45.94],
[-104.05, 48.99]
]]
}
}, {
"type": "Feature",
"properties": {"party": "Democrat"},
"geometry": {
"type": "Polygon",
"coordinates": [[
[-109.05, 41.00],
[-102.06, 40.99],
[-102.03, 36.99],
[-109.04, 36.99],
[-109.05, 41.00]
]]
}
}];
你有看過瀏覽器控制檯的錯誤日誌嗎? –
我會改變我的策略,並將事情的服務器端分開處理到前端。 PHP通過AJAX調用請求您的數據庫並返回geojson。這樣你可以分別調試你的數據庫,你的geojson和你的js代碼。 – datafunk
@NafianWildana瀏覽器控制檯表示「Uncaught ReferenceError:Republican is not defined」。但是當我使用如果沒有數據庫,我的多邊形顯示。 –