Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8053569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:53:29+00:00 2026-06-05T07:53:29+00:00

I would like to give multiple polygons a different pop up window with data

  • 0

I would like to give multiple polygons a different pop up window with data that I get from a database. This script already works for when there is a single polygon in the window.
This is where I take the data from the database:

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
}
?>

These are the functions I use to make Polygons etc. sorry for the dutch comment, but I hope someone can help me out with this

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]);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T07:53:31+00:00Added an answer on June 5, 2026 at 7:53 am

    This is the fix in the onFeatureSelect function:

    var selectedFeature = myLayers.vector.selectedFeatures[0].clone();
                    var identification;
                    var i;
                    var j;
                    for (i = 0; i < tbMap.map.layers.length; i++) {
                        if (tbMap.map.layers[i].CLASS_NAME == "OpenLayers.Layer.Vector") {
                            for (j = 0; j < tbMap.map.layers[i].features.length; j++) {
                                if (selectedFeature.geometry.getBounds().bottom == tbMap.map.layers[i].features[j].geometry.bounds.bottom && selectedFeature.geometry.getBounds().top == tbMap.map.layers[i].features[j].geometry.bounds.top) {
                                    identification = j;
                                } else {
                                }
                            }
                        }
                    }
                    popup = new OpenLayers.Popup.FramedCloud("Pop up",selectedFeature.geometry.getBounds().getCenterLonLat(),null,html[identification],null, true, tbLocations.onPopupClose);
                    selectedFeature.popup = popup;
                    tbMap.map.addPopup(popup);
                } else {
                    var selectedFeature = myLayers.vector.selectedFeatures[0].clone();
                    popup = new OpenLayers.Popup.FramedCloud("Pop up",selectedFeature.geometry.getBounds().getCenterLonLat(),null,html,null, true, tbLocations.onPopupClose);
                    selectedFeature.popup = popup;
                    tbMap.map.addPopup(popup);
                }   
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a script. I would like to give this script a quiet mode
I would like to know how i can include files from multiple locations in
I would like to know how to get the values into this array. Can
I would like to build a reporting tool in an Oracle database that calculates
I would like to give the users of my iphone app the option to
We would like to give our customers access to report bugs and to look
I would like to give points to my users who submit articles based on
I would like to give text shadow for my text using css3. Can anyone
I would like to give the user the ability to insert custom elements in
I am making a Firefox extension and would like to give my users more

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.