[OpenLayers-Users] Displaying Multiple Markers from Database

Burgholzer,Robert rwburgholzer at deq.virginia.gov
Tue Feb 19 13:03:19 EST 2008


You could also create a simple CGI script to produce a text file of markers from your database, which conformed to the markers from text file example.  Below is the code that I use to do this in an example based on markersTextLayer.html (in the OpenLayers examples folder).

 

First I changed the code in the OpenLayers example file "markersTextLayer.html" to load my script file (a PHP file, shown below)

 

Change line in markersTextLayer.html demo 

 

FROM:

var newl = new OpenLayers.Layer.Text( "text", {location: "./textfile.txt"} );

 

TO:

var newl = new OpenLayers.Layer.Text( "text", {location: "http://172.16.210.66/html/wms_maps/text.php"} );

 

CONTENTS of text.php:

<?php

 

$connection = pg_connect("host=localhost port=5432 dbname=wsp user=postgres password=topsecret");

 

$querystring = "  select \"OWNNAME\" as title, \"FACILITY\" as descrip, X(the_geom), Y(the_geom) ";

$querystring .= " from water_use_dd limit 8 ";

 

$res = pg_query  ( $connection, $querystring );

 

print("point" . "\t" . "title" . "\t" . "description" . "\t" . "icon");

while ($thisrec = pg_fetch_array($res)) {

   

   $x = $thisrec['x'];

   $y = $thisrec['y'];

   $title = $thisrec['title'];

   $descrip = $thisrec['descrip'];

   print("$y,$x" . "\t" . "$title" . "\t" . "$descrip" . "\t" . "" . "\n");

}

 

?>

 

Hope this helps,

r.b.

 

Robert W. Burgholzer

Surface Water Modeler

Office of Water Supply and Planning

Virginia Department of Environmental Quality

rwburgholzer at deq.virginia.gov

804-698-4405

Open Source Modeling Tools:

http://sourceforge.net/projects/npsource/

-----Original Message-----
From: users-bounces at openlayers.org [mailto:users-bounces at openlayers.org] On Behalf Of Dipl. Inf. Carsten Eider
Sent: Monday, February 18, 2008 11:58 AM
To: Eric Lemoine
Cc: users at openlayers.org
Subject: Re: [OpenLayers-Users] Displaying Multiple Markers from Database

 

I have solved a similar problem by abusing a GeoRSS-Layer.
A servlet generated the required GeoRSS-Feed, it worked great.
Unfortunatelay some of my feeds contained about 1000 items, where
upto 4 feeds at one time where loaded.

My local system sometimes broke down.

Carsten

Eric Lemoine schrieb: 

On Feb 16, 2008 8:16 AM, schone <prashant.g.raju at gmail.com> <mailto:prashant.g.raju at gmail.com>  wrote:
  

	Hello all,
	 
	New to OpenLayers but I think it is an amazing project!
	 
	So here is my situation...
	 
	I have around 200 long/lat in a database attached with unique locations.
	(MySQL database)
	 
	I would like to display all these markers on the map using OpenLayers but
	I'm finding it hard to display multiple markers.
	 
	Has anyone got any good examples of working with Multiple Markers and MySQL
	or an XML document?
	 
	Thanks for the help!
	 
	Kind Regards
	Prashant
	    

 
Hi Prashant
 
You'd need to have some software on the server side to extract the
data from your database and send it to the client. If I had to do
that, I'd implement a simple web sevice in Python that reads the
lon/lat's from the database and sends a JSON representation of this
data to the client. On the client side, I'd write code that requests
the data through Ajax and uses OpenLayers to create and display a
marker for each lon/lat in the response. This is just off the top of
my head...
 
Cheers,
--
Eric
_______________________________________________
Users mailing list
Users at openlayers.org
http://openlayers.org/mailman/listinfo/users
 
  





-- 
Mit freundlichen Grüßen / Yours faithfully
Carsten Eider
 
Dipl. Inf. (FH)
 
Kompetenzzentrum für Innovative Informationssysteme
 
c/o Fachhochschhule Bingen / University of applied sciences Bingen
 
Berlinstraße 109
55411 Bingen
 
Tel: +49 (0) 6721 / 409-179
Fax: +49 (0) 6721 / 409-158
email: eider at fh-bingen.de
Internet: iis.fh-bingen.de 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20080219/e4b293a7/attachment.html


More information about the Users mailing list