Rewrite ooc site using leaflet and bring it under chef control
authorTom Hughes <tom@compton.nu>
Fri, 2 Feb 2018 19:23:53 +0000 (19:23 +0000)
committerTom Hughes <tom@compton.nu>
Fri, 2 Feb 2018 19:23:53 +0000 (19:23 +0000)
cookbooks/dev/files/default/ooc/index.html [new file with mode: 0644]
cookbooks/dev/files/default/ooc/map.css [new file with mode: 0644]
cookbooks/dev/files/default/ooc/map.js [new file with mode: 0644]
cookbooks/dev/files/default/ooc/openlayers/OOC.js [new file with mode: 0644]
cookbooks/dev/files/default/ooc/robots.txt [new file with mode: 0644]
cookbooks/dev/recipes/default.rb
cookbooks/dev/templates/default/apache.ooc.erb [new file with mode: 0644]

diff --git a/cookbooks/dev/files/default/ooc/index.html b/cookbooks/dev/files/default/ooc/index.html
new file mode 100644 (file)
index 0000000..7510906
--- /dev/null
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">
+  <head>
+    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
+    <title>GeoDNS - tile.openstreetmap.org</title>
+    <link rel="stylesheet" href="map.css" type="text/css" media="all" />
+    <link rel="stylesheet" href="https://unpkg.com/leaflet@1.3.0/dist/leaflet.css" integrity="sha512-Rksm5RenBEKSKFjgI3a41vrjkw4EVPlJ3+OiI65vTjIdo9brlAacEuKOiQ5OFh7cOI1bkDwLqdLw3Zg0cRJAAQ==" crossorigin="anonymous" />
+    <script src="https://unpkg.com/leaflet@1.3.0/dist/leaflet.js" integrity="sha512-C7BBF9irt5R7hqbUm2uxtODlUVs+IsNu2UULGuZN7gM+k/mmeG4xvIEac01BtQa4YIkUpp23zZC4wIwuXaPMQA==" crossorigin="anonymous"></script>
+    <script type="text/javascript" src="https://code.jquery.com/jquery-3.1.1.min.js" integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=" crossorigin="anonymous"></script>
+    <script type="text/javascript" src="map.js"></script>
+  </head>
+  <body>
+    <div id="map"></div>
+  </body>
+</html>
diff --git a/cookbooks/dev/files/default/ooc/map.css b/cookbooks/dev/files/default/ooc/map.css
new file mode 100644 (file)
index 0000000..0a22de6
--- /dev/null
@@ -0,0 +1,7 @@
+#map {
+  position: absolute;
+  top: 0px;
+  bottom: 0px;
+  left: 0px;
+  right: 0px;
+}
diff --git a/cookbooks/dev/files/default/ooc/map.js b/cookbooks/dev/files/default/ooc/map.js
new file mode 100644 (file)
index 0000000..4811d2e
--- /dev/null
@@ -0,0 +1,48 @@
+$(document).ready(function () {
+  // Create a map
+  var map = L.map("map").fitBounds([[49.85,-10.5], [58.75, 1.9]]);
+
+  // Create NPE layer
+  var npe = L.tileLayer("https://{s}.ooc.openstreetmap.org/npe/{z}/{x}/{y}.png", {
+    minZoom: 6,
+    maxZoom: 15
+  });
+
+  // Create NPE Scotland layer
+  var npescotland = L.tileLayer("https://{s}.ooc.openstreetmap.org/npescotland/{z}/{x}/{y}.jpg", {
+    minZoom: 6,
+    maxZoom: 15
+  });
+
+  // Create 7th edition layer
+  var os7 = L.tileLayer("https://{s}.ooc.openstreetmap.org/os7/{z}/{x}/{y}.jpg", {
+    minZoom: 3,
+    maxZoom: 14
+  });
+
+  // Create 1st edition layer
+  var os1 = L.tileLayer("https://{s}.ooc.openstreetmap.org/os1/{z}/{x}/{y}.jpg", {
+    minZoom: 6,
+    maxZoom: 17
+  });
+
+  // Add OpenStreetMap layer
+  var osm = L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
+    attribution: "© <a target=\"_parent\" href=\"https://www.openstreetmap.org\">OpenStreetMap</a> and contributors, under an <a target=\"_parent\" href=\"https://www.openstreetmap.org/copyright\">open license</a>",
+    maxZoom: 18
+  });
+
+  // Create a layer switcher
+  var layers = L.control.layers({
+    "OS NPE (Eng/Wales 1945-55) 1:50k": npe,
+    "OS NPE/7th (Scotland) 1:50k": npescotland,
+    "OS 7th Series (1947-60) 1:50k": os7,
+    "OS 1st Edition (1946-60) 1:25k": os1,
+    "OpenStreetMap": osm
+  } , null, {
+    collapsed: false
+  }).addTo(map);
+
+  // Add the NPE layer to the map
+  npe.addTo(map);
+});
diff --git a/cookbooks/dev/files/default/ooc/openlayers/OOC.js b/cookbooks/dev/files/default/ooc/openlayers/OOC.js
new file mode 100644 (file)
index 0000000..e84251e
--- /dev/null
@@ -0,0 +1,145 @@
+/**
+ * Namespace: Util.OOC
+ */
+OpenLayers.Util.OOC = {};
+
+/**
+ * @requires OpenLayers/Layer/XYZ.js
+ *
+ * Class: OpenLayers.Layer.NPE
+ *
+ * Inherits from:
+ *  - <OpenLayers.Layer.XYZ>
+ */
+OpenLayers.Layer.NPE = OpenLayers.Class(OpenLayers.Layer.XYZ, {
+    /**
+     * Constructor: OpenLayers.Layer.NPE
+     *
+     * Parameters:
+     * name - {String}
+     * url - {String}
+     * options - {Object} Hashtable of extra options to tag onto the layer
+     */
+    initialize: function(name, options) {
+        var url = [
+            "http://a.ooc.openstreetmap.org/npe/${z}/${x}/${y}.png",
+            "http://b.ooc.openstreetmap.org/npe/${z}/${x}/${y}.png",
+            "http://c.ooc.openstreetmap.org/npe/${z}/${x}/${y}.png"
+        ];
+        options = OpenLayers.Util.extend({
+            numZoomLevels: 16,
+            transitionEffect: "resize",
+            sphericalMercator: true
+        }, options);
+        var newArguments = [name, url, options];
+        OpenLayers.Layer.XYZ.prototype.initialize.apply(this, newArguments);
+    },
+
+    CLASS_NAME: "OpenLayers.Layer.NPE"
+});
+
+/**
+ * @requires OpenLayers/Layer/XYZ.js
+ *
+ * Class: OpenLayers.Layer.OS7
+ *
+ * Inherits from:
+ *  - <OpenLayers.Layer.XYZ>
+ */
+OpenLayers.Layer.OS7 = OpenLayers.Class(OpenLayers.Layer.XYZ, {
+    /**
+     * Constructor: OpenLayers.Layer.OS7
+     *
+     * Parameters:
+     * name - {String}
+     * url - {String}
+     * options - {Object} Hashtable of extra options to tag onto the layer
+     */
+    initialize: function(name, options) {
+        var url = [
+            "http://a.ooc.openstreetmap.org/os7/${z}/${x}/${y}.jpg",
+            "http://b.ooc.openstreetmap.org/os7/${z}/${x}/${y}.jpg",
+            "http://c.ooc.openstreetmap.org/os7/${z}/${x}/${y}.jpg"
+        ];
+        options = OpenLayers.Util.extend({
+            numZoomLevels: 15,
+            transitionEffect: "resize",
+            sphericalMercator: true
+        }, options);
+        var newArguments = [name, url, options];
+        OpenLayers.Layer.XYZ.prototype.initialize.apply(this, newArguments);
+    },
+
+    CLASS_NAME: "OpenLayers.Layer.OS7"
+});
+
+/**
+ * @requires OpenLayers/Layer/XYZ.js
+ *
+ * Class: OpenLayers.Layer.OS1
+ *
+ * Inherits from:
+ *  - <OpenLayers.Layer.XYZ>
+ */
+OpenLayers.Layer.OS1 = OpenLayers.Class(OpenLayers.Layer.XYZ, {
+    /**
+     * Constructor: OpenLayers.Layer.OS1
+     *
+     * Parameters:
+     * name - {String}
+     * url - {String}
+     * options - {Object} Hashtable of extra options to tag onto the layer
+     */
+    initialize: function(name, options) {
+        var url = [
+            "http://a.ooc.openstreetmap.org/os1/${z}/${x}/${y}.jpg",
+            "http://b.ooc.openstreetmap.org/os1/${z}/${x}/${y}.jpg",
+            "http://c.ooc.openstreetmap.org/os1/${z}/${x}/${y}.jpg"
+        ];
+        options = OpenLayers.Util.extend({
+            numZoomLevels: 18,
+            transitionEffect: "resize",
+            sphericalMercator: true
+        }, options);
+        var newArguments = [name, url, options];
+        OpenLayers.Layer.XYZ.prototype.initialize.apply(this, newArguments);
+    },
+
+    CLASS_NAME: "OpenLayers.Layer.OS1"
+});
+
+/**
+ * @requires OpenLayers/Layer/XYZ.js
+ *
+ * Class: OpenLayers.Layer.NPEScotland
+ *
+ * Inherits from:
+ *  - <OpenLayers.Layer.XYZ>
+ */
+OpenLayers.Layer.NPEScotland = OpenLayers.Class(OpenLayers.Layer.XYZ, {
+    /**
+     * Constructor: OpenLayers.Layer.NPEScotland
+     *
+     * Parameters:
+     * name - {String}
+     * url - {String}
+     * options - {Object} Hashtable of extra options to tag onto the layer
+     */
+    initialize: function(name, options) {
+        var url = [
+            "http://a.ooc.openstreetmap.org/npescotland/${z}/${x}/${y}.jpg",
+            "http://b.ooc.openstreetmap.org/npescotland/${z}/${x}/${y}.jpg",
+            "http://c.ooc.openstreetmap.org/npescotland/${z}/${x}/${y}.jpg"
+        ];
+        options = OpenLayers.Util.extend({
+            numZoomLevels: 16,
+            transitionEffect: "resize",
+            sphericalMercator: true
+        }, options);
+        var newArguments = [name, url, options];
+        OpenLayers.Layer.XYZ.prototype.initialize.apply(this, newArguments);
+    },
+
+    CLASS_NAME: "OpenLayers.Layer.NPEScotland"
+});
+
diff --git a/cookbooks/dev/files/default/ooc/robots.txt b/cookbooks/dev/files/default/ooc/robots.txt
new file mode 100644 (file)
index 0000000..1f53798
--- /dev/null
@@ -0,0 +1,2 @@
+User-agent: *
+Disallow: /
index 4ac5848..d6b27a0 100644 (file)
@@ -301,3 +301,31 @@ if node[:postgresql][:clusters][:"9.5/main"]
     end
   end
 end
     end
   end
 end
+
+directory "/srv/ooc.openstreetmap.org" do
+  owner "root"
+  group "root"
+  mode 0o755
+end
+
+remote_directory "/srv/ooc.openstreetmap.org/html" do
+  source "ooc"
+  owner "root"
+  group "root"
+  mode 0o755
+  files_owner "root"
+  files_group "root"
+  files_mode 0o644
+end
+
+ssl_certificate "ooc.openstreetmap.org" do
+  domains ["ooc.openstreetmap.org",
+           "a.ooc.openstreetmap.org",
+           "b.ooc.openstreetmap.org",
+           "c.ooc.openstreetmap.org"]
+  notifies :reload, "service[apache2]"
+end
+
+apache_site "ooc.openstreetmap.org" do
+  template "apache.ooc.erb"
+end
diff --git a/cookbooks/dev/templates/default/apache.ooc.erb b/cookbooks/dev/templates/default/apache.ooc.erb
new file mode 100644 (file)
index 0000000..6b921e8
--- /dev/null
@@ -0,0 +1,57 @@
+# DO NOT EDIT - This file is being maintained by Chef
+
+<VirtualHost *:443>
+       ServerName ooc.openstreetmap.org
+       ServerAlias a.ooc.openstreetmap.org
+       ServerAlias b.ooc.openstreetmap.org
+       ServerAlias c.ooc.openstreetmap.org
+       ServerAdmin webmaster@openstreetmap.org
+
+       SSLEngine on
+       SSLCertificateFile /etc/ssl/certs/ooc.openstreetmap.org.pem
+       SSLCertificateKeyFile /etc/ssl/private/ooc.openstreetmap.org.key
+
+       CustomLog /var/log/apache2/ooc.openstreetmap.org-access.log combined
+       ErrorLog /var/log/apache2/ooc.openstreetmap.org-error.log
+
+       DocumentRoot /srv/ooc.openstreetmap.org/html
+       Alias /npe/ /home/ooc/npe/
+       Alias /npescotland/ /home/ooc/npescotland/
+       Alias /os7/ /home/ooc/os7/
+       Alias /os1/ /home/ooc/os1/
+</VirtualHost>
+
+<VirtualHost *:80>
+       ServerName ooc.openstreetmap.org
+       ServerAlias a.ooc.openstreetmap.org
+       ServerAlias b.ooc.openstreetmap.org
+       ServerAlias c.ooc.openstreetmap.org
+       ServerAdmin webmaster@openstreetmap.org
+
+       CustomLog /var/log/apache2/ooc.openstreetmap.org-access.log combined
+       ErrorLog /var/log/apache2/ooc.openstreetmap.org-error.log
+
+       RedirectPermanent /.well-known/acme-challenge/ http://acme.openstreetmap.org/.well-known/acme-challenge/
+       RedirectPermanent / https://ooc.openstreetmap.org/
+</VirtualHost>
+
+<VirtualHost *:80>
+       ServerName npe.openstreetmap.org
+       ServerAdmin webmaster@openstreetmap.org
+
+       CustomLog /var/log/apache2/npe.openstreetmap.org-access.log combined
+       ErrorLog /var/log/apache2/npe.openstreetmap.org-error.log
+
+       RewriteEngine on
+       RewriteRule ^/robots.txt$ https://ooc.openstreetmap.org/robots.txt [R=permanent]
+       RewriteRule ^/openlayers/NPE.js$ https://ooc.openstreetmap.org/openlayers/OOC.js [R=permanent]
+       RewriteRule ^/(.*)$ https://ooc.openstreetmap.org/npe/$1 [R=permanent]
+</VirtualHost>
+
+<Directory /srv/ooc.openstreetmap.org/html>
+       Require all granted
+</Directory>
+
+<Directory /home/ooc>
+       Require all granted
+</Directory>