我想为多个多边形提供一个不同的弹出窗口,其中包含从数据库中获取的数据。当窗口中有单个多边形时,此脚本已经有效。这是我从数据库中获取数据的地方:
var length = <?php echo count($locations); ?>;
<?php
//Tel het aantal plaatsen in de array en zet deze via json in een javascript array
for ($i=0; $i < count($locations); $i++) {
?>
var counter = parseInt(<?php echo $i; ?>);
title[counter] = <?php print json_encode($locations[$i]['Location']['title']); ?>;
location_id[counter] = <?php print json_encode($locations[$i]['Location']['id']); ?>;
address[counter] = <?php print json_encode($locations[$i]['Location']['address']); ?>;
city[counter] = <?php print json_encode($locations[$i]['Location']['city']); ?>;
coordinates[counter] = <?php print json_encode($polygon[$i]); ?>;
<?php
}
?>
这些是我用来制作多边形等的功能。对荷兰语的评论感到抱歉,但我希望有人能帮我解决这个问题
onFeatureSelect: function(feature) {
if (title != null) {
if (html.length > 1) {
selectedFeature = feature;
popup = new OpenLayers.Popup.FramedCloud("Pop up",feature.geometry.getBounds().getCenterLonLat(),null,html[i],null, true, myLocations.onPopupClose);
feature.popup = popup;
map.addPopup(popup);
} else {
selectedFeature = feature;
popup = new OpenLayers.Popup.FramedCloud("Pop up",feature.geometry.getBounds().getCenterLonLat(),null,html,null, true, myLocations.onPopupClose);
feature.popup = popup;
map.addPopup(popup);
}
}
}
/**
* Bouw de HTML string op voor de pop up window
**/
buildHTML: function(element) {
html = '<table>' +
'<tr>' +
'<td>Locatie:</td>' +
'<td>'+title+'</td>'+
'<td rowspan="3" style="padding-left: 10px;">' +
'<a href="/locations/edit/'+location_id+'" title="Bewerken" ><div class="icon edit"></div></a><br/>' +
'<a href="/locations/view/'+location_id+'" title="Details" ><div class="icon view"></div></a>' +
'</td>' +
'</tr><tr>'+
'<td>Adres:</td>'+
'<td>'+address+'</td>' +
'</tr><tr>'+
'<td>Plaats:</td>'+
'<td>'+city+'</td>'+
'</tr>'+
'</table>';
},
/**
* Gooi de HTML strings in een array als het er meer zijn
**/
buildMultipleHTML: function(element) {
html = new Array();
for(i=0;i < title.length; i++) {
html[i] = '<table>' +
'<tr>' +
'<td>Locatie:</td>' +
'<td>'+title[i]+'</td>'+
'<td rowspan="3" style="padding-left: 10px;">' +
'<a href="/locations/edit/'+location_id[i]+'" title="Bewerken" ><div class="icon edit"></div></a><br/>' +
'<a href="/locations/view/'+location_id[i]+'" title="Details" ><div class="icon view"></div></a>' +
'</td>' +
'</tr><tr>'+
'<td>Adres:</td>'+
'<td>'+address[i]+'</td>' +
'</tr><tr>'+
'<td>Plaats:</td>'+
'<td>'+city[i]+'</td>'+
'</tr>'+
'</table>';
}
}
/**
* Meerdere polygonen tekenen
**/
drawMultiplePolygons: function(coordinates) {
//Array site_points leegmaken
site_points = new Array();
for (j=0; j < coordinates.length; j++) {
site_points[j] = new Array();
for (i=0; i < coordinates[j][0].length; i++) {
//Maak de punten aan met de OpenLayers, Geometry functie
point = new OpenLayers.Geometry.Point(coordinates[j][1][i], coordinates[j][0][i]);
//Zet de punten om in de projectie van openstreetmaps
point.transform(
new OpenLayers.Projection("EPSG:4326"),
new OpenLayers.Projection("EPSG:900913")
);
//Zet de punten in een array
site_points[j].push(point);
}
//Lineaire ring aanmaken met de OpenLayers functie
linear_ring = new OpenLayers.Geometry.LinearRing(site_points[j]);
//Polygoon aanmaken
polygonFeature = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Polygon([linear_ring]), null);
//Polygoonvector maken
myLayers.vector.addFeatures([polygonFeature]);
}
}