Harry Wood


OpenLayers Database Text

This map has a 'text' layer pointed at 'db2text.php', a script which queries the database example.db and generates text in the format OpenLayers can use to display lots of markers (see the generated text)

In this case OpenLayers makes a single request, and db2text.php simply fetches every point from the database, which takes a little while at the server-side. The amount of data returned can also overload your browser a bit. These difficulties are takled with the BBOX strategy example.
x
 
<head>
  <title>OpenLayers Database Text Example</title>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/openlayers/2.11/lib/OpenLayers.js"></script>           
  
  <style>
#mapdiv {
   width:400px;
   height:400px;
   float:left;
}
  </style>
</head>
  
<body>
  <div id="mapdiv"></div>
  <script>
    map = new OpenLayers.Map("mapdiv");
    map.addLayer(new OpenLayers.Layer.OSM());
       
    var points = new OpenLayers.Layer.Text( "My Points",
                    { location: "./db2text.php",
                      projection: map.displayProjection
                    });
    map.addLayer(points);
    
    //Set start centrepoint and zoom
    var lonLat = new OpenLayers.LonLat( -0.1196, 51.5033 )
          .transform(
            new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984
            map.getProjectionObject() // to Spherical Mercator Projection
          );
    var zoom=15;
    map.setCenter (lonLat, zoom);  
  </script>
  
</body>
</html>
    

view directly