while ($row = pg_fetch_array($result))
{
echo '<div id="' . $row['nom'] . '" class="col-sm-10"><li class="Liste">' . $row['nom'] . '</li>
<div class="checkbox chk">
<label><input type="checkbox" name="id" id="DisplayCheckbox" value="' . $row['nom'] . '"></label>
</div>';
$variable=$row2['nom'];
if($result)
{
$query2 = "SELECT st_asgeojson(st_transform(geom,4326)) from domaine where nom='$variable'";
$result2 = pg_query($query2);
while ($row2 = pg_fetch_array($result2))
{
echo '<li class="Liste" name="id" style="display:none;">' . $row2[0]. '</li></div><br/>';
}
}
}
echo '</ul>'
}
?>
<script type="text/javascript">
$(document).ready(function(){
$('input[id^="DisplayCheckbox"]').on('click',function()
{
parent = $(this).val();
Item = $(this).parents('#' + parent).find("li.Liste").text();
if($(this).is(":checked"))
$.drawCategory(geoItem);
else
$.removeItem(CategoryItem);
});
});
</script>
External jquery file:
$.drawCategory = function(data)
{
dataCategory = $.parseJSON(data);
var geojsonFeature =
{
"type": "FeatureCollection",
"features": [{
"type": "Feature",
},
"geometry": {
"type": dataCategory.type,
"coordinates": dataCategory.coordinates
}
}]
};
Item=L.geoJson(geojsonFeature).addTo(map);
map.fitBounds(Item.getBounds());
};
$.removeItem = function()
{
map.removeLayer(Item);