Z25965

{
    "Z1K1": "Z2",
    "Z2K1": {
        "Z1K1": "Z6",
        "Z6K1": "Z25965"
    },
    "Z2K2": {
        "Z1K1": "Z14",
        "Z14K1": "Z25963",
        "Z14K3": {
            "Z1K1": "Z16",
            "Z16K1": "Z600",
            "Z16K2": "// Copyright 2014 Google Inc. All rights reserved.\n//\n// Licensed under the Apache License, Version 2.0 (the 'License');\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an 'AS IS' BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n/**\n * Provides a normal precision code, approximately 14x14 meters.\n * @const {number}\n */\nconst CODE_PRECISION_NORMAL = 10;\n\n/**\n * Provides an extra precision code, approximately 2x3 meters.\n * @const {number}\n */\nconst CODE_PRECISION_EXTRA = 11;\n\n// A separator used to break the code into two parts to aid memorability.\nvar SEPARATOR_ = '+';\n\n// The number of characters to place before the separator.\nvar SEPARATOR_POSITION_ = 8;\n\n// The character used to pad codes.\nvar PADDING_CHARACTER_ = '0';\n\n// The character set used to encode the values.\nvar CODE_ALPHABET_ = '23456789CFGHJMPQRVWX';\n\n// The base to use to convert numbers to/from.\nvar ENCODING_BASE_ = CODE_ALPHABET_.length;\n\n// The maximum value for latitude in degrees.\nvar LATITUDE_MAX_ = 90;\n\n// The maximum value for longitude in degrees.\nvar LONGITUDE_MAX_ = 180;\n\n// The min number of digits in a Plus Code.\nvar MIN_DIGIT_COUNT_ = 2;\n\n// The max number of digits to process in a Plus Code.\nvar MAX_DIGIT_COUNT_ = 15;\n\n// Maximum code length using lat/lng pair encoding. The area of such a\n// code is approximately 13x13 meters (at the equator), and should be suitable\n// for identifying buildings. This excludes prefix and separator characters.\nvar PAIR_CODE_LENGTH_ = 10;\n\n// First place value of the pairs (if the last pair value is 1).\nvar PAIR_FIRST_PLACE_VALUE_ = Math.pow(\n\tENCODING_BASE_, (PAIR_CODE_LENGTH_ / 2 - 1));\n\n// Inverse of the precision of the pair section of the code.\nvar PAIR_PRECISION_ = Math.pow(ENCODING_BASE_, 3);\n\n// The resolution values in degrees for each position in the lat/lng pair\n// encoding. These give the place value of each position, and therefore the\n// dimensions of the resulting area.\nvar PAIR_RESOLUTIONS_ = [20.0, 1.0, .05, .0025, .000125];\n\n// Number of digits in the grid precision part of the code.\nvar GRID_CODE_LENGTH_ = MAX_DIGIT_COUNT_ - PAIR_CODE_LENGTH_;\n\n// Number of columns in the grid refinement method.\nvar GRID_COLUMNS_ = 4;\n\n// Number of rows in the grid refinement method.\nvar GRID_ROWS_ = 5;\n\n// First place value of the latitude grid (if the last place is 1).\nvar GRID_LAT_FIRST_PLACE_VALUE_ = Math.pow(\n\tGRID_ROWS_, (GRID_CODE_LENGTH_ - 1));\n\n// First place value of the longitude grid (if the last place is 1).\nvar GRID_LNG_FIRST_PLACE_VALUE_ = Math.pow(\n\tGRID_COLUMNS_, (GRID_CODE_LENGTH_ - 1));\n\n// Multiply latitude by this much to make it a multiple of the finest\n// precision.\nvar FINAL_LAT_PRECISION_ = PAIR_PRECISION_ *\n\tMath.pow(GRID_ROWS_, (MAX_DIGIT_COUNT_ - PAIR_CODE_LENGTH_));\n\n// Multiply longitude by this much to make it a multiple of the finest\n// precision.\nvar FINAL_LNG_PRECISION_ = PAIR_PRECISION_ *\n\tMath.pow(GRID_COLUMNS_, (MAX_DIGIT_COUNT_ - PAIR_CODE_LENGTH_));\n\n/**\n * Encode a location into an Open Location Code.\n *\n * @param {number} latitude The latitude in signed decimal degrees. It will\n *     be clipped to the range -90 to 90.\n * @param {number} longitude The longitude in signed decimal degrees. Will be\n *     normalised to the range -180 to 180.\n * @param {?number} codeLength The length of the code to generate. If\n *     omitted, the value CODE_PRECISION_NORMAL will be used.\n *     For a more precise result, CODE_PRECISION_EXTRA is\n *     recommended.\n * @return {string} The code.\n * @throws {Exception} if any of the input values are not numbers.\n */\nvar encode = function(latitude, longitude, codeLength) {\n\tlatitude = Number(latitude);\n\tlongitude = Number(longitude);\n\n\tconst locationIntegers = locationToIntegers(latitude, longitude);\n\n\treturn encodeIntegers(locationIntegers[0], locationIntegers[1], codeLength);\n};\n\n/**\n * Convert a latitude, longitude location into integer values.\n *\n * This function is only exposed for testing.\n *\n * Latitude is converted into a positive integer clipped into the range\n * 0 \u003C= X \u003C 180*2.5e7. (Latitude 90 needs to be adjusted to be slightly lower,\n * so that the returned code can also be decoded.\n * Longitude is converted into a positive integer and normalised into the range\n * 0 \u003C= X \u003C 360*8.192e6.\n\n * @param {number} latitude\n * @param {number} longitude\n * @return {Array\u003Cnumber\u003E} A tuple of the latitude integer and longitude integer.\n */\nvar locationToIntegers = function(latitude, longitude) {\n\tvar latVal = Math.floor(latitude * FINAL_LAT_PRECISION_);\n\tlatVal += LATITUDE_MAX_ * FINAL_LAT_PRECISION_;\n\tif (latVal \u003C 0) {\n\t\tlatVal = 0;\n\t} else if (latVal \u003E= 2 * LATITUDE_MAX_ * FINAL_LAT_PRECISION_) {\n\t\tlatVal = 2 * LATITUDE_MAX_ * FINAL_LAT_PRECISION_ - 1;\n\t}\n\tvar lngVal = Math.floor(longitude * FINAL_LNG_PRECISION_);\n\tlngVal += LONGITUDE_MAX_ * FINAL_LNG_PRECISION_;\n\tif (lngVal \u003C 0) {\n\t\tlngVal =\n\t\t\t(lngVal % (2 * LONGITUDE_MAX_ * FINAL_LNG_PRECISION_)) +\n\t\t\t2 * LONGITUDE_MAX_ * FINAL_LNG_PRECISION_;\n\t} else if (lngVal \u003E= 2 * LONGITUDE_MAX_ * FINAL_LNG_PRECISION_) {\n\t\tlngVal = lngVal % (2 * LONGITUDE_MAX_ * FINAL_LNG_PRECISION_);\n\t}\n\treturn [latVal, lngVal];\n};\n\n/**\n * Encode a location that uses integer values into an Open Location Code.\n *\n * This is a testing function, and should not be called directly.\n *\n * @param {number} latInt An integer latitude.\n * @param {number} lngInt An integer longitude.\n * @param {number=} codeLength The number of significant digits in the output\n *     code, not including any separator characters.\n * @return {string} A code of the specified length or the default length if not\n *     specified.\n * @throws {Exception} if any of the input values are not numbers.\n */\nvar encodeIntegers = function(latInt, lngInt, codeLength) {\n\tif (typeof codeLength == 'undefined') {\n\t\tcodeLength = CODE_PRECISION_NORMAL;\n\t} else {\n\t\tcodeLength = Math.min(MAX_DIGIT_COUNT_, Number(codeLength));\n\t}\n\tif (isNaN(latInt) || isNaN(lngInt) || isNaN(codeLength)) {\n\t\tthrow new Error('ValueError: Parameters are not numbers');\n\t}\n\tif (codeLength \u003C MIN_DIGIT_COUNT_ ||\n\t\t\t(codeLength \u003C PAIR_CODE_LENGTH_ \u0026\u0026 codeLength % 2 == 1)) {\n\t\tthrow new Error('IllegalArgumentException: Invalid Open Location Code length');\n\t}\n\t// Javascript strings are immutable and it doesn't have a native\n\t// StringBuilder, so we'll use an array.\n\tconst code = new Array(MAX_DIGIT_COUNT_ + 1);\n\tcode[SEPARATOR_POSITION_] = SEPARATOR_;\n\n\t// Compute the grid part of the code if necessary.\n\tif (codeLength \u003E PAIR_CODE_LENGTH_) {\n\t\tfor (var i = MAX_DIGIT_COUNT_ - PAIR_CODE_LENGTH_; i \u003E= 1; i--) {\n\t\t\tvar latDigit = latInt % GRID_ROWS_;\n\t\t\tvar lngDigit = lngInt % GRID_COLUMNS_;\n\t\t\tvar ndx = latDigit * GRID_COLUMNS_ + lngDigit;\n\t\t\tcode[SEPARATOR_POSITION_ + 2 + i] = CODE_ALPHABET_.charAt(ndx);\n\t\t\t// Note! Integer division.\n\t\t\tlatInt = Math.floor(latInt / GRID_ROWS_);\n\t\t\tlngInt = Math.floor(lngInt / GRID_COLUMNS_);\n\t\t}\n\t} else {\n\t\tlatInt = Math.floor(latInt / Math.pow(GRID_ROWS_, GRID_CODE_LENGTH_));\n\t\tlngInt = Math.floor(lngInt / Math.pow(GRID_COLUMNS_, GRID_CODE_LENGTH_));\n\t}\n\n\t// Add the pair after the separator.\n\tcode[SEPARATOR_POSITION_ + 1] = CODE_ALPHABET_.charAt(latInt % ENCODING_BASE_);\n\tcode[SEPARATOR_POSITION_ + 2] = CODE_ALPHABET_.charAt(lngInt % ENCODING_BASE_);\n\tlatInt = Math.floor(latInt / ENCODING_BASE_);\n\tlngInt = Math.floor(lngInt / ENCODING_BASE_);\n\n\t// Compute the pair section of the code.\n\tfor (var i = PAIR_CODE_LENGTH_ / 2 + 1; i \u003E= 0; i -= 2) {\n\t\tcode[i] = CODE_ALPHABET_.charAt(latInt % ENCODING_BASE_);\n\t\tcode[i + 1] = CODE_ALPHABET_.charAt(lngInt % ENCODING_BASE_);\n\t\tlatInt = Math.floor(latInt / ENCODING_BASE_);\n\t\tlngInt = Math.floor(lngInt / ENCODING_BASE_);\n\t}\n\n\t// If we don't need to pad the code, return the requested section.\n\tif (codeLength \u003E= SEPARATOR_POSITION_) {\n\t\treturn code.slice(0, codeLength + 1).join(*);\n\t}\n\t// Pad and return the code.\n\treturn code.slice(0, codeLength).join(*) +\n\t\tArray(SEPARATOR_POSITION_ - codeLength + 1).join(PADDING_CHARACTER_) + SEPARATOR_;\n};\n\nfunction Z25963( Z25963K1, Z25963K2, Z25963K3 ) {\n//\tWikifunctions.debug(Z25963K1);\n//\tWikifunctions.debug(Z25963K2);\n//\tWikifunctions.debug(Z25963K3);\n\tconst lat = Number(Z25963K1.K1) / Number(Z25963K1.K2);\n\tconst long = Number(Z25963K2.K1) / Number(Z25963K2.K2);\n//\tWikifunctions.debug(lat);\n//\tWikifunctions.debug(long);\n\treturn encode(lat, long, Number(Z25963K3));\n}"
        }
    },
    "Z2K3": {
        "Z1K1": "Z12",
        "Z12K1": [
            "Z11",
            {
                "Z1K1": "Z11",
                "Z11K1": "Z1002",
                "Z11K2": "Plus Code from co-ordinates, reference JS"
            }
        ]
    },
    "Z2K4": {
        "Z1K1": "Z32",
        "Z32K1": [
            "Z31"
        ]
    },
    "Z2K5": {
        "Z1K1": "Z12",
        "Z12K1": [
            "Z11"
        ]
    }
}