I am new to javascript and I have been attempting to modify the method of generating maps in leaflet using a Polish WKT database. The issue arises when multiple positions are returned, as the onclick function does not work properly. For example, when searching for "Koty 4," which has two villages with parcel number 4. What mistake am I making?
function load(){
map = L.map('mapa').setView([52, 19], 6);
L.tileLayer('https://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: '© <a href="https://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
var wmsLayer = L.tileLayer.wms('https://integracja.gugik.gov.pl/cgi-bin/KrajowaIntegracjaEwidencjiGruntow', {
layers: 'geoportal,dzialki,numery_dzialek,budynki',format: 'image/png', transparent: true,
}).addTo(map);
window.osmMap = map;
}
function addPolygon(points){
var gPoints = new Array();
var _p = points.split(',');
var cX = 0, cY = 0;
var p0 = null;
var gPoints2 = new Array();
var geojson_pgons = Terraformer.WKT.parse(geomWKT);
var xMin = 1000, yMin = 1000, xMax = -1000, yMax = -1000;
for(var i=0;i<_p.length;i++){
var point = _p[i].split(' ');
if(p0==null) p0 = point;
cX += parseFloat(point[0]);
cY += parseFloat(point[1]);
xMin = Math.min(xMin,point[0]);
xMax = Math.max(xMax,point[0]);
yMin = Math.min(yMin,point[1]);
yMax = Math.max(yMax,point[1]);
gPoints.push(new Array(point[1],point[0]));
}
map.eachLayer(function(polygon) {
if( polygon instanceof L.GeoJSON )
map.removeLayer(polygon);
});
var polygon = L.geoJson(geojson_pgons, {}).addTo(window.osmMap);
var bounds = geojson_pgons.bbox();
window.osmMap.fitBounds([ [bounds[1], bounds[0]], [bounds[3], bounds[2]] ]);