commit 5c5b75049200d1e4d97408381f1c5fd4f713ee39
Author: Jocelyn Delande <jocelyn at delalande dot fr>
Date:   Sun Dec 1 01:31:50 2013 +0100

    Added a display of all the ref_points on the map.

diff --git a/ajax/ref_points.php b/ajax/ref_points.php
new file mode 100644
index 0000000..2e0fd6b
--- /dev/null
+++ b/ajax/ref_points.php
@@ -0,0 +1,69 @@
+<?php
+
+
+/**
+ *  An example CORS-compliant method.  It will allow any GET, POST, or OPTIONS requests from any
+ *  origin.
+ *
+ *  In a production environment, you probably want to be more restrictive, but this gives you
+ *  the general idea of what is involved.  For the nitty-gritty low-down, read:
+ *
+ *  - https://developer.mozilla.org/en/HTTP_access_control
+ *  - http://www.w3.org/TR/cors/
+ *
+ */
+function cors() {
+    // Allow from any origin
+    if (isset($_SERVER['HTTP_ORIGIN'])) {
+        header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
+        header('Access-Control-Allow-Credentials: true');
+        header('Access-Control-Max-Age: 86400');    // cache for 1 day
+    }
+
+    // Access-Control headers are received during OPTIONS requests
+    if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
+
+        if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
+            header("Access-Control-Allow-Methods: GET, POST, OPTIONS");
+
+        if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
+            header("Access-Control-Allow-Headers: {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");
+
+        exit(0);
+    }
+}
+
+cors();
+
+function ref_point_to_geoJSONFeature($name, $values) {
+	return array("type" => "Feature",
+	             "geometry" => array(
+	                                 "type" => "Point",
+	                                 "coordinates" => [$values[1],$values[0]]
+	                                 ),
+	             "properties" => array("name" => $name)
+	             );
+}
+
+function get_ref_points() {
+	$ref_points_filename = '../ref_points.local.php';
+	if (file_exists($ref_points_filename)) {
+		include $ref_points_filename;
+		return $ref_points;
+	} else {
+		return array();
+	}
+}
+
+$json = array(
+              "type" => "FeatureCollection",
+              "features"=> array()
+              );
+
+foreach (get_ref_points() as $name => $vals) {
+	$json['features'][] = ref_point_to_geoJSONFeature($name, $vals);
+}
+
+echo json_encode($json);
+
+?>
diff --git a/js/utils_osm.js b/js/utils_osm.js
index d1aee2b..6fe0db2 100644
--- a/js/utils_osm.js
+++ b/js/utils_osm.js
@@ -225,4 +225,45 @@ function draw_cap_map() {
 	    alert(position.lat.toFixed(5) + ', ' + position.lon.toFixed(5));
 	});
     }
+
+	return map;
+}
+
+function mk_all_refpoints_layer() {
+	var layer = new OpenLayers.Layer.Vector(
+		"Reference points",{
+			projection: new OpenLayers.Projection("EPSG:4326"),
+			strategies: [new OpenLayers.Strategy.Fixed()],
+			protocol: new OpenLayers.Protocol.HTTP({
+				url: 'ajax/ref_points.php',
+				format: new OpenLayers.Format.GeoJSON(),
+			})
+		});
+	return layer;
 }
+
+
+function add_refpoint_control(layer, map) {
+	var selectControl ;
+	selectControl = new OpenLayers.Control.SelectFeature(
+		layer,{
+			onSelect:function(feature) {
+				var popup = new OpenLayers.Popup.FramedCloud(
+					feature.attributes.name,
+					feature.geometry.getBounds().getCenterLonLat(),
+					null,
+					"<div>" + feature.attributes.name+"</div>",
+					null, true, function() {selectControl.unselect(feature);});
+				feature.popup = popup;
+				map.addPopup(popup);},
+
+			onUnselect:function(feature) {
+				map.removePopup(feature.popup);
+				feature.popup.destroy();
+				feature.popup = null;
+			}});
+
+	map.addControl(selectControl);
+	selectControl.activate();
+}
+
diff --git a/show_capline.php b/show_capline.php
index ab971cd..cecb980 100644
--- a/show_capline.php
+++ b/show_capline.php
@@ -86,7 +86,12 @@ EOS;
 }
 ?>
 <script>
-window.onload = draw_cap_map;
+window.onload = function() {
+  var map = draw_cap_map();
+  all_refpoints = mk_all_refpoints_layer()
+  map.addLayer(all_refpoints);
+  add_refpoint_control(all_refpoints, map);
+}
 </script>
 </head>
 <body>
