Browse Source

Locator (web)

netico 2 years ago
parent
commit
cc799fe4fa

+ 3 - 1
.gitignore

@@ -1 +1,3 @@
-OSM/OpenLayers/node_modules/
+OSM/OpenLayers/node_modules/
+OSM/Locator/web/vendor
+OSM/Locator/web/smarty/compile

+ 20 - 0
OSM/Locator/web/composer.json

@@ -0,0 +1,20 @@
+{
+    "name": "netico/locator",
+    "description": "Retrieve latitude and longitude of an address, via OSM",
+    "type": "project",
+    "license": "GPLv3",
+    "authors": [
+        {
+            "name": "netico",
+            "email": "netico@riseup.net"
+        }
+    ],
+    "minimum-stability": "stable",
+    "require": {
+        "smarty/smarty": "^4.0",
+        "twitter/bootstrap": "^5.1"
+    },
+    "require-dev": {
+        "squizlabs/php_codesniffer": "^3.5"
+    }
+}

+ 192 - 0
OSM/Locator/web/composer.lock

@@ -0,0 +1,192 @@
+{
+    "_readme": [
+        "This file locks the dependencies of your project to a known state",
+        "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
+        "This file is @generated automatically"
+    ],
+    "content-hash": "67b9c6393bde9f3bc008c3eb1a417387",
+    "packages": [
+        {
+            "name": "smarty/smarty",
+            "version": "v4.0.3",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/smarty-php/smarty.git",
+                "reference": "f707dadecbc145bac40f77f47595f32ec18eed01"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/smarty-php/smarty/zipball/f707dadecbc145bac40f77f47595f32ec18eed01",
+                "reference": "f707dadecbc145bac40f77f47595f32ec18eed01",
+                "shasum": ""
+            },
+            "require": {
+                "php": "^7.1 || ^8.0"
+            },
+            "require-dev": {
+                "phpunit/phpunit": "^8.5 || ^7.5",
+                "smarty/smarty-lexer": "^3.1"
+            },
+            "type": "library",
+            "extra": {
+                "branch-alias": {
+                    "dev-master": "4.0.x-dev"
+                }
+            },
+            "autoload": {
+                "classmap": [
+                    "libs/"
+                ]
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "LGPL-3.0"
+            ],
+            "authors": [
+                {
+                    "name": "Monte Ohrt",
+                    "email": "monte@ohrt.com"
+                },
+                {
+                    "name": "Uwe Tews",
+                    "email": "uwe.tews@googlemail.com"
+                },
+                {
+                    "name": "Rodney Rehm",
+                    "email": "rodney.rehm@medialize.de"
+                },
+                {
+                    "name": "Simon Wisselink",
+                    "homepage": "https://www.iwink.nl/"
+                }
+            ],
+            "description": "Smarty - the compiling PHP template engine",
+            "homepage": "https://smarty-php.github.io/smarty/",
+            "keywords": [
+                "templating"
+            ],
+            "support": {
+                "forum": "https://github.com/smarty-php/smarty/discussions",
+                "issues": "https://github.com/smarty-php/smarty/issues",
+                "source": "https://github.com/smarty-php/smarty/tree/v4.0.3"
+            },
+            "time": "2022-01-10T09:52:14+00:00"
+        },
+        {
+            "name": "twitter/bootstrap",
+            "version": "v5.1.3",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/twbs/bootstrap.git",
+                "reference": "1a6fdfae6be09b09eaced8f0e442ca6f7680a61e"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/twbs/bootstrap/zipball/1a6fdfae6be09b09eaced8f0e442ca6f7680a61e",
+                "reference": "1a6fdfae6be09b09eaced8f0e442ca6f7680a61e",
+                "shasum": ""
+            },
+            "replace": {
+                "twitter/bootstrap": "self.version"
+            },
+            "type": "library",
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Mark Otto",
+                    "email": "markdotto@gmail.com"
+                },
+                {
+                    "name": "Jacob Thornton",
+                    "email": "jacobthornton@gmail.com"
+                }
+            ],
+            "description": "The most popular front-end framework for developing responsive, mobile first projects on the web.",
+            "homepage": "https://getbootstrap.com/",
+            "keywords": [
+                "JS",
+                "css",
+                "framework",
+                "front-end",
+                "mobile-first",
+                "responsive",
+                "sass",
+                "web"
+            ],
+            "support": {
+                "issues": "https://github.com/twbs/bootstrap/issues",
+                "source": "https://github.com/twbs/bootstrap/tree/v5.1.3"
+            },
+            "time": "2021-10-09T06:43:19+00:00"
+        }
+    ],
+    "packages-dev": [
+        {
+            "name": "squizlabs/php_codesniffer",
+            "version": "3.6.2",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/squizlabs/PHP_CodeSniffer.git",
+                "reference": "5e4e71592f69da17871dba6e80dd51bce74a351a"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/5e4e71592f69da17871dba6e80dd51bce74a351a",
+                "reference": "5e4e71592f69da17871dba6e80dd51bce74a351a",
+                "shasum": ""
+            },
+            "require": {
+                "ext-simplexml": "*",
+                "ext-tokenizer": "*",
+                "ext-xmlwriter": "*",
+                "php": ">=5.4.0"
+            },
+            "require-dev": {
+                "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0"
+            },
+            "bin": [
+                "bin/phpcs",
+                "bin/phpcbf"
+            ],
+            "type": "library",
+            "extra": {
+                "branch-alias": {
+                    "dev-master": "3.x-dev"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "BSD-3-Clause"
+            ],
+            "authors": [
+                {
+                    "name": "Greg Sherwood",
+                    "role": "lead"
+                }
+            ],
+            "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.",
+            "homepage": "https://github.com/squizlabs/PHP_CodeSniffer",
+            "keywords": [
+                "phpcs",
+                "standards"
+            ],
+            "support": {
+                "issues": "https://github.com/squizlabs/PHP_CodeSniffer/issues",
+                "source": "https://github.com/squizlabs/PHP_CodeSniffer",
+                "wiki": "https://github.com/squizlabs/PHP_CodeSniffer/wiki"
+            },
+            "time": "2021-12-12T21:44:58+00:00"
+        }
+    ],
+    "aliases": [],
+    "minimum-stability": "stable",
+    "stability-flags": [],
+    "prefer-stable": false,
+    "prefer-lowest": false,
+    "platform": [],
+    "platform-dev": [],
+    "plugin-api-version": "2.1.0"
+}

+ 105 - 0
OSM/Locator/web/locator.php

@@ -0,0 +1,105 @@
+<?php
+# Debug
+ini_set('display_errors', 1);
+ini_set('display_startup_errors', 1);
+error_reporting(E_ALL);
+
+require "vendor/autoload.php";
+
+if (isset($_GET["address"])) {
+    $address = filter_var($_GET["address"], FILTER_SANITIZE_STRING);
+    $address = base64_decode($address);
+    $address = ucwords(trim($address));
+
+    # Nominatim Usage Policy
+    # https://operations.osmfoundation.org/policies/nominatim/
+    # sleep(1);
+
+    # OpenStreetMap Nominatim API
+    $url = 'https://nominatim.openstreetmap.org/search?q=' . urlencode($address) . '&limit=1&format=json';
+    $ch = curl_init();
+    # Set cURL User Agent
+    curl_setopt($ch, CURLOPT_USERAGENT, "PostmanRuntime/7.28.4");
+    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+    curl_setopt($ch, CURLOPT_URL, $url);
+    $response = curl_exec($ch);
+    curl_close($ch);
+
+    # Response
+    $a = json_decode($response, true);
+    $valid = false;
+    foreach ($a as $array) {
+        foreach ($array as $k => $v) {
+            switch ("$k") {
+                case "lat":
+                    echo "<div class='alert alert-primary' role='alert'>";
+                    echo "<b>Latitude</b>: " . round($v, 8) . "<br>";
+                    $valid = true;
+                    break;
+                case "lon":
+                    echo "<b>Longitude</b>: " . round($v, 8);
+                    echo "</div>";
+                    $valid = true;
+                    break;
+            }
+        }
+    }
+    if ($valid === false) {
+        echo "<div class='alert alert-danger' role='alert'>";
+        echo "Something goes wrong!";
+        echo "</div>";
+    }
+} else {
+    $favicon = <<<EOL
+data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAPAAAADwCAYAAAA+VemSAAAABmJLR0QA/wD/AP+gvaeTAAANhUlEQVR4nO3dW6xeRRnG8f+mF
+FosIgZoKRQJBloLCJWgEDmUkEYIAkYFFCJGIRATD/FCxXjDJYYLI3hDQI2iQCLxhFEixoYKiNBiRBNoEYGUFlrUFii0lNbtxXwbetjHb6/5nnlnnl/yJlyU
+zMxa8+5v1rvWmjWERbQ/cBywsBeLgXnAwb04aIz/b3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sCrjJXR9xrvG9fVvZZzA9XEC
+N8QJXB8nsFlg4xWyXMAyC2C0QpYLWBXyErpOoy2VvXyukBO4Tk7gRjiB6+QENgtstEKWC1hmgexayHIBq1JeQtdr1Rj/bRVxAtfLCdwAJ3C9nMBmgc3n7Wv
+geeK+mFkf1uMCVtX2VXfAslpF+gW2SjmB6+YErpwTuG5O4MrNUHfAstpCug7eou6I5fF/vHbSxLeHmIAAAAAASUVORK5CYII=
+EOL;
+
+    // Smarty
+    $smarty = new Smarty();
+    $smarty->setTemplateDir("./smarty/template");
+    $smarty->setCompileDir("./smarty/compile");
+
+    $smarty->assign("title", "OSM Locator");
+    $smarty->assign("favicon", $favicon);
+
+    $smarty->display("locator.tpl");
+}

+ 58 - 0
OSM/Locator/web/smarty/template/locator.tpl

@@ -0,0 +1,58 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+
+	<meta charset="utf-8">
+	<meta name="viewport" content="width=device-width, initial-scale=1">
+	<title>{$title}</title>
+	<link rel="shortcut icon" href="{$favicon}">
+	<link href="vendor/twitter/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
+
+	<script>
+		function nominatim(str) {
+			if (str.length == 0) { 
+				document.getElementById("coordinates").innerHTML = "";
+				return;
+			} else {
+				var xmlhttp = new XMLHttpRequest();
+				xmlhttp.onreadystatechange = function() {
+					if (this.readyState == 4 && this.status == 200) {
+						document.getElementById("coordinates").innerHTML = this.responseText;
+					}
+				};
+				xmlhttp.open("GET", "?address=" + btoa(str), true);
+				xmlhttp.send();
+			}
+		}
+		
+		function blank() {
+			document.getElementById("address").value = "Craven Road 7, London";
+			document.getElementById("coordinates").innerHTML = "";
+		}
+	</script>
+
+</head>
+<body class="text-center">
+	<main style="max-width: 350pt; margin: auto;">
+		<form onsubmit="return false" class="m-5">
+			<h1 class="h1">{$title}</h1>
+			<span>Powered by <a href="https://www.openstreetmaps.org">OpenStreetMaps</a>.</span>
+			<div class="form-floating mt-4">
+				<input class="form-control" id="address" name="address" type="text" placeholder="Craven Road 7, London" required autofocus>
+				<label for="address">Address</label>
+			</div>
+			<div class="form-floating mt-2">
+				<div id="coordinates" type="text" ></div>
+			</div>
+			<div class="form-floating mt-2">
+				<button class="btn btn-lg btn-primary m-2" onclick="nominatim(document.getElementById('address').value)" type="submit">
+					Get coordinates
+				</button>
+				<button class="btn btn-lg btn-secondary m-2" onclick="blank()" type="submit">
+					Clear
+				</button>				
+			</div>
+		</form>
+	</main>
+</body>
+</html>

BIN
OSM/locator.png