@sk-global/js-msearch-gsi-jp 2.0.1 → 2.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.module.js +1 -1
- package/dist/index.module.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var e=require("global-mercator"),r=require("axios"),t=require("axios-cache-interceptor"),
|
|
1
|
+
var e=require("global-mercator"),r=require("axios"),t=require("axios-cache-interceptor"),n=require("mapbox-vector-tile");function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var a=/*#__PURE__*/o(r);function i(){return i=Object.assign?Object.assign.bind():function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)({}).hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e},i.apply(null,arguments)}var s={JP:{zoomBase:10,tileUrl:"https://skglobal-jsc.github.io/open-reverse-geocoder/tiles/{z}/{x}/{y}.pbf",layer:"japanese-admins",getResult:function(e){var r,t;return{code:5===String(e.id).length?String(e.id):"0"+String(e.id),prefecture:null==(r=e.properties)?void 0:r.prefecture,city:null==(t=e.properties)?void 0:t.city}}}};s.DEFAULT=s.JP;var c=/GSI\.MUNI_ARRAY\["\d+"\]\s*=\s*'(.*?)';/g,u=t.setupCache(a.default.create({timeout:2e3}),{ttl:864e5});u.interceptors.request.use(function(e){var r=""+e.baseURL+e.url+"?"+new URLSearchParams(e.params).toString();return console.log("Full URL:",r),e});var l=s.DEFAULT;exports.getCityMap=function(){try{return Promise.resolve(function(e,r){try{var t=Promise.resolve(a.default.get("https://maps.gsi.go.jp/js/muni.js",{responseType:"text",timeout:500})).then(function(e){return r={},e.data.split("\n").forEach(function(e){if(c.test(e)){var t=function(e){var r=e.replace(c,"$1"),t=r.split(",");if(4!==t.length)throw new Error("invalid muni record: "+r);var n=t[0],o=t[1],a=t[2],i=t[3];return a=a.padStart(5,"0"),{prefCode:n=n.padStart(2,"0"),prefName:o,cityCode:a,cityName:i}}(e);r[t.cityCode]=t}}),r;var r})}catch(e){return r(e)}return t&&t.then?t.then(void 0,r):t}(0,function(e){return console.log("Failed to get muni map: "+e),{}}))}catch(e){return Promise.reject(e)}},exports.getElevation=function(e){var r=e.lon,t=e.lat;try{return Promise.resolve(u.get("https://mreversegeocoder.gsi.go.jp/general/dem/scripts/getelevation.php",{responseType:"json",params:{lat:t,lon:r}})).then(function(e){var n=parseFloat(e.data.elevation);return{longitude:r,latitude:t,elevation:n}})}catch(e){return Promise.reject(e)}},exports.reverseGeocoder=function(r){var t=r.lon,o=r.lat;try{return Promise.resolve(function(r,s){try{var c=Promise.resolve(function(r){try{var t=i({},l,void 0),o=e.lngLatToGoogle(r,t.zoomBase),s=o[0],c=o[1];return Promise.resolve(function(e,r,t,o){void 0===o&&(o=a.default);try{var i,s=function(e){return new n.VectorTile(i)},c=t.tileUrl.replace("{z}",String(t.zoomBase)).replace("{x}",String(e)).replace("{y}",String(r)),u=function(e,r){try{var t=Promise.resolve(o.get(c,{responseType:"arraybuffer"})).then(function(e){i=Buffer.from(e.data,"binary")})}catch(e){return r(e)}return t&&t.then?t.then(void 0,r):t}(0,function(e){throw e});return Promise.resolve(u&&u.then?u.then(s):s())}catch(e){return Promise.reject(e)}}(s,c,t,u)).then(function(e){return function(e,r,t,n,o){var a=Object.keys(e.layers);return Array.isArray(a)||(a=[a]),a.forEach(function(n){var i=e.layers[n];if(i&&o.layer===i.name)for(var s=0;s<i.length;s++){var c=i.feature(s).toGeoJSON(r,t,o.zoomBase);a.length>1&&(c.properties.vt_layer=n)}}),{}}(e,s,c,0,t)})}catch(e){return Promise.reject(e)}}([t,o]))}catch(e){return s()}return c&&c.then?c.then(void 0,s):c}(0,function(){return console.log("Failed to get city code from open reverse geocoder"),function(e){var r=e.lat,t=e.lon;try{return Promise.resolve(u.get("https://mreversegeocoder.gsi.go.jp/reverse-geocoder/LonLatToAddress",{responseType:"json",params:{lat:r,lon:t}})).then(function(e){var r=e.data.results;return{code:r.muniCd,city:r.lv01Nm}})}catch(e){return Promise.reject(e)}}({lat:o,lon:t})}))}catch(e){return Promise.reject(e)}};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/countryOptions.ts","../src/muni.ts","../src/index.ts","../src/utils.ts"],"sourcesContent":["import {\n ReverseGeocodingOptions,\n ReverseGeocodingResultJP,\n} from './interfaces';\n\n/**\n * vector tiles settings for each country\n */\nconst countryOptions: { [s: string]: ReverseGeocodingOptions } = {\n JP: {\n zoomBase: 10,\n // tileUrl: `http://127.0.0.1:5500/docs/tiles/{z}/{x}/{y}.pbf`,\n tileUrl: 'https://skglobal-jsc.github.io/open-reverse-geocoder/tiles/{z}/{x}/{y}.pbf',\n layer: 'japanese-admins',\n getResult: function (feature: GeoJSON.Feature) {\n const res: ReverseGeocodingResultJP = {\n code:\n 5 === String(feature.id).length\n ? String(feature.id)\n : `0${String(feature.id)}`,\n prefecture: feature.properties?.prefecture,\n city: feature.properties?.city,\n };\n return res;\n },\n },\n};\n\n// default country options\ncountryOptions.DEFAULT = countryOptions.JP;\n\nexport default countryOptions;\n","// Muni file url\nconst MuniURL = 'https://maps.gsi.go.jp/js/muni.js';\nconst MuniRegex = /GSI\\.MUNI_ARRAY\\[\"\\d+\"\\]\\s*=\\s*'(.*?)';/g;\n\nimport axios from 'axios';\n\ninterface MuniRecord {\n prefCode: string;\n prefName: string;\n cityCode: string;\n cityName: string;\n}\n\ninterface MuniMap {\n [key: string]: MuniRecord;\n}\n\ninterface AddressResults {\n muniCd: string;\n lv01Nm: string;\n mesh_code?: string;\n notes?: string;\n}\n\n/**\n * parse muni.js\n * @param muniMap\n */\nconst parseMuniMap = (muniMap: string) => {\n const muniMapObj: MuniMap = {};\n const lines = muniMap.split('\\n');\n lines.forEach((line) => {\n if (MuniRegex.test(line)) {\n const muniRecord = parseMuniRecord(line);\n muniMapObj[muniRecord.cityCode] = muniRecord;\n }\n });\n return muniMapObj;\n};\n\n/**\n * parse muni record\n * @param line\n */\nconst parseMuniRecord = (line: string) => {\n const muniRecord = line.replace(MuniRegex, '$1');\n\n const muniRecordArray = muniRecord.split(',');\n\n // validate muni record\n if (muniRecordArray.length !== 4) {\n throw new Error(`invalid muni record: ${muniRecord}`);\n }\n\n let [prefCode, prefName, cityCode, cityName] = muniRecordArray;\n\n // if cityCode is not 5 digits, add 0 to the beginning\n cityCode = cityCode.padStart(5, '0');\n\n // if prefCode is not 2 digits, add 0 to the beginning\n prefCode = prefCode.padStart(2, '0');\n\n return {\n prefCode: prefCode,\n prefName: prefName,\n cityCode: cityCode,\n cityName: cityName,\n };\n};\n\n/**\n * Fetches the municipality map data from a specified URL.\n *\n * @returns {Promise<object>} A promise that resolves to the parsed municipality map data.\n *\n * @throws Will log an error message and return an empty object if the request fails.\n */\nconst getMuniMap = async () => {\n try {\n const response = await axios.get(MuniURL, {\n responseType: 'text',\n timeout: 500,\n });\n\n const muniMap = response.data;\n return parseMuniMap(muniMap);\n } catch (error) {\n console.log(`Failed to get muni map: ${error}`);\n return {};\n }\n};\n\n/**\n * converts muni code to address name.\n *\n * @param muniMap\n * @param muniCode\n */\nconst muniCodeToAddressName = (muniMap: MuniMap, muniCode: string) => {\n const muniRecord = muniMap[muniCode];\n if (!muniRecord) {\n throw new Error(`muni code ${muniCode} not found`);\n }\n\n const add = `${muniRecord.prefName}${muniRecord.cityName}`;\n return add.replace(/ /g, '');\n};\n\n/**\n * converts address result to address name.\n * @param muniMap\n * @param addressResults\n */\nconst addressResultsToAddressName = (\n muniMap: MuniMap,\n addressResults: AddressResults\n) => {\n const mc = addressResults.muniCd;\n const muniName = muniCodeToAddressName(muniMap, mc);\n const addrName = `${muniName}${addressResults.lv01Nm}`;\n return addrName;\n};\n\nconst getMuniMapLocations = async () => {\n const muniMap = await getMuniMap();\n // muniMap is a map of all cities and wards in Japan\n // key: city code, value: { prefCode, prefName, cityCode, cityName }\n // we need to convert this to a map of all locations in Japan\n // key: prefCode , value: { prefName, cities: { key: cityCode, value: { cityCode, cityName, wards: { key: wardCode, value: { wardCode, wardName } } } } }\n\n const muniMapLocations = {};\n Object.keys(muniMap).forEach((cityCode) => {\n const muniRecord = muniMap[cityCode];\n const { prefCode, prefName, cityName } = muniRecord;\n if (!muniMapLocations[prefCode]) {\n muniMapLocations[prefCode] = { prefName, cities: {} };\n }\n\n // if cityName contains ' ', it is a ward\n // otherwise, it is a city\n if (cityName.includes(' ')) {\n // ward name is after ' '\n const [name, wardName] = cityName.split(' ');\n // find city has the same name\n const city: any = Object.values(muniMap).find(\n (c: any) => c.cityName === name\n );\n if (!city) {\n console.log(`City ${name} not found in prefCode ${prefCode}`);\n } else {\n // add ward to city\n muniMapLocations[prefCode].cities[city.cityCode].wards[cityCode] = {\n prefCode,\n cityCode: cityCode,\n cityName: `${name}${wardName}`,\n bigCityFlag: '1',\n bigCityCode: city.cityCode,\n };\n }\n } else {\n muniMapLocations[prefCode].cities[cityCode] = {\n prefCode,\n cityCode,\n cityName,\n wards: {},\n };\n }\n });\n\n // assign bigCityFlag to each city\n Object.keys(muniMapLocations).forEach((prefCode) => {\n const pref = muniMapLocations[prefCode];\n Object.keys(pref.cities).forEach((cityCode) => {\n const city = pref.cities[cityCode];\n const isBigCity = Object.values(city.wards).length > 0;\n if (isBigCity) {\n city.bigCityFlag = '2';\n } else {\n // delete wards\n delete city.wards;\n // if city is tokyo then bigCityFlag is 3, otherwise 0\n if (city.prefCode === '13') {\n city.bigCityFlag = '3';\n } else {\n city.bigCityFlag = '0';\n }\n }\n });\n });\n\n return muniMapLocations;\n};\n\nexport { getMuniMap };\n","import { lngLatToGoogle } from 'global-mercator';\nimport axios from 'axios';\nimport { setupCache } from 'axios-cache-interceptor';\nimport {\n ReverseGeocodingOptions,\n ReverseGeocodingResult,\n ReverseGeocodingResultJP,\n} from './interfaces';\nimport countryOptions from './countryOptions';\nimport { getTile, getTileResult } from './utils';\n\nimport { getMuniMap } from './muni';\n\ntype LngLat = [number, number];\n\nconst api = setupCache(\n axios.create({\n timeout: 2000,\n }),\n {\n ttl: 60 * 60 * 24 * 1000, // 1 day\n }\n);\n\napi.interceptors.request.use((config) => {\n const fullUrl = `${config.baseURL}${config.url}?${new URLSearchParams(\n config.params\n ).toString()}`;\n console.log('Full URL:', fullUrl);\n return config;\n});\n\nconst defaultOptions = countryOptions.DEFAULT;\n\n/**\n * Performs reverse geocoding to obtain location information based on longitude and latitude.\n *\n * @param lnglat - The longitude and latitude coordinates.\n * @param options - Optional parameters for reverse geocoding.\n * @returns A promise that resolves to the reverse geocoding result.\n */\nconst openReverseGeocoder = async (\n lnglat: LngLat,\n options?: ReverseGeocodingOptions\n): Promise<ReverseGeocodingResult> => {\n const opt = { ...defaultOptions, ...options };\n const [x, y] = lngLatToGoogle(lnglat, opt.zoomBase);\n const tile = await getTile(x, y, opt, api);\n return getTileResult(tile, x, y, lnglat, opt);\n};\n\n/**\n * Performs reverse geocoding using the GSI (Geospatial Information Authority of Japan) API.\n * Given latitude and longitude coordinates, it returns the corresponding municipality code and city name.\n *\n * @param {Object} params - The parameters for the reverse geocoding request.\n * @param {number} params.lat - The latitude coordinate.\n * @param {number} params.lon - The longitude coordinate.\n * @returns {Promise<ReverseGeocodingResultJP>} A promise that resolves to an object containing the municipality code and city name.\n *\n * @example\n * const result = await gsiReverseGeocoder({ lat: 35.6895, lon: 139.6917 });\n * console.log(result); // { code: '13101', city: 'Chiyoda-ku' }\n */\nconst gsiReverseGeocoder = async ({\n lat,\n lon,\n}: {\n lat: number;\n lon: number;\n}) => {\n const response = await api.get(\n 'https://mreversegeocoder.gsi.go.jp/reverse-geocoder/LonLatToAddress',\n {\n responseType: 'json',\n params: {\n lat,\n lon,\n },\n }\n );\n const result = response.data;\n const {\n results: { muniCd: code, lv01Nm: city },\n } = result;\n return { code, city } as ReverseGeocodingResultJP;\n};\n\n/**\n * Retrieves the elevation for a given longitude and latitude using the GSI API.\n *\n * @param {Object} coordinates - The coordinates for which to get the elevation.\n * @param {number} coordinates.lon - The longitude of the location.\n * @param {number} coordinates.lat - The latitude of the location.\n * @returns {Promise<{ longitude: number, latitude: number, elevation: number }>}\n * A promise that resolves to an object containing the longitude, latitude, and elevation.\n */\nconst getElevation = async ({ lon, lat }: { lon: number; lat: number }) => {\n // first, get elevation from GSI\n const response = await api.get(\n 'https://mreversegeocoder.gsi.go.jp/general/dem/scripts/getelevation.php',\n {\n responseType: 'json',\n params: {\n lat,\n lon,\n },\n }\n );\n\n const elevation = parseFloat(response.data.elevation);\n return { longitude: lon, latitude: lat, elevation };\n};\n\n/**\n * Reverse geocodes the given longitude and latitude to obtain a city code.\n *\n * @param {Object} params - The parameters for reverse geocoding.\n * @param {number} params.lon - The longitude of the location.\n * @param {number} params.lat - The latitude of the location.\n *\n * @returns {Promise<ReverseGeocodingResult>} A promise that resolves to the reverse geocoding result.\n *\n * @throws Will attempt to use an alternative geocoding service if the primary service fails.\n */\nconst reverseGeocoder = async ({\n lon,\n lat,\n}: {\n lon: number;\n lat: number;\n}): Promise<ReverseGeocodingResult> => {\n // first, get city code from open reverse geocoder(local)\n try {\n const result = await openReverseGeocoder([lon, lat]);\n return result;\n } catch (error) {\n // if failed, get city code from GSI\n console.log('Failed to get city code from open reverse geocoder');\n return gsiReverseGeocoder({ lat, lon });\n }\n};\n\nexport { reverseGeocoder, getElevation, getMuniMap as getCityMap };\n","import { geoContains } from 'd3-geo';\nimport axios, { AxiosInstance } from 'axios';\nimport { VectorTile } from 'mapbox-vector-tile';\nimport { ReverseGeocodingOptions, ReverseGeocodingResult } from './interfaces';\n\n/**\n * Get a tile from targeted country's tilesets by using x and y tile index\n * @param x x tile index\n * @param y y tile index\n * @param options ReverseGeocodingOptions\n * @param api Axios object\n * @returns VectorTile object\n */\nexport const getTile = async (\n x: number,\n y: number,\n options: ReverseGeocodingOptions,\n api: AxiosInstance = axios\n): Promise<VectorTile> => {\n const tileUrl = options.tileUrl\n .replace('{z}', String(options.zoomBase))\n .replace('{x}', String(x))\n .replace('{y}', String(y));\n\n let buffer;\n\n try {\n const res = await api.get(tileUrl, { responseType: 'arraybuffer' });\n buffer = Buffer.from(res.data, 'binary');\n } catch (error) {\n throw error;\n }\n\n const tile = new VectorTile(buffer);\n return tile;\n};\n\n/**\n * Get a result of reverse geocoding\n * @param tile VectorTile object\n * @param x x tile index\n * @param y y tile index\n * @param lnglat number[] longitude, latitude\n * @param options ReverseGeocodingOptions\n * @returns an object of result of reverse gecoding\n */\nexport const getTileResult = (\n tile: VectorTile,\n x: number,\n y: number,\n lnglat: [number, number],\n options: ReverseGeocodingOptions\n): ReverseGeocodingResult => {\n let layers = Object.keys(tile.layers);\n\n if (!Array.isArray(layers)) layers = [layers];\n\n let geocodingResult: ReverseGeocodingResult = {};\n layers.forEach((layerID) => {\n const layer = tile.layers[layerID];\n if (layer && options.layer === layer.name) {\n for (let i = 0; i < layer.length; i++) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const feature: any = layer.feature(i).toGeoJSON(x, y, options.zoomBase);\n if (layers.length > 1) feature.properties.vt_layer = layerID;\n\n const geojson = {\n type: 'FeatureCollection',\n features: [feature],\n };\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const res = geoContains(geojson as any, lnglat);\n if (res) {\n geocodingResult = options.getResult(feature);\n }\n }\n }\n });\n return geocodingResult;\n};\n\n"],"names":["countryOptions","JP","zoomBase","tileUrl","layer","getResult","feature","_feature$properties","_feature$properties2","code","String","id","length","prefecture","properties","city","DEFAULT","MuniRegex","api","setupCache","axios","create","timeout","ttl","interceptors","request","use","config","fullUrl","baseURL","url","URLSearchParams","params","toString","console","log","defaultOptions","Promise","resolve","get","responseType","then","response","muniMapObj","data","split","forEach","line","test","muniRecord","replace","muniRecordArray","Error","prefCode","prefName","cityCode","cityName","padStart","parseMuniRecord","_catch","error","e","reject","_ref2","lon","lat","elevation","parseFloat","longitude","latitude","_ref3","lnglat","opt","_extends","openReverseGeocoder","_lngLatToGoogle","lngLatToGoogle","x","y","options","buffer","_temp2","_result","VectorTile","_temp","res","Buffer","from","getTile","tile","layers","Object","keys","Array","isArray","geocodingResult","layerID","name","i","toGeoJSON","vt_layer","geoContains","type","features","getTileResult","_ref","_result$results","results","muniCd","lv01Nm","gsiReverseGeocoder"],"mappings":"qcAQA,IAAMA,EAA2D,CAC/DC,GAAI,CACFC,SAAU,GAEVC,QAAS,6EACTC,MAAO,kBACPC,UAAW,SAAUC,GAAwB,IAAAC,EAAAC,EAS3C,MARsC,CACpCC,KACE,IAAMC,OAAOJ,EAAQK,IAAIC,OACrBF,OAAOJ,EAAQK,QACXD,OAAOJ,EAAQK,IACzBE,WAAYN,OAAFA,EAAED,EAAQQ,iBAARP,EAAAA,EAAoBM,WAChCE,KAAMP,OAAFA,EAAEF,EAAQQ,iBAARN,EAAAA,EAAoBO,KAG9B,IAKJf,EAAegB,QAAUhB,EAAeC,GC5BxC,IACMgB,EAAY,2CCaZC,EAAMC,EAAAA,WACVC,EAAAA,QAAMC,OAAO,CACXC,QAAS,MAEX,CACEC,IAAK,QAITL,EAAIM,aAAaC,QAAQC,IAAI,SAACC,GAC5B,IAAMC,EAAO,GAAMD,EAAOE,QAAUF,EAAOG,IAAO,IAAA,IAAIC,gBACpDJ,EAAOK,QACPC,WAEF,OADAC,QAAQC,IAAI,YAAaP,GAClBD,CACT,GAEA,IAAMS,EAAiBpC,EAAegB,2BD6ChC,WAAU,WAAcqB,QAAAC,gCACxBD,QAAAC,QACqBlB,EAAK,QAACmB,IA9EjB,oCA8E8B,CACxCC,aAAc,OACdlB,QAAS,OACTmB,KAAA,SAHIC,GAMN,OAxDIC,EAAsB,CAAE,EAuDZD,EAASE,KAtDLC,MAAM,MACtBC,QAAQ,SAACC,GACb,GAAI9B,EAAU+B,KAAKD,GAAO,CACxB,IAAME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kBhB,EAAQ1E,UAAUC,GAEvC,CAEL,GACOyF,CACT,CDhCSS,CAAcf,EAAMZ,EAAGC,EAAGP,EAAQC,EAAK,EAChD,CAAC,MAAAX,GAAA,OAAAxB,QAAAyB,OAAAD,EAeD,CAAA,CAsEyBa,CAAoB,CAACV,EAAKC,6DAHbN,CAAA,EAKnC,WAGC,OADAzB,QAAQC,IAAI,sDA1EV,SAAkBsE,GACtB,IAAAxC,EAAGwC,EAAHxC,IACAD,EAAGyC,EAAHzC,IAAG,IAIA3B,OAAAA,QAAAC,QACoBpB,EAAIqB,IACzB,sEACA,CACEC,aAAc,OACdR,OAAQ,CACNiC,IAAAA,EACAD,IAAAA,MAGLvB,KAAA,SATKC,GAUN,IACAgE,EADehE,EAASE,KAEtB+D,QAEF,MAAO,CAAElG,KAFgBiG,EAAZE,OAEE7F,KAFwB2F,EAAZG,OAEuB,EACpD,CAAC,MAAAhD,GAAA,OAAAxB,QAAAyB,OAAAD,EAAA,CAAA,CAqDUiD,CAAmB,CAAE7C,IAAAA,EAAKD,IAAAA,GAClC,GACH,CAAC,MAAAH,GAAA,OAAAxB,QAAAyB,OAAAD,EAED,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/countryOptions.ts","../src/muni.ts","../src/index.ts","../src/utils.ts"],"sourcesContent":["import {\n ReverseGeocodingOptions,\n ReverseGeocodingResultJP,\n} from './interfaces';\n\n/**\n * vector tiles settings for each country\n */\nconst countryOptions: { [s: string]: ReverseGeocodingOptions } = {\n JP: {\n zoomBase: 10,\n // tileUrl: `http://127.0.0.1:5500/docs/tiles/{z}/{x}/{y}.pbf`,\n tileUrl: 'https://skglobal-jsc.github.io/open-reverse-geocoder/tiles/{z}/{x}/{y}.pbf',\n layer: 'japanese-admins',\n getResult: function (feature: GeoJSON.Feature) {\n const res: ReverseGeocodingResultJP = {\n code:\n 5 === String(feature.id).length\n ? String(feature.id)\n : `0${String(feature.id)}`,\n prefecture: feature.properties?.prefecture,\n city: feature.properties?.city,\n };\n return res;\n },\n },\n};\n\n// default country options\ncountryOptions.DEFAULT = countryOptions.JP;\n\nexport default countryOptions;\n","// Muni file url\nconst MuniURL = 'https://maps.gsi.go.jp/js/muni.js';\nconst MuniRegex = /GSI\\.MUNI_ARRAY\\[\"\\d+\"\\]\\s*=\\s*'(.*?)';/g;\n\nimport axios from 'axios';\n\ninterface MuniRecord {\n prefCode: string;\n prefName: string;\n cityCode: string;\n cityName: string;\n}\n\ninterface MuniMap {\n [key: string]: MuniRecord;\n}\n\ninterface AddressResults {\n muniCd: string;\n lv01Nm: string;\n mesh_code?: string;\n notes?: string;\n}\n\n/**\n * parse muni.js\n * @param muniMap\n */\nconst parseMuniMap = (muniMap: string) => {\n const muniMapObj: MuniMap = {};\n const lines = muniMap.split('\\n');\n lines.forEach((line) => {\n if (MuniRegex.test(line)) {\n const muniRecord = parseMuniRecord(line);\n muniMapObj[muniRecord.cityCode] = muniRecord;\n }\n });\n return muniMapObj;\n};\n\n/**\n * parse muni record\n * @param line\n */\nconst parseMuniRecord = (line: string) => {\n const muniRecord = line.replace(MuniRegex, '$1');\n\n const muniRecordArray = muniRecord.split(',');\n\n // validate muni record\n if (muniRecordArray.length !== 4) {\n throw new Error(`invalid muni record: ${muniRecord}`);\n }\n\n let [prefCode, prefName, cityCode, cityName] = muniRecordArray;\n\n // if cityCode is not 5 digits, add 0 to the beginning\n cityCode = cityCode.padStart(5, '0');\n\n // if prefCode is not 2 digits, add 0 to the beginning\n prefCode = prefCode.padStart(2, '0');\n\n return {\n prefCode: prefCode,\n prefName: prefName,\n cityCode: cityCode,\n cityName: cityName,\n };\n};\n\n/**\n * Fetches the municipality map data from a specified URL.\n *\n * @returns {Promise<object>} A promise that resolves to the parsed municipality map data.\n *\n * @throws Will log an error message and return an empty object if the request fails.\n */\nconst getMuniMap = async () => {\n try {\n const response = await axios.get(MuniURL, {\n responseType: 'text',\n timeout: 500,\n });\n\n const muniMap = response.data;\n return parseMuniMap(muniMap);\n } catch (error) {\n console.log(`Failed to get muni map: ${error}`);\n return {};\n }\n};\n\n/**\n * converts muni code to address name.\n *\n * @param muniMap\n * @param muniCode\n */\nconst muniCodeToAddressName = (muniMap: MuniMap, muniCode: string) => {\n const muniRecord = muniMap[muniCode];\n if (!muniRecord) {\n throw new Error(`muni code ${muniCode} not found`);\n }\n\n const add = `${muniRecord.prefName}${muniRecord.cityName}`;\n return add.replace(/ /g, '');\n};\n\n/**\n * converts address result to address name.\n * @param muniMap\n * @param addressResults\n */\nconst addressResultsToAddressName = (\n muniMap: MuniMap,\n addressResults: AddressResults\n) => {\n const mc = addressResults.muniCd;\n const muniName = muniCodeToAddressName(muniMap, mc);\n const addrName = `${muniName}${addressResults.lv01Nm}`;\n return addrName;\n};\n\nconst getMuniMapLocations = async () => {\n const muniMap = await getMuniMap();\n // muniMap is a map of all cities and wards in Japan\n // key: city code, value: { prefCode, prefName, cityCode, cityName }\n // we need to convert this to a map of all locations in Japan\n // key: prefCode , value: { prefName, cities: { key: cityCode, value: { cityCode, cityName, wards: { key: wardCode, value: { wardCode, wardName } } } } }\n\n const muniMapLocations = {};\n Object.keys(muniMap).forEach((cityCode) => {\n const muniRecord = muniMap[cityCode];\n const { prefCode, prefName, cityName } = muniRecord;\n if (!muniMapLocations[prefCode]) {\n muniMapLocations[prefCode] = { prefName, cities: {} };\n }\n\n // if cityName contains ' ', it is a ward\n // otherwise, it is a city\n if (cityName.includes(' ')) {\n // ward name is after ' '\n const [name, wardName] = cityName.split(' ');\n // find city has the same name\n const city: any = Object.values(muniMap).find(\n (c: any) => c.cityName === name\n );\n if (!city) {\n console.log(`City ${name} not found in prefCode ${prefCode}`);\n } else {\n // add ward to city\n muniMapLocations[prefCode].cities[city.cityCode].wards[cityCode] = {\n prefCode,\n cityCode: cityCode,\n cityName: `${name}${wardName}`,\n bigCityFlag: '1',\n bigCityCode: city.cityCode,\n };\n }\n } else {\n muniMapLocations[prefCode].cities[cityCode] = {\n prefCode,\n cityCode,\n cityName,\n wards: {},\n };\n }\n });\n\n // assign bigCityFlag to each city\n Object.keys(muniMapLocations).forEach((prefCode) => {\n const pref = muniMapLocations[prefCode];\n Object.keys(pref.cities).forEach((cityCode) => {\n const city = pref.cities[cityCode];\n const isBigCity = Object.values(city.wards).length > 0;\n if (isBigCity) {\n city.bigCityFlag = '2';\n } else {\n // delete wards\n delete city.wards;\n // if city is tokyo then bigCityFlag is 3, otherwise 0\n if (city.prefCode === '13') {\n city.bigCityFlag = '3';\n } else {\n city.bigCityFlag = '0';\n }\n }\n });\n });\n\n return muniMapLocations;\n};\n\nexport { getMuniMap };\n","import { lngLatToGoogle } from 'global-mercator';\nimport axios from 'axios';\nimport { setupCache } from 'axios-cache-interceptor';\nimport {\n ReverseGeocodingOptions,\n ReverseGeocodingResult,\n ReverseGeocodingResultJP,\n} from './interfaces';\nimport countryOptions from './countryOptions';\nimport { getTile, getTileResult } from './utils';\n\nimport { getMuniMap } from './muni';\n\ntype LngLat = [number, number];\n\nconst api = setupCache(\n axios.create({\n timeout: 2000,\n }),\n {\n ttl: 60 * 60 * 24 * 1000, // 1 day\n }\n);\n\napi.interceptors.request.use((config) => {\n const fullUrl = `${config.baseURL}${config.url}?${new URLSearchParams(\n config.params\n ).toString()}`;\n console.log('Full URL:', fullUrl);\n return config;\n});\n\nconst defaultOptions = countryOptions.DEFAULT;\n\n/**\n * Performs reverse geocoding to obtain location information based on longitude and latitude.\n *\n * @param lnglat - The longitude and latitude coordinates.\n * @param options - Optional parameters for reverse geocoding.\n * @returns A promise that resolves to the reverse geocoding result.\n */\nconst openReverseGeocoder = async (\n lnglat: LngLat,\n options?: ReverseGeocodingOptions\n): Promise<ReverseGeocodingResult> => {\n const opt = { ...defaultOptions, ...options };\n const [x, y] = lngLatToGoogle(lnglat, opt.zoomBase);\n const tile = await getTile(x, y, opt, api);\n return getTileResult(tile, x, y, lnglat, opt);\n};\n\n/**\n * Performs reverse geocoding using the GSI (Geospatial Information Authority of Japan) API.\n * Given latitude and longitude coordinates, it returns the corresponding municipality code and city name.\n *\n * @param {Object} params - The parameters for the reverse geocoding request.\n * @param {number} params.lat - The latitude coordinate.\n * @param {number} params.lon - The longitude coordinate.\n * @returns {Promise<ReverseGeocodingResultJP>} A promise that resolves to an object containing the municipality code and city name.\n *\n * @example\n * const result = await gsiReverseGeocoder({ lat: 35.6895, lon: 139.6917 });\n * console.log(result); // { code: '13101', city: 'Chiyoda-ku' }\n */\nconst gsiReverseGeocoder = async ({\n lat,\n lon,\n}: {\n lat: number;\n lon: number;\n}) => {\n const response = await api.get(\n 'https://mreversegeocoder.gsi.go.jp/reverse-geocoder/LonLatToAddress',\n {\n responseType: 'json',\n params: {\n lat,\n lon,\n },\n }\n );\n const result = response.data;\n const {\n results: { muniCd: code, lv01Nm: city },\n } = result;\n return { code, city } as ReverseGeocodingResultJP;\n};\n\n/**\n * Retrieves the elevation for a given longitude and latitude using the GSI API.\n *\n * @param {Object} coordinates - The coordinates for which to get the elevation.\n * @param {number} coordinates.lon - The longitude of the location.\n * @param {number} coordinates.lat - The latitude of the location.\n * @returns {Promise<{ longitude: number, latitude: number, elevation: number }>}\n * A promise that resolves to an object containing the longitude, latitude, and elevation.\n */\nconst getElevation = async ({ lon, lat }: { lon: number; lat: number }) => {\n // first, get elevation from GSI\n const response = await api.get(\n 'https://mreversegeocoder.gsi.go.jp/general/dem/scripts/getelevation.php',\n {\n responseType: 'json',\n params: {\n lat,\n lon,\n },\n }\n );\n\n const elevation = parseFloat(response.data.elevation);\n return { longitude: lon, latitude: lat, elevation };\n};\n\n/**\n * Reverse geocodes the given longitude and latitude to obtain a city code.\n *\n * @param {Object} params - The parameters for reverse geocoding.\n * @param {number} params.lon - The longitude of the location.\n * @param {number} params.lat - The latitude of the location.\n *\n * @returns {Promise<ReverseGeocodingResult>} A promise that resolves to the reverse geocoding result.\n *\n * @throws Will attempt to use an alternative geocoding service if the primary service fails.\n */\nconst reverseGeocoder = async ({\n lon,\n lat,\n}: {\n lon: number;\n lat: number;\n}): Promise<ReverseGeocodingResult> => {\n // first, get city code from open reverse geocoder(local)\n try {\n const result = await openReverseGeocoder([lon, lat]);\n return result;\n } catch (error) {\n // if failed, get city code from GSI\n console.log('Failed to get city code from open reverse geocoder');\n return gsiReverseGeocoder({ lat, lon });\n }\n};\n\nexport { reverseGeocoder, getElevation, getMuniMap as getCityMap };\n","// import { geoContains } from 'd3-geo';\nimport axios, { AxiosInstance } from 'axios';\nimport { VectorTile } from 'mapbox-vector-tile';\nimport { ReverseGeocodingOptions, ReverseGeocodingResult } from './interfaces';\n\n/**\n * Get a tile from targeted country's tilesets by using x and y tile index\n * @param x x tile index\n * @param y y tile index\n * @param options ReverseGeocodingOptions\n * @param api Axios object\n * @returns VectorTile object\n */\nexport const getTile = async (\n x: number,\n y: number,\n options: ReverseGeocodingOptions,\n api: AxiosInstance = axios\n): Promise<VectorTile> => {\n const tileUrl = options.tileUrl\n .replace('{z}', String(options.zoomBase))\n .replace('{x}', String(x))\n .replace('{y}', String(y));\n\n let buffer;\n\n try {\n const res = await api.get(tileUrl, { responseType: 'arraybuffer' });\n buffer = Buffer.from(res.data, 'binary');\n } catch (error) {\n throw error;\n }\n\n const tile = new VectorTile(buffer);\n return tile;\n};\n\n/**\n * Get a result of reverse geocoding\n * @param tile VectorTile object\n * @param x x tile index\n * @param y y tile index\n * @param lnglat number[] longitude, latitude\n * @param options ReverseGeocodingOptions\n * @returns an object of result of reverse gecoding\n */\nexport const getTileResult = (\n tile: VectorTile,\n x: number,\n y: number,\n lnglat: [number, number],\n options: ReverseGeocodingOptions\n): ReverseGeocodingResult => {\n let layers = Object.keys(tile.layers);\n\n if (!Array.isArray(layers)) layers = [layers];\n\n let geocodingResult: ReverseGeocodingResult = {};\n layers.forEach((layerID) => {\n const layer = tile.layers[layerID];\n if (layer && options.layer === layer.name) {\n for (let i = 0; i < layer.length; i++) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const feature: any = layer.feature(i).toGeoJSON(x, y, options.zoomBase);\n if (layers.length > 1) feature.properties.vt_layer = layerID;\n\n const geojson = {\n type: 'FeatureCollection',\n features: [feature],\n };\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n // const res = geoContains(geojson as any, lnglat);\n // if (res) {\n // geocodingResult = options.getResult(feature);\n // }\n }\n }\n });\n return geocodingResult;\n};\n\n"],"names":["countryOptions","JP","zoomBase","tileUrl","layer","getResult","feature","_feature$properties","_feature$properties2","code","String","id","length","prefecture","properties","city","DEFAULT","MuniRegex","api","setupCache","axios","create","timeout","ttl","interceptors","request","use","config","fullUrl","baseURL","url","URLSearchParams","params","toString","console","log","defaultOptions","Promise","resolve","get","responseType","then","response","muniMapObj","data","split","forEach","line","test","muniRecord","replace","muniRecordArray","Error","prefCode","prefName","cityCode","cityName","padStart","parseMuniRecord","_catch","error","e","reject","_ref2","lon","lat","elevation","parseFloat","longitude","latitude","_ref3","lnglat","opt","_extends","openReverseGeocoder","_lngLatToGoogle","lngLatToGoogle","x","y","options","buffer","_temp2","_result","VectorTile","_temp","res","Buffer","from","getTile","tile","layers","Object","keys","Array","isArray","layerID","name","i","toGeoJSON","vt_layer","getTileResult","_ref","_result$results","results","muniCd","lv01Nm","gsiReverseGeocoder"],"mappings":"ibAQA,IAAMA,EAA2D,CAC/DC,GAAI,CACFC,SAAU,GAEVC,QAAS,6EACTC,MAAO,kBACPC,UAAW,SAAUC,GAAwB,IAAAC,EAAAC,EAS3C,MARsC,CACpCC,KACE,IAAMC,OAAOJ,EAAQK,IAAIC,OACrBF,OAAOJ,EAAQK,QACXD,OAAOJ,EAAQK,IACzBE,WAAYN,OAAFA,EAAED,EAAQQ,iBAARP,EAAAA,EAAoBM,WAChCE,KAAMP,OAAFA,EAAEF,EAAQQ,iBAARN,EAAAA,EAAoBO,KAG9B,IAKJf,EAAegB,QAAUhB,EAAeC,GC5BxC,IACMgB,EAAY,2CCaZC,EAAMC,EAAAA,WACVC,EAAAA,QAAMC,OAAO,CACXC,QAAS,MAEX,CACEC,IAAK,QAITL,EAAIM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AS,CAACA,IAGtCA,EAAO5C,QAAQ,SAACiD,GACd,IAAM3F,EAAQqF,EAAKC,OAAOK,GAC1B,GAAI3F,GAAS2E,EAAQ3E,QAAUA,EAAM4F,KACnC,IAAK,IAAIC,EAAI,EAAGA,EAAI7F,EAAMQ,OAAQqF,IAAK,CAErC,IAAM3F,EAAeF,EAAME,QAAQ2F,GAAGC,UAAUrB,EAAGC,EAAGC,EAAQ7E,UAC1DwF,EAAO9E,OAAS,IAAGN,EAAQQ,WAAWqF,SAAWJ,EAYtD,CAEL,GArB8C,CAAE,CAuBlD,CDhCSK,CAAcX,EAAMZ,EAAGC,EAAGP,EAAQC,EAAK,EAChD,CAAC,MAAAX,GAAA,OAAAxB,QAAAyB,OAAAD,EAeD,CAAA,CAsEyBa,CAAoB,CAACV,EAAKC,6DAHbN,CAAA,EAKnC,WAGC,OADAzB,QAAQC,IAAI,sDA1EV,SAAkBkE,GACtB,IAAApC,EAAGoC,EAAHpC,IACAD,EAAGqC,EAAHrC,IAAG,IAIA3B,OAAAA,QAAAC,QACoBpB,EAAIqB,IACzB,sEACA,CACEC,aAAc,OACdR,OAAQ,CACNiC,IAAAA,EACAD,IAAAA,MAGLvB,KAAA,SATKC,GAUN,IACA4D,EADe5D,EAASE,KAEtB2D,QAEF,MAAO,CAAE9F,KAFgB6F,EAAZE,OAEEzF,KAFwBuF,EAAZG,OAEuB,EACpD,CAAC,MAAA5C,GAAA,OAAAxB,QAAAyB,OAAAD,EAAA,CAAA,CAqDU6C,CAAmB,CAAEzC,IAAAA,EAAKD,IAAAA,GAClC,GACH,CAAC,MAAAH,GAAA,OAAAxB,QAAAyB,OAAAD,EAED,CAAA"}
|
package/dist/index.module.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{lngLatToGoogle as e}from"global-mercator";import r from"axios";import{setupCache as t}from"axios-cache-interceptor";import{
|
|
1
|
+
import{lngLatToGoogle as e}from"global-mercator";import r from"axios";import{setupCache as t}from"axios-cache-interceptor";import{VectorTile as o}from"mapbox-vector-tile";function n(){return n=Object.assign?Object.assign.bind():function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var o in t)({}).hasOwnProperty.call(t,o)&&(e[o]=t[o])}return e},n.apply(null,arguments)}var a={JP:{zoomBase:10,tileUrl:"https://skglobal-jsc.github.io/open-reverse-geocoder/tiles/{z}/{x}/{y}.pbf",layer:"japanese-admins",getResult:function(e){var r,t;return{code:5===String(e.id).length?String(e.id):"0"+String(e.id),prefecture:null==(r=e.properties)?void 0:r.prefecture,city:null==(t=e.properties)?void 0:t.city}}}};a.DEFAULT=a.JP;var i=/GSI\.MUNI_ARRAY\["\d+"\]\s*=\s*'(.*?)';/g,s=function(){try{return Promise.resolve(function(e,t){try{var o=Promise.resolve(r.get("https://maps.gsi.go.jp/js/muni.js",{responseType:"text",timeout:500})).then(function(e){return r={},e.data.split("\n").forEach(function(e){if(i.test(e)){var t=function(e){var r=e.replace(i,"$1"),t=r.split(",");if(4!==t.length)throw new Error("invalid muni record: "+r);var o=t[0],n=t[1],a=t[2],s=t[3];return a=a.padStart(5,"0"),{prefCode:o=o.padStart(2,"0"),prefName:n,cityCode:a,cityName:s}}(e);r[t.cityCode]=t}}),r;var r})}catch(e){return t(e)}return o&&o.then?o.then(void 0,t):o}(0,function(e){return console.log("Failed to get muni map: "+e),{}}))}catch(e){return Promise.reject(e)}},c=t(r.create({timeout:2e3}),{ttl:864e5});c.interceptors.request.use(function(e){var r=""+e.baseURL+e.url+"?"+new URLSearchParams(e.params).toString();return console.log("Full URL:",r),e});var u=a.DEFAULT,l=function(e){var r=e.lon,t=e.lat;try{return Promise.resolve(c.get("https://mreversegeocoder.gsi.go.jp/general/dem/scripts/getelevation.php",{responseType:"json",params:{lat:t,lon:r}})).then(function(e){var o=parseFloat(e.data.elevation);return{longitude:r,latitude:t,elevation:o}})}catch(e){return Promise.reject(e)}},p=function(t){var a=t.lon,i=t.lat;try{return Promise.resolve(function(t,s){try{var l=Promise.resolve(function(t){try{var a=n({},u,void 0),i=e(t,a.zoomBase),s=i[0],l=i[1];return Promise.resolve(function(e,t,n,a){void 0===a&&(a=r);try{var i,s=function(e){return new o(i)},c=n.tileUrl.replace("{z}",String(n.zoomBase)).replace("{x}",String(e)).replace("{y}",String(t)),u=function(e,r){try{var t=Promise.resolve(a.get(c,{responseType:"arraybuffer"})).then(function(e){i=Buffer.from(e.data,"binary")})}catch(e){return r(e)}return t&&t.then?t.then(void 0,r):t}(0,function(e){throw e});return Promise.resolve(u&&u.then?u.then(s):s())}catch(e){return Promise.reject(e)}}(s,l,a,c)).then(function(e){return function(e,r,t,o,n){var a=Object.keys(e.layers);return Array.isArray(a)||(a=[a]),a.forEach(function(o){var i=e.layers[o];if(i&&n.layer===i.name)for(var s=0;s<i.length;s++){var c=i.feature(s).toGeoJSON(r,t,n.zoomBase);a.length>1&&(c.properties.vt_layer=o)}}),{}}(e,s,l,0,a)})}catch(e){return Promise.reject(e)}}([a,i]))}catch(e){return s()}return l&&l.then?l.then(void 0,s):l}(0,function(){return console.log("Failed to get city code from open reverse geocoder"),function(e){var r=e.lat,t=e.lon;try{return Promise.resolve(c.get("https://mreversegeocoder.gsi.go.jp/reverse-geocoder/LonLatToAddress",{responseType:"json",params:{lat:r,lon:t}})).then(function(e){var r=e.data.results;return{code:r.muniCd,city:r.lv01Nm}})}catch(e){return Promise.reject(e)}}({lat:i,lon:a})}))}catch(e){return Promise.reject(e)}};export{s as getCityMap,l as getElevation,p as reverseGeocoder};
|
|
2
2
|
//# sourceMappingURL=index.module.js.map
|
package/dist/index.module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.module.js","sources":["../src/countryOptions.ts","../src/muni.ts","../src/index.ts","../src/utils.ts"],"sourcesContent":["import {\n ReverseGeocodingOptions,\n ReverseGeocodingResultJP,\n} from './interfaces';\n\n/**\n * vector tiles settings for each country\n */\nconst countryOptions: { [s: string]: ReverseGeocodingOptions } = {\n JP: {\n zoomBase: 10,\n // tileUrl: `http://127.0.0.1:5500/docs/tiles/{z}/{x}/{y}.pbf`,\n tileUrl: 'https://skglobal-jsc.github.io/open-reverse-geocoder/tiles/{z}/{x}/{y}.pbf',\n layer: 'japanese-admins',\n getResult: function (feature: GeoJSON.Feature) {\n const res: ReverseGeocodingResultJP = {\n code:\n 5 === String(feature.id).length\n ? String(feature.id)\n : `0${String(feature.id)}`,\n prefecture: feature.properties?.prefecture,\n city: feature.properties?.city,\n };\n return res;\n },\n },\n};\n\n// default country options\ncountryOptions.DEFAULT = countryOptions.JP;\n\nexport default countryOptions;\n","// Muni file url\nconst MuniURL = 'https://maps.gsi.go.jp/js/muni.js';\nconst MuniRegex = /GSI\\.MUNI_ARRAY\\[\"\\d+\"\\]\\s*=\\s*'(.*?)';/g;\n\nimport axios from 'axios';\n\ninterface MuniRecord {\n prefCode: string;\n prefName: string;\n cityCode: string;\n cityName: string;\n}\n\ninterface MuniMap {\n [key: string]: MuniRecord;\n}\n\ninterface AddressResults {\n muniCd: string;\n lv01Nm: string;\n mesh_code?: string;\n notes?: string;\n}\n\n/**\n * parse muni.js\n * @param muniMap\n */\nconst parseMuniMap = (muniMap: string) => {\n const muniMapObj: MuniMap = {};\n const lines = muniMap.split('\\n');\n lines.forEach((line) => {\n if (MuniRegex.test(line)) {\n const muniRecord = parseMuniRecord(line);\n muniMapObj[muniRecord.cityCode] = muniRecord;\n }\n });\n return muniMapObj;\n};\n\n/**\n * parse muni record\n * @param line\n */\nconst parseMuniRecord = (line: string) => {\n const muniRecord = line.replace(MuniRegex, '$1');\n\n const muniRecordArray = muniRecord.split(',');\n\n // validate muni record\n if (muniRecordArray.length !== 4) {\n throw new Error(`invalid muni record: ${muniRecord}`);\n }\n\n let [prefCode, prefName, cityCode, cityName] = muniRecordArray;\n\n // if cityCode is not 5 digits, add 0 to the beginning\n cityCode = cityCode.padStart(5, '0');\n\n // if prefCode is not 2 digits, add 0 to the beginning\n prefCode = prefCode.padStart(2, '0');\n\n return {\n prefCode: prefCode,\n prefName: prefName,\n cityCode: cityCode,\n cityName: cityName,\n };\n};\n\n/**\n * Fetches the municipality map data from a specified URL.\n *\n * @returns {Promise<object>} A promise that resolves to the parsed municipality map data.\n *\n * @throws Will log an error message and return an empty object if the request fails.\n */\nconst getMuniMap = async () => {\n try {\n const response = await axios.get(MuniURL, {\n responseType: 'text',\n timeout: 500,\n });\n\n const muniMap = response.data;\n return parseMuniMap(muniMap);\n } catch (error) {\n console.log(`Failed to get muni map: ${error}`);\n return {};\n }\n};\n\n/**\n * converts muni code to address name.\n *\n * @param muniMap\n * @param muniCode\n */\nconst muniCodeToAddressName = (muniMap: MuniMap, muniCode: string) => {\n const muniRecord = muniMap[muniCode];\n if (!muniRecord) {\n throw new Error(`muni code ${muniCode} not found`);\n }\n\n const add = `${muniRecord.prefName}${muniRecord.cityName}`;\n return add.replace(/ /g, '');\n};\n\n/**\n * converts address result to address name.\n * @param muniMap\n * @param addressResults\n */\nconst addressResultsToAddressName = (\n muniMap: MuniMap,\n addressResults: AddressResults\n) => {\n const mc = addressResults.muniCd;\n const muniName = muniCodeToAddressName(muniMap, mc);\n const addrName = `${muniName}${addressResults.lv01Nm}`;\n return addrName;\n};\n\nconst getMuniMapLocations = async () => {\n const muniMap = await getMuniMap();\n // muniMap is a map of all cities and wards in Japan\n // key: city code, value: { prefCode, prefName, cityCode, cityName }\n // we need to convert this to a map of all locations in Japan\n // key: prefCode , value: { prefName, cities: { key: cityCode, value: { cityCode, cityName, wards: { key: wardCode, value: { wardCode, wardName } } } } }\n\n const muniMapLocations = {};\n Object.keys(muniMap).forEach((cityCode) => {\n const muniRecord = muniMap[cityCode];\n const { prefCode, prefName, cityName } = muniRecord;\n if (!muniMapLocations[prefCode]) {\n muniMapLocations[prefCode] = { prefName, cities: {} };\n }\n\n // if cityName contains ' ', it is a ward\n // otherwise, it is a city\n if (cityName.includes(' ')) {\n // ward name is after ' '\n const [name, wardName] = cityName.split(' ');\n // find city has the same name\n const city: any = Object.values(muniMap).find(\n (c: any) => c.cityName === name\n );\n if (!city) {\n console.log(`City ${name} not found in prefCode ${prefCode}`);\n } else {\n // add ward to city\n muniMapLocations[prefCode].cities[city.cityCode].wards[cityCode] = {\n prefCode,\n cityCode: cityCode,\n cityName: `${name}${wardName}`,\n bigCityFlag: '1',\n bigCityCode: city.cityCode,\n };\n }\n } else {\n muniMapLocations[prefCode].cities[cityCode] = {\n prefCode,\n cityCode,\n cityName,\n wards: {},\n };\n }\n });\n\n // assign bigCityFlag to each city\n Object.keys(muniMapLocations).forEach((prefCode) => {\n const pref = muniMapLocations[prefCode];\n Object.keys(pref.cities).forEach((cityCode) => {\n const city = pref.cities[cityCode];\n const isBigCity = Object.values(city.wards).length > 0;\n if (isBigCity) {\n city.bigCityFlag = '2';\n } else {\n // delete wards\n delete city.wards;\n // if city is tokyo then bigCityFlag is 3, otherwise 0\n if (city.prefCode === '13') {\n city.bigCityFlag = '3';\n } else {\n city.bigCityFlag = '0';\n }\n }\n });\n });\n\n return muniMapLocations;\n};\n\nexport { getMuniMap };\n","import { lngLatToGoogle } from 'global-mercator';\nimport axios from 'axios';\nimport { setupCache } from 'axios-cache-interceptor';\nimport {\n ReverseGeocodingOptions,\n ReverseGeocodingResult,\n ReverseGeocodingResultJP,\n} from './interfaces';\nimport countryOptions from './countryOptions';\nimport { getTile, getTileResult } from './utils';\n\nimport { getMuniMap } from './muni';\n\ntype LngLat = [number, number];\n\nconst api = setupCache(\n axios.create({\n timeout: 2000,\n }),\n {\n ttl: 60 * 60 * 24 * 1000, // 1 day\n }\n);\n\napi.interceptors.request.use((config) => {\n const fullUrl = `${config.baseURL}${config.url}?${new URLSearchParams(\n config.params\n ).toString()}`;\n console.log('Full URL:', fullUrl);\n return config;\n});\n\nconst defaultOptions = countryOptions.DEFAULT;\n\n/**\n * Performs reverse geocoding to obtain location information based on longitude and latitude.\n *\n * @param lnglat - The longitude and latitude coordinates.\n * @param options - Optional parameters for reverse geocoding.\n * @returns A promise that resolves to the reverse geocoding result.\n */\nconst openReverseGeocoder = async (\n lnglat: LngLat,\n options?: ReverseGeocodingOptions\n): Promise<ReverseGeocodingResult> => {\n const opt = { ...defaultOptions, ...options };\n const [x, y] = lngLatToGoogle(lnglat, opt.zoomBase);\n const tile = await getTile(x, y, opt, api);\n return getTileResult(tile, x, y, lnglat, opt);\n};\n\n/**\n * Performs reverse geocoding using the GSI (Geospatial Information Authority of Japan) API.\n * Given latitude and longitude coordinates, it returns the corresponding municipality code and city name.\n *\n * @param {Object} params - The parameters for the reverse geocoding request.\n * @param {number} params.lat - The latitude coordinate.\n * @param {number} params.lon - The longitude coordinate.\n * @returns {Promise<ReverseGeocodingResultJP>} A promise that resolves to an object containing the municipality code and city name.\n *\n * @example\n * const result = await gsiReverseGeocoder({ lat: 35.6895, lon: 139.6917 });\n * console.log(result); // { code: '13101', city: 'Chiyoda-ku' }\n */\nconst gsiReverseGeocoder = async ({\n lat,\n lon,\n}: {\n lat: number;\n lon: number;\n}) => {\n const response = await api.get(\n 'https://mreversegeocoder.gsi.go.jp/reverse-geocoder/LonLatToAddress',\n {\n responseType: 'json',\n params: {\n lat,\n lon,\n },\n }\n );\n const result = response.data;\n const {\n results: { muniCd: code, lv01Nm: city },\n } = result;\n return { code, city } as ReverseGeocodingResultJP;\n};\n\n/**\n * Retrieves the elevation for a given longitude and latitude using the GSI API.\n *\n * @param {Object} coordinates - The coordinates for which to get the elevation.\n * @param {number} coordinates.lon - The longitude of the location.\n * @param {number} coordinates.lat - The latitude of the location.\n * @returns {Promise<{ longitude: number, latitude: number, elevation: number }>}\n * A promise that resolves to an object containing the longitude, latitude, and elevation.\n */\nconst getElevation = async ({ lon, lat }: { lon: number; lat: number }) => {\n // first, get elevation from GSI\n const response = await api.get(\n 'https://mreversegeocoder.gsi.go.jp/general/dem/scripts/getelevation.php',\n {\n responseType: 'json',\n params: {\n lat,\n lon,\n },\n }\n );\n\n const elevation = parseFloat(response.data.elevation);\n return { longitude: lon, latitude: lat, elevation };\n};\n\n/**\n * Reverse geocodes the given longitude and latitude to obtain a city code.\n *\n * @param {Object} params - The parameters for reverse geocoding.\n * @param {number} params.lon - The longitude of the location.\n * @param {number} params.lat - The latitude of the location.\n *\n * @returns {Promise<ReverseGeocodingResult>} A promise that resolves to the reverse geocoding result.\n *\n * @throws Will attempt to use an alternative geocoding service if the primary service fails.\n */\nconst reverseGeocoder = async ({\n lon,\n lat,\n}: {\n lon: number;\n lat: number;\n}): Promise<ReverseGeocodingResult> => {\n // first, get city code from open reverse geocoder(local)\n try {\n const result = await openReverseGeocoder([lon, lat]);\n return result;\n } catch (error) {\n // if failed, get city code from GSI\n console.log('Failed to get city code from open reverse geocoder');\n return gsiReverseGeocoder({ lat, lon });\n }\n};\n\nexport { reverseGeocoder, getElevation, getMuniMap as getCityMap };\n","import { geoContains } from 'd3-geo';\nimport axios, { AxiosInstance } from 'axios';\nimport { VectorTile } from 'mapbox-vector-tile';\nimport { ReverseGeocodingOptions, ReverseGeocodingResult } from './interfaces';\n\n/**\n * Get a tile from targeted country's tilesets by using x and y tile index\n * @param x x tile index\n * @param y y tile index\n * @param options ReverseGeocodingOptions\n * @param api Axios object\n * @returns VectorTile object\n */\nexport const getTile = async (\n x: number,\n y: number,\n options: ReverseGeocodingOptions,\n api: AxiosInstance = axios\n): Promise<VectorTile> => {\n const tileUrl = options.tileUrl\n .replace('{z}', String(options.zoomBase))\n .replace('{x}', String(x))\n .replace('{y}', String(y));\n\n let buffer;\n\n try {\n const res = await api.get(tileUrl, { responseType: 'arraybuffer' });\n buffer = Buffer.from(res.data, 'binary');\n } catch (error) {\n throw error;\n }\n\n const tile = new VectorTile(buffer);\n return tile;\n};\n\n/**\n * Get a result of reverse geocoding\n * @param tile VectorTile object\n * @param x x tile index\n * @param y y tile index\n * @param lnglat number[] longitude, latitude\n * @param options ReverseGeocodingOptions\n * @returns an object of result of reverse gecoding\n */\nexport const getTileResult = (\n tile: VectorTile,\n x: number,\n y: number,\n lnglat: [number, number],\n options: ReverseGeocodingOptions\n): ReverseGeocodingResult => {\n let layers = Object.keys(tile.layers);\n\n if (!Array.isArray(layers)) layers = [layers];\n\n let geocodingResult: ReverseGeocodingResult = {};\n layers.forEach((layerID) => {\n const layer = tile.layers[layerID];\n if (layer && options.layer === layer.name) {\n for (let i = 0; i < layer.length; i++) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const feature: any = layer.feature(i).toGeoJSON(x, y, options.zoomBase);\n if (layers.length > 1) feature.properties.vt_layer = layerID;\n\n const geojson = {\n type: 'FeatureCollection',\n features: [feature],\n };\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const res = geoContains(geojson as any, lnglat);\n if (res) {\n geocodingResult = options.getResult(feature);\n }\n }\n }\n });\n return geocodingResult;\n};\n\n"],"names":["countryOptions","JP","zoomBase","tileUrl","layer","getResult","feature","_feature$properties","_feature$properties2","code","String","id","length","prefecture","properties","city","DEFAULT","MuniRegex","getMuniMap","Promise","resolve","axios","get","responseType","timeout","then","response","muniMapObj","data","split","forEach","line","test","muniRecord","replace","muniRecordArray","Error","prefCode","prefName","cityCode","cityName","padStart","parseMuniRecord","_catch","error","console","log","e","reject","api","setupCache","create","ttl","interceptors","request","use","config","fullUrl","baseURL","url","URLSearchParams","params","toString","defaultOptions","getElevation","_ref2","lon","lat","elevation","parseFloat","longitude","latitude","reverseGeocoder","_ref3","lnglat","opt","_extends","openReverseGeocoder","_lngLatToGoogle","lngLatToGoogle","x","y","options","buffer","_temp2","_result","VectorTile","_temp","res","Buffer","from","getTile","tile","layers","Object","keys","Array","isArray","geocodingResult","layerID","name","i","toGeoJSON","vt_layer","geoContains","type","features","getTileResult","_ref","_result$results","results","muniCd","lv01Nm","gsiReverseGeocoder"],"mappings":"waAQA,IAAMA,EAA2D,CAC/DC,GAAI,CACFC,SAAU,GAEVC,QAAS,6EACTC,MAAO,kBACPC,UAAW,SAAUC,GAAwB,IAAAC,EAAAC,EAS3C,MARsC,CACpCC,KACE,IAAMC,OAAOJ,EAAQK,IAA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KAFgBoG,EAAZE,OAEEhG,KAFwB8F,EAAZG,OAEuB,EACpD,CAAC,MAAAjE,GAAA,OAAA5B,QAAA6B,OAAAD,EAAA,CAAA,CAqDUkE,CAAmB,CAAE9C,IAAAA,EAAKD,IAAAA,GAClC,GACH,CAAC,MAAAnB,GAAA,OAAA5B,QAAA6B,OAAAD,EAED,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.module.js","sources":["../src/countryOptions.ts","../src/muni.ts","../src/index.ts","../src/utils.ts"],"sourcesContent":["import {\n ReverseGeocodingOptions,\n ReverseGeocodingResultJP,\n} from './interfaces';\n\n/**\n * vector tiles settings for each country\n */\nconst countryOptions: { [s: string]: ReverseGeocodingOptions } = {\n JP: {\n zoomBase: 10,\n // tileUrl: `http://127.0.0.1:5500/docs/tiles/{z}/{x}/{y}.pbf`,\n tileUrl: 'https://skglobal-jsc.github.io/open-reverse-geocoder/tiles/{z}/{x}/{y}.pbf',\n layer: 'japanese-admins',\n getResult: function (feature: GeoJSON.Feature) {\n const res: ReverseGeocodingResultJP = {\n code:\n 5 === String(feature.id).length\n ? String(feature.id)\n : `0${String(feature.id)}`,\n prefecture: feature.properties?.prefecture,\n city: feature.properties?.city,\n };\n return res;\n },\n },\n};\n\n// default country options\ncountryOptions.DEFAULT = countryOptions.JP;\n\nexport default countryOptions;\n","// Muni file url\nconst MuniURL = 'https://maps.gsi.go.jp/js/muni.js';\nconst MuniRegex = /GSI\\.MUNI_ARRAY\\[\"\\d+\"\\]\\s*=\\s*'(.*?)';/g;\n\nimport axios from 'axios';\n\ninterface MuniRecord {\n prefCode: string;\n prefName: string;\n cityCode: string;\n cityName: string;\n}\n\ninterface MuniMap {\n [key: string]: MuniRecord;\n}\n\ninterface AddressResults {\n muniCd: string;\n lv01Nm: string;\n mesh_code?: string;\n notes?: string;\n}\n\n/**\n * parse muni.js\n * @param muniMap\n */\nconst parseMuniMap = (muniMap: string) => {\n const muniMapObj: MuniMap = {};\n const lines = muniMap.split('\\n');\n lines.forEach((line) => {\n if (MuniRegex.test(line)) {\n const muniRecord = parseMuniRecord(line);\n muniMapObj[muniRecord.cityCode] = muniRecord;\n }\n });\n return muniMapObj;\n};\n\n/**\n * parse muni record\n * @param line\n */\nconst parseMuniRecord = (line: string) => {\n const muniRecord = line.replace(MuniRegex, '$1');\n\n const muniRecordArray = muniRecord.split(',');\n\n // validate muni record\n if (muniRecordArray.length !== 4) {\n throw new Error(`invalid muni record: ${muniRecord}`);\n }\n\n let [prefCode, prefName, cityCode, cityName] = muniRecordArray;\n\n // if cityCode is not 5 digits, add 0 to the beginning\n cityCode = cityCode.padStart(5, '0');\n\n // if prefCode is not 2 digits, add 0 to the beginning\n prefCode = prefCode.padStart(2, '0');\n\n return {\n prefCode: prefCode,\n prefName: prefName,\n cityCode: cityCode,\n cityName: cityName,\n };\n};\n\n/**\n * Fetches the municipality map data from a specified URL.\n *\n * @returns {Promise<object>} A promise that resolves to the parsed municipality map data.\n *\n * @throws Will log an error message and return an empty object if the request fails.\n */\nconst getMuniMap = async () => {\n try {\n const response = await axios.get(MuniURL, {\n responseType: 'text',\n timeout: 500,\n });\n\n const muniMap = response.data;\n return parseMuniMap(muniMap);\n } catch (error) {\n console.log(`Failed to get muni map: ${error}`);\n return {};\n }\n};\n\n/**\n * converts muni code to address name.\n *\n * @param muniMap\n * @param muniCode\n */\nconst muniCodeToAddressName = (muniMap: MuniMap, muniCode: string) => {\n const muniRecord = muniMap[muniCode];\n if (!muniRecord) {\n throw new Error(`muni code ${muniCode} not found`);\n }\n\n const add = `${muniRecord.prefName}${muniRecord.cityName}`;\n return add.replace(/ /g, '');\n};\n\n/**\n * converts address result to address name.\n * @param muniMap\n * @param addressResults\n */\nconst addressResultsToAddressName = (\n muniMap: MuniMap,\n addressResults: AddressResults\n) => {\n const mc = addressResults.muniCd;\n const muniName = muniCodeToAddressName(muniMap, mc);\n const addrName = `${muniName}${addressResults.lv01Nm}`;\n return addrName;\n};\n\nconst getMuniMapLocations = async () => {\n const muniMap = await getMuniMap();\n // muniMap is a map of all cities and wards in Japan\n // key: city code, value: { prefCode, prefName, cityCode, cityName }\n // we need to convert this to a map of all locations in Japan\n // key: prefCode , value: { prefName, cities: { key: cityCode, value: { cityCode, cityName, wards: { key: wardCode, value: { wardCode, wardName } } } } }\n\n const muniMapLocations = {};\n Object.keys(muniMap).forEach((cityCode) => {\n const muniRecord = muniMap[cityCode];\n const { prefCode, prefName, cityName } = muniRecord;\n if (!muniMapLocations[prefCode]) {\n muniMapLocations[prefCode] = { prefName, cities: {} };\n }\n\n // if cityName contains ' ', it is a ward\n // otherwise, it is a city\n if (cityName.includes(' ')) {\n // ward name is after ' '\n const [name, wardName] = cityName.split(' ');\n // find city has the same name\n const city: any = Object.values(muniMap).find(\n (c: any) => c.cityName === name\n );\n if (!city) {\n console.log(`City ${name} not found in prefCode ${prefCode}`);\n } else {\n // add ward to city\n muniMapLocations[prefCode].cities[city.cityCode].wards[cityCode] = {\n prefCode,\n cityCode: cityCode,\n cityName: `${name}${wardName}`,\n bigCityFlag: '1',\n bigCityCode: city.cityCode,\n };\n }\n } else {\n muniMapLocations[prefCode].cities[cityCode] = {\n prefCode,\n cityCode,\n cityName,\n wards: {},\n };\n }\n });\n\n // assign bigCityFlag to each city\n Object.keys(muniMapLocations).forEach((prefCode) => {\n const pref = muniMapLocations[prefCode];\n Object.keys(pref.cities).forEach((cityCode) => {\n const city = pref.cities[cityCode];\n const isBigCity = Object.values(city.wards).length > 0;\n if (isBigCity) {\n city.bigCityFlag = '2';\n } else {\n // delete wards\n delete city.wards;\n // if city is tokyo then bigCityFlag is 3, otherwise 0\n if (city.prefCode === '13') {\n city.bigCityFlag = '3';\n } else {\n city.bigCityFlag = '0';\n }\n }\n });\n });\n\n return muniMapLocations;\n};\n\nexport { getMuniMap };\n","import { lngLatToGoogle } from 'global-mercator';\nimport axios from 'axios';\nimport { setupCache } from 'axios-cache-interceptor';\nimport {\n ReverseGeocodingOptions,\n ReverseGeocodingResult,\n ReverseGeocodingResultJP,\n} from './interfaces';\nimport countryOptions from './countryOptions';\nimport { getTile, getTileResult } from './utils';\n\nimport { getMuniMap } from './muni';\n\ntype LngLat = [number, number];\n\nconst api = setupCache(\n axios.create({\n timeout: 2000,\n }),\n {\n ttl: 60 * 60 * 24 * 1000, // 1 day\n }\n);\n\napi.interceptors.request.use((config) => {\n const fullUrl = `${config.baseURL}${config.url}?${new URLSearchParams(\n config.params\n ).toString()}`;\n console.log('Full URL:', fullUrl);\n return config;\n});\n\nconst defaultOptions = countryOptions.DEFAULT;\n\n/**\n * Performs reverse geocoding to obtain location information based on longitude and latitude.\n *\n * @param lnglat - The longitude and latitude coordinates.\n * @param options - Optional parameters for reverse geocoding.\n * @returns A promise that resolves to the reverse geocoding result.\n */\nconst openReverseGeocoder = async (\n lnglat: LngLat,\n options?: ReverseGeocodingOptions\n): Promise<ReverseGeocodingResult> => {\n const opt = { ...defaultOptions, ...options };\n const [x, y] = lngLatToGoogle(lnglat, opt.zoomBase);\n const tile = await getTile(x, y, opt, api);\n return getTileResult(tile, x, y, lnglat, opt);\n};\n\n/**\n * Performs reverse geocoding using the GSI (Geospatial Information Authority of Japan) API.\n * Given latitude and longitude coordinates, it returns the corresponding municipality code and city name.\n *\n * @param {Object} params - The parameters for the reverse geocoding request.\n * @param {number} params.lat - The latitude coordinate.\n * @param {number} params.lon - The longitude coordinate.\n * @returns {Promise<ReverseGeocodingResultJP>} A promise that resolves to an object containing the municipality code and city name.\n *\n * @example\n * const result = await gsiReverseGeocoder({ lat: 35.6895, lon: 139.6917 });\n * console.log(result); // { code: '13101', city: 'Chiyoda-ku' }\n */\nconst gsiReverseGeocoder = async ({\n lat,\n lon,\n}: {\n lat: number;\n lon: number;\n}) => {\n const response = await api.get(\n 'https://mreversegeocoder.gsi.go.jp/reverse-geocoder/LonLatToAddress',\n {\n responseType: 'json',\n params: {\n lat,\n lon,\n },\n }\n );\n const result = response.data;\n const {\n results: { muniCd: code, lv01Nm: city },\n } = result;\n return { code, city } as ReverseGeocodingResultJP;\n};\n\n/**\n * Retrieves the elevation for a given longitude and latitude using the GSI API.\n *\n * @param {Object} coordinates - The coordinates for which to get the elevation.\n * @param {number} coordinates.lon - The longitude of the location.\n * @param {number} coordinates.lat - The latitude of the location.\n * @returns {Promise<{ longitude: number, latitude: number, elevation: number }>}\n * A promise that resolves to an object containing the longitude, latitude, and elevation.\n */\nconst getElevation = async ({ lon, lat }: { lon: number; lat: number }) => {\n // first, get elevation from GSI\n const response = await api.get(\n 'https://mreversegeocoder.gsi.go.jp/general/dem/scripts/getelevation.php',\n {\n responseType: 'json',\n params: {\n lat,\n lon,\n },\n }\n );\n\n const elevation = parseFloat(response.data.elevation);\n return { longitude: lon, latitude: lat, elevation };\n};\n\n/**\n * Reverse geocodes the given longitude and latitude to obtain a city code.\n *\n * @param {Object} params - The parameters for reverse geocoding.\n * @param {number} params.lon - The longitude of the location.\n * @param {number} params.lat - The latitude of the location.\n *\n * @returns {Promise<ReverseGeocodingResult>} A promise that resolves to the reverse geocoding result.\n *\n * @throws Will attempt to use an alternative geocoding service if the primary service fails.\n */\nconst reverseGeocoder = async ({\n lon,\n lat,\n}: {\n lon: number;\n lat: number;\n}): Promise<ReverseGeocodingResult> => {\n // first, get city code from open reverse geocoder(local)\n try {\n const result = await openReverseGeocoder([lon, lat]);\n return result;\n } catch (error) {\n // if failed, get city code from GSI\n console.log('Failed to get city code from open reverse geocoder');\n return gsiReverseGeocoder({ lat, lon });\n }\n};\n\nexport { reverseGeocoder, getElevation, getMuniMap as getCityMap };\n","// import { geoContains } from 'd3-geo';\nimport axios, { AxiosInstance } from 'axios';\nimport { VectorTile } from 'mapbox-vector-tile';\nimport { ReverseGeocodingOptions, ReverseGeocodingResult } from './interfaces';\n\n/**\n * Get a tile from targeted country's tilesets by using x and y tile index\n * @param x x tile index\n * @param y y tile index\n * @param options ReverseGeocodingOptions\n * @param api Axios object\n * @returns VectorTile object\n */\nexport const getTile = async (\n x: number,\n y: number,\n options: ReverseGeocodingOptions,\n api: AxiosInstance = axios\n): Promise<VectorTile> => {\n const tileUrl = options.tileUrl\n .replace('{z}', String(options.zoomBase))\n .replace('{x}', String(x))\n .replace('{y}', String(y));\n\n let buffer;\n\n try {\n const res = await api.get(tileUrl, { responseType: 'arraybuffer' });\n buffer = Buffer.from(res.data, 'binary');\n } catch (error) {\n throw error;\n }\n\n const tile = new VectorTile(buffer);\n return tile;\n};\n\n/**\n * Get a result of reverse geocoding\n * @param tile VectorTile object\n * @param x x tile index\n * @param y y tile index\n * @param lnglat number[] longitude, latitude\n * @param options ReverseGeocodingOptions\n * @returns an object of result of reverse gecoding\n */\nexport const getTileResult = (\n tile: VectorTile,\n x: number,\n y: number,\n lnglat: [number, number],\n options: ReverseGeocodingOptions\n): ReverseGeocodingResult => {\n let layers = Object.keys(tile.layers);\n\n if (!Array.isArray(layers)) layers = [layers];\n\n let geocodingResult: ReverseGeocodingResult = {};\n layers.forEach((layerID) => {\n const layer = tile.layers[layerID];\n if (layer && options.layer === layer.name) {\n for (let i = 0; i < layer.length; i++) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const feature: any = layer.feature(i).toGeoJSON(x, y, options.zoomBase);\n if (layers.length > 1) feature.properties.vt_layer = layerID;\n\n const geojson = {\n type: 'FeatureCollection',\n features: [feature],\n };\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n // const res = geoContains(geojson as any, lnglat);\n // if (res) {\n // geocodingResult = options.getResult(feature);\n // }\n }\n }\n });\n return geocodingResult;\n};\n\n"],"names":["countryOptions","JP","zoomBase","tileUrl","layer","getResult","feature","_feature$properties","_feature$properties2","code","String","id","length","prefecture","properties","city","DEFAULT","MuniRegex","getMuniMap","Promise","resolve","axios","get","responseType","timeout","then","response","muniMapObj","data","split","forEach","line","test","muniRecord","replace","muniRecordArray","Error","prefCode","prefName","cityCode","cityName","padStart","parseMuniRecord","_catch","error","console","log","e","reject","api","setupCache","create","ttl","interceptors","request","use","config","fullUrl","baseURL","url","URLSearchParams","params","toString","defaultOptions","getElevation","_ref2","lon","lat","elevation","parseFloat","longitude","latitude","reverseGeocoder","_ref3","lnglat","opt","_extends","openReverseGeocoder","_lngLatToGoogle","lngLatToGoogle","x","y","options","buffer","_temp2","_result","VectorTile","_temp","res","Buffer","from","getTile","tile","layers","Object","keys","Array","isArray","layerID","name","i","toGeoJSON","vt_layer","getTileResult","_ref","_result$results","results","muniCd","lv01Nm","gsiReverseGeocoder"],"mappings":"mYAQA,IAAMA,EAA2D,CAC/DC,GAAI,CACFC,SAAU,GAEVC,QAAS,6EACTC,MAAO,kBACPC,UAAW,SAAUC,GAAwB,IAAAC,EAAAC,EAS3C,MARsC,CACpCC,KACE,IAAMC,OAAOJ,EAAQK,IAAIC,OACrBF,OAAOJ,EAAQK,QACXD,OAAOJ,EAAQK,IACzBE,WAAYN,OAAFA,EAAED,EAAQQ,iBAARP,EAAAA,EAAoBM,WAChCE,KAAMP,OAAFA,EAAEF,EAAQQ,iBAARN,EAAAA,EAAoBO,KAG9B,IAKJf,EAAegB,QAAUhB,EAAeC,GC5BxC,IACMgB,EAAY,2CA2EZC,EAAA,WAAU,WAAcC,QAAAC,gCACxBD,QAAAC,QACqBC,EAAMC,IA9EjB,oCA8E8B,CACxCC,aAAc,OACdC,QAAS,OACTC,KAAA,SAHIC,GAMN,OAxDIC,EAAsB,CAAE,EAuDZD,EAASE,KAtDLC,MAAM,MACtBC,QAAQ,SAACC,GACb,GAAId,EAAUe,KAAKD,GAAO,CACxB,IAAME,EAWY,SAACF,GACvB,IAAME,EAAaF,EAAKG,QAAQjB,EAAW,MAErCkB,EAAkBF,EAAWJ,MAAM,KAGzC,GAA+B,IAA3BM,EAAgBvB,OAClB,UAAUwB,8BAA8BH,GAG1C,IAAKI,EAA0CF,EAAe,GAA/CG,EAAgCH,KAAtBI,EAAsBJ,EAAZK,GAAAA,EAAYL,EAAe,GAQ9D,OALAI,EAAWA,EAASE,SAAS,EAAG,KAKzB,CACLJ,SAHFA,EAAWA,EAASI,SAA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B,CAACX,EAAKC,6DAHbxB,CAAA,EAKnC,WAGC,OADAE,QAAQC,IAAI,sDA1EV,SAAkB0D,GACtB,IAAArC,EAAGqC,EAAHrC,IACAD,EAAGsC,EAAHtC,IAAG,IAIA/C,OAAAA,QAAAC,QACoB6B,EAAI3B,IACzB,sEACA,CACEC,aAAc,OACdsC,OAAQ,CACNM,IAAAA,EACAD,IAAAA,MAGLzC,KAAA,SATKC,GAUN,IACA+E,EADe/E,EAASE,KAEtB8E,QAEF,MAAO,CAAEjG,KAFgBgG,EAAZE,OAEE5F,KAFwB0F,EAAZG,OAEuB,EACpD,CAAC,MAAA7D,GAAA,OAAA5B,QAAA6B,OAAAD,EAAA,CAAA,CAqDU8D,CAAmB,CAAE1C,IAAAA,EAAKD,IAAAA,GAClC,GACH,CAAC,MAAAnB,GAAA,OAAA5B,QAAA6B,OAAAD,EAED,CAAA"}
|
package/dist/index.umd.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("global-mercator"),require("axios"),require("axios-cache-interceptor"),require("
|
|
1
|
+
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("global-mercator"),require("axios"),require("axios-cache-interceptor"),require("mapbox-vector-tile")):"function"==typeof define&&define.amd?define(["exports","global-mercator","axios","axios-cache-interceptor","mapbox-vector-tile"],r):r((e||self).jsMsearchGsiJp={},e.globalMercator,e.axios,e.axiosCacheInterceptor,e.mapboxVectorTile)}(this,function(e,r,t,o,n){function a(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var i=/*#__PURE__*/a(t);function s(){return s=Object.assign?Object.assign.bind():function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var o in t)({}).hasOwnProperty.call(t,o)&&(e[o]=t[o])}return e},s.apply(null,arguments)}var c={JP:{zoomBase:10,tileUrl:"https://skglobal-jsc.github.io/open-reverse-geocoder/tiles/{z}/{x}/{y}.pbf",layer:"japanese-admins",getResult:function(e){var r,t;return{code:5===String(e.id).length?String(e.id):"0"+String(e.id),prefecture:null==(r=e.properties)?void 0:r.prefecture,city:null==(t=e.properties)?void 0:t.city}}}};c.DEFAULT=c.JP;var l=/GSI\.MUNI_ARRAY\["\d+"\]\s*=\s*'(.*?)';/g,u=o.setupCache(i.default.create({timeout:2e3}),{ttl:864e5});u.interceptors.request.use(function(e){var r=""+e.baseURL+e.url+"?"+new URLSearchParams(e.params).toString();return console.log("Full URL:",r),e});var p=c.DEFAULT;e.getCityMap=function(){try{return Promise.resolve(function(e,r){try{var t=Promise.resolve(i.default.get("https://maps.gsi.go.jp/js/muni.js",{responseType:"text",timeout:500})).then(function(e){return r={},e.data.split("\n").forEach(function(e){if(l.test(e)){var t=function(e){var r=e.replace(l,"$1"),t=r.split(",");if(4!==t.length)throw new Error("invalid muni record: "+r);var o=t[0],n=t[1],a=t[2],i=t[3];return a=a.padStart(5,"0"),{prefCode:o=o.padStart(2,"0"),prefName:n,cityCode:a,cityName:i}}(e);r[t.cityCode]=t}}),r;var r})}catch(e){return r(e)}return t&&t.then?t.then(void 0,r):t}(0,function(e){return console.log("Failed to get muni map: "+e),{}}))}catch(e){return Promise.reject(e)}},e.getElevation=function(e){var r=e.lon,t=e.lat;try{return Promise.resolve(u.get("https://mreversegeocoder.gsi.go.jp/general/dem/scripts/getelevation.php",{responseType:"json",params:{lat:t,lon:r}})).then(function(e){var o=parseFloat(e.data.elevation);return{longitude:r,latitude:t,elevation:o}})}catch(e){return Promise.reject(e)}},e.reverseGeocoder=function(e){var t=e.lon,o=e.lat;try{return Promise.resolve(function(e,a){try{var c=Promise.resolve(function(e){try{var t=s({},p,void 0),o=r.lngLatToGoogle(e,t.zoomBase),a=o[0],c=o[1];return Promise.resolve(function(e,r,t,o){void 0===o&&(o=i.default);try{var a,s=function(e){return new n.VectorTile(a)},c=t.tileUrl.replace("{z}",String(t.zoomBase)).replace("{x}",String(e)).replace("{y}",String(r)),l=function(e,r){try{var t=Promise.resolve(o.get(c,{responseType:"arraybuffer"})).then(function(e){a=Buffer.from(e.data,"binary")})}catch(e){return r(e)}return t&&t.then?t.then(void 0,r):t}(0,function(e){throw e});return Promise.resolve(l&&l.then?l.then(s):s())}catch(e){return Promise.reject(e)}}(a,c,t,u)).then(function(e){return function(e,r,t,o,n){var a=Object.keys(e.layers);return Array.isArray(a)||(a=[a]),a.forEach(function(o){var i=e.layers[o];if(i&&n.layer===i.name)for(var s=0;s<i.length;s++){var c=i.feature(s).toGeoJSON(r,t,n.zoomBase);a.length>1&&(c.properties.vt_layer=o)}}),{}}(e,a,c,0,t)})}catch(e){return Promise.reject(e)}}([t,o]))}catch(e){return a()}return c&&c.then?c.then(void 0,a):c}(0,function(){return console.log("Failed to get city code from open reverse geocoder"),function(e){var r=e.lat,t=e.lon;try{return Promise.resolve(u.get("https://mreversegeocoder.gsi.go.jp/reverse-geocoder/LonLatToAddress",{responseType:"json",params:{lat:r,lon:t}})).then(function(e){var r=e.data.results;return{code:r.muniCd,city:r.lv01Nm}})}catch(e){return Promise.reject(e)}}({lat:o,lon:t})}))}catch(e){return Promise.reject(e)}}});
|
|
2
2
|
//# sourceMappingURL=index.umd.js.map
|
package/dist/index.umd.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.umd.js","sources":["../src/countryOptions.ts","../src/muni.ts","../src/index.ts","../src/utils.ts"],"sourcesContent":["import {\n ReverseGeocodingOptions,\n ReverseGeocodingResultJP,\n} from './interfaces';\n\n/**\n * vector tiles settings for each country\n */\nconst countryOptions: { [s: string]: ReverseGeocodingOptions } = {\n JP: {\n zoomBase: 10,\n // tileUrl: `http://127.0.0.1:5500/docs/tiles/{z}/{x}/{y}.pbf`,\n tileUrl: 'https://skglobal-jsc.github.io/open-reverse-geocoder/tiles/{z}/{x}/{y}.pbf',\n layer: 'japanese-admins',\n getResult: function (feature: GeoJSON.Feature) {\n const res: ReverseGeocodingResultJP = {\n code:\n 5 === String(feature.id).length\n ? String(feature.id)\n : `0${String(feature.id)}`,\n prefecture: feature.properties?.prefecture,\n city: feature.properties?.city,\n };\n return res;\n },\n },\n};\n\n// default country options\ncountryOptions.DEFAULT = countryOptions.JP;\n\nexport default countryOptions;\n","// Muni file url\nconst MuniURL = 'https://maps.gsi.go.jp/js/muni.js';\nconst MuniRegex = /GSI\\.MUNI_ARRAY\\[\"\\d+\"\\]\\s*=\\s*'(.*?)';/g;\n\nimport axios from 'axios';\n\ninterface MuniRecord {\n prefCode: string;\n prefName: string;\n cityCode: string;\n cityName: string;\n}\n\ninterface MuniMap {\n [key: string]: MuniRecord;\n}\n\ninterface AddressResults {\n muniCd: string;\n lv01Nm: string;\n mesh_code?: string;\n notes?: string;\n}\n\n/**\n * parse muni.js\n * @param muniMap\n */\nconst parseMuniMap = (muniMap: string) => {\n const muniMapObj: MuniMap = {};\n const lines = muniMap.split('\\n');\n lines.forEach((line) => {\n if (MuniRegex.test(line)) {\n const muniRecord = parseMuniRecord(line);\n muniMapObj[muniRecord.cityCode] = muniRecord;\n }\n });\n return muniMapObj;\n};\n\n/**\n * parse muni record\n * @param line\n */\nconst parseMuniRecord = (line: string) => {\n const muniRecord = line.replace(MuniRegex, '$1');\n\n const muniRecordArray = muniRecord.split(',');\n\n // validate muni record\n if (muniRecordArray.length !== 4) {\n throw new Error(`invalid muni record: ${muniRecord}`);\n }\n\n let [prefCode, prefName, cityCode, cityName] = muniRecordArray;\n\n // if cityCode is not 5 digits, add 0 to the beginning\n cityCode = cityCode.padStart(5, '0');\n\n // if prefCode is not 2 digits, add 0 to the beginning\n prefCode = prefCode.padStart(2, '0');\n\n return {\n prefCode: prefCode,\n prefName: prefName,\n cityCode: cityCode,\n cityName: cityName,\n };\n};\n\n/**\n * Fetches the municipality map data from a specified URL.\n *\n * @returns {Promise<object>} A promise that resolves to the parsed municipality map data.\n *\n * @throws Will log an error message and return an empty object if the request fails.\n */\nconst getMuniMap = async () => {\n try {\n const response = await axios.get(MuniURL, {\n responseType: 'text',\n timeout: 500,\n });\n\n const muniMap = response.data;\n return parseMuniMap(muniMap);\n } catch (error) {\n console.log(`Failed to get muni map: ${error}`);\n return {};\n }\n};\n\n/**\n * converts muni code to address name.\n *\n * @param muniMap\n * @param muniCode\n */\nconst muniCodeToAddressName = (muniMap: MuniMap, muniCode: string) => {\n const muniRecord = muniMap[muniCode];\n if (!muniRecord) {\n throw new Error(`muni code ${muniCode} not found`);\n }\n\n const add = `${muniRecord.prefName}${muniRecord.cityName}`;\n return add.replace(/ /g, '');\n};\n\n/**\n * converts address result to address name.\n * @param muniMap\n * @param addressResults\n */\nconst addressResultsToAddressName = (\n muniMap: MuniMap,\n addressResults: AddressResults\n) => {\n const mc = addressResults.muniCd;\n const muniName = muniCodeToAddressName(muniMap, mc);\n const addrName = `${muniName}${addressResults.lv01Nm}`;\n return addrName;\n};\n\nconst getMuniMapLocations = async () => {\n const muniMap = await getMuniMap();\n // muniMap is a map of all cities and wards in Japan\n // key: city code, value: { prefCode, prefName, cityCode, cityName }\n // we need to convert this to a map of all locations in Japan\n // key: prefCode , value: { prefName, cities: { key: cityCode, value: { cityCode, cityName, wards: { key: wardCode, value: { wardCode, wardName } } } } }\n\n const muniMapLocations = {};\n Object.keys(muniMap).forEach((cityCode) => {\n const muniRecord = muniMap[cityCode];\n const { prefCode, prefName, cityName } = muniRecord;\n if (!muniMapLocations[prefCode]) {\n muniMapLocations[prefCode] = { prefName, cities: {} };\n }\n\n // if cityName contains ' ', it is a ward\n // otherwise, it is a city\n if (cityName.includes(' ')) {\n // ward name is after ' '\n const [name, wardName] = cityName.split(' ');\n // find city has the same name\n const city: any = Object.values(muniMap).find(\n (c: any) => c.cityName === name\n );\n if (!city) {\n console.log(`City ${name} not found in prefCode ${prefCode}`);\n } else {\n // add ward to city\n muniMapLocations[prefCode].cities[city.cityCode].wards[cityCode] = {\n prefCode,\n cityCode: cityCode,\n cityName: `${name}${wardName}`,\n bigCityFlag: '1',\n bigCityCode: city.cityCode,\n };\n }\n } else {\n muniMapLocations[prefCode].cities[cityCode] = {\n prefCode,\n cityCode,\n cityName,\n wards: {},\n };\n }\n });\n\n // assign bigCityFlag to each city\n Object.keys(muniMapLocations).forEach((prefCode) => {\n const pref = muniMapLocations[prefCode];\n Object.keys(pref.cities).forEach((cityCode) => {\n const city = pref.cities[cityCode];\n const isBigCity = Object.values(city.wards).length > 0;\n if (isBigCity) {\n city.bigCityFlag = '2';\n } else {\n // delete wards\n delete city.wards;\n // if city is tokyo then bigCityFlag is 3, otherwise 0\n if (city.prefCode === '13') {\n city.bigCityFlag = '3';\n } else {\n city.bigCityFlag = '0';\n }\n }\n });\n });\n\n return muniMapLocations;\n};\n\nexport { getMuniMap };\n","import { lngLatToGoogle } from 'global-mercator';\nimport axios from 'axios';\nimport { setupCache } from 'axios-cache-interceptor';\nimport {\n ReverseGeocodingOptions,\n ReverseGeocodingResult,\n ReverseGeocodingResultJP,\n} from './interfaces';\nimport countryOptions from './countryOptions';\nimport { getTile, getTileResult } from './utils';\n\nimport { getMuniMap } from './muni';\n\ntype LngLat = [number, number];\n\nconst api = setupCache(\n axios.create({\n timeout: 2000,\n }),\n {\n ttl: 60 * 60 * 24 * 1000, // 1 day\n }\n);\n\napi.interceptors.request.use((config) => {\n const fullUrl = `${config.baseURL}${config.url}?${new URLSearchParams(\n config.params\n ).toString()}`;\n console.log('Full URL:', fullUrl);\n return config;\n});\n\nconst defaultOptions = countryOptions.DEFAULT;\n\n/**\n * Performs reverse geocoding to obtain location information based on longitude and latitude.\n *\n * @param lnglat - The longitude and latitude coordinates.\n * @param options - Optional parameters for reverse geocoding.\n * @returns A promise that resolves to the reverse geocoding result.\n */\nconst openReverseGeocoder = async (\n lnglat: LngLat,\n options?: ReverseGeocodingOptions\n): Promise<ReverseGeocodingResult> => {\n const opt = { ...defaultOptions, ...options };\n const [x, y] = lngLatToGoogle(lnglat, opt.zoomBase);\n const tile = await getTile(x, y, opt, api);\n return getTileResult(tile, x, y, lnglat, opt);\n};\n\n/**\n * Performs reverse geocoding using the GSI (Geospatial Information Authority of Japan) API.\n * Given latitude and longitude coordinates, it returns the corresponding municipality code and city name.\n *\n * @param {Object} params - The parameters for the reverse geocoding request.\n * @param {number} params.lat - The latitude coordinate.\n * @param {number} params.lon - The longitude coordinate.\n * @returns {Promise<ReverseGeocodingResultJP>} A promise that resolves to an object containing the municipality code and city name.\n *\n * @example\n * const result = await gsiReverseGeocoder({ lat: 35.6895, lon: 139.6917 });\n * console.log(result); // { code: '13101', city: 'Chiyoda-ku' }\n */\nconst gsiReverseGeocoder = async ({\n lat,\n lon,\n}: {\n lat: number;\n lon: number;\n}) => {\n const response = await api.get(\n 'https://mreversegeocoder.gsi.go.jp/reverse-geocoder/LonLatToAddress',\n {\n responseType: 'json',\n params: {\n lat,\n lon,\n },\n }\n );\n const result = response.data;\n const {\n results: { muniCd: code, lv01Nm: city },\n } = result;\n return { code, city } as ReverseGeocodingResultJP;\n};\n\n/**\n * Retrieves the elevation for a given longitude and latitude using the GSI API.\n *\n * @param {Object} coordinates - The coordinates for which to get the elevation.\n * @param {number} coordinates.lon - The longitude of the location.\n * @param {number} coordinates.lat - The latitude of the location.\n * @returns {Promise<{ longitude: number, latitude: number, elevation: number }>}\n * A promise that resolves to an object containing the longitude, latitude, and elevation.\n */\nconst getElevation = async ({ lon, lat }: { lon: number; lat: number }) => {\n // first, get elevation from GSI\n const response = await api.get(\n 'https://mreversegeocoder.gsi.go.jp/general/dem/scripts/getelevation.php',\n {\n responseType: 'json',\n params: {\n lat,\n lon,\n },\n }\n );\n\n const elevation = parseFloat(response.data.elevation);\n return { longitude: lon, latitude: lat, elevation };\n};\n\n/**\n * Reverse geocodes the given longitude and latitude to obtain a city code.\n *\n * @param {Object} params - The parameters for reverse geocoding.\n * @param {number} params.lon - The longitude of the location.\n * @param {number} params.lat - The latitude of the location.\n *\n * @returns {Promise<ReverseGeocodingResult>} A promise that resolves to the reverse geocoding result.\n *\n * @throws Will attempt to use an alternative geocoding service if the primary service fails.\n */\nconst reverseGeocoder = async ({\n lon,\n lat,\n}: {\n lon: number;\n lat: number;\n}): Promise<ReverseGeocodingResult> => {\n // first, get city code from open reverse geocoder(local)\n try {\n const result = await openReverseGeocoder([lon, lat]);\n return result;\n } catch (error) {\n // if failed, get city code from GSI\n console.log('Failed to get city code from open reverse geocoder');\n return gsiReverseGeocoder({ lat, lon });\n }\n};\n\nexport { reverseGeocoder, getElevation, getMuniMap as getCityMap };\n","import { geoContains } from 'd3-geo';\nimport axios, { AxiosInstance } from 'axios';\nimport { VectorTile } from 'mapbox-vector-tile';\nimport { ReverseGeocodingOptions, ReverseGeocodingResult } from './interfaces';\n\n/**\n * Get a tile from targeted country's tilesets by using x and y tile index\n * @param x x tile index\n * @param y y tile index\n * @param options ReverseGeocodingOptions\n * @param api Axios object\n * @returns VectorTile object\n */\nexport const getTile = async (\n x: number,\n y: number,\n options: ReverseGeocodingOptions,\n api: AxiosInstance = axios\n): Promise<VectorTile> => {\n const tileUrl = options.tileUrl\n .replace('{z}', String(options.zoomBase))\n .replace('{x}', String(x))\n .replace('{y}', String(y));\n\n let buffer;\n\n try {\n const res = await api.get(tileUrl, { responseType: 'arraybuffer' });\n buffer = Buffer.from(res.data, 'binary');\n } catch (error) {\n throw error;\n }\n\n const tile = new VectorTile(buffer);\n return tile;\n};\n\n/**\n * Get a result of reverse geocoding\n * @param tile VectorTile object\n * @param x x tile index\n * @param y y tile index\n * @param lnglat number[] longitude, latitude\n * @param options ReverseGeocodingOptions\n * @returns an object of result of reverse gecoding\n */\nexport const getTileResult = (\n tile: VectorTile,\n x: number,\n y: number,\n lnglat: [number, number],\n options: ReverseGeocodingOptions\n): ReverseGeocodingResult => {\n let layers = Object.keys(tile.layers);\n\n if (!Array.isArray(layers)) layers = [layers];\n\n let geocodingResult: ReverseGeocodingResult = {};\n layers.forEach((layerID) => {\n const layer = tile.layers[layerID];\n if (layer && options.layer === layer.name) {\n for (let i = 0; i < layer.length; i++) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const feature: any = layer.feature(i).toGeoJSON(x, y, options.zoomBase);\n if (layers.length > 1) feature.properties.vt_layer = layerID;\n\n const geojson = {\n type: 'FeatureCollection',\n features: [feature],\n };\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const res = geoContains(geojson as any, lnglat);\n if (res) {\n geocodingResult = options.getResult(feature);\n }\n }\n }\n });\n return geocodingResult;\n};\n\n"],"names":["countryOptions","JP","zoomBase","tileUrl","layer","getResult","feature","_feature$properties","_feature$properties2","code","String","id","length","prefecture","properties","city","DEFAULT","MuniRegex","api","setupCache","axios","create","timeout","ttl","interceptors","request","use","config","fullUrl","baseURL","url","URLSearchParams","params","toString","console","log","defaultOptions","Promise","resolve","get","responseType","then","response","muniMapObj","data","split","forEach","line","test","muniRecord","replace","muniRecordArray","Error","prefCode","prefName","cityCode","cityName","padStart","parseMuniRecord","_catch","error","e","reject","_ref2","lon","lat","elevation","parseFloat","longitude","latitude","_ref3","lnglat","opt","_extends","openReverseGeocoder","_lngLatToGoogle","lngLatToGoogle","x","y","options","buffer","_temp2","_result","VectorTile","_temp","res","Buffer","from","getTile","tile","layers","Object","keys","Array","isArray","geocodingResult","layerID","name","i","toGeoJSON","vt_layer","geoContains","type","features","getTileResult","_ref","_result$results","results","muniCd","lv01Nm","gsiReverseGeocoder"],"mappings":"u0BAQA,IAAMA,EAA2D,CAC/DC,GAAI,CACFC,SAAU,GAEVC,QAAS,6EACTC,MAAO,kBACPC,UAAW,SAAUC,GAAwB,IAAAC,EAAAC,EAS3C,MARsC,CACpCC,KACE,IAAMC,OAAOJ,EAAQK,IAAIC,OACrBF,OAAOJ,EAAQK,QACXD,OAAOJ,EAAQK,IACzBE,WAAYN,OAAFA,EAAED,EAAQQ,iBAARP,EAAAA,EAAoBM,WAChCE,KAAMP,OAAFA,EAAEF,EAAQQ,iBAARN,EAAAA,EAAoBO,KAG9B,IAKJf,EAAegB,QAAUhB,EAAeC,GC5BxC,IACMgB,EAAY,2CCaZC,EAAMC,E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D,EAED,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.umd.js","sources":["../src/countryOptions.ts","../src/muni.ts","../src/index.ts","../src/utils.ts"],"sourcesContent":["import {\n ReverseGeocodingOptions,\n ReverseGeocodingResultJP,\n} from './interfaces';\n\n/**\n * vector tiles settings for each country\n */\nconst countryOptions: { [s: string]: ReverseGeocodingOptions } = {\n JP: {\n zoomBase: 10,\n // tileUrl: `http://127.0.0.1:5500/docs/tiles/{z}/{x}/{y}.pbf`,\n tileUrl: 'https://skglobal-jsc.github.io/open-reverse-geocoder/tiles/{z}/{x}/{y}.pbf',\n layer: 'japanese-admins',\n getResult: function (feature: GeoJSON.Feature) {\n const res: ReverseGeocodingResultJP = {\n code:\n 5 === String(feature.id).length\n ? String(feature.id)\n : `0${String(feature.id)}`,\n prefecture: feature.properties?.prefecture,\n city: feature.properties?.city,\n };\n return res;\n },\n },\n};\n\n// default country options\ncountryOptions.DEFAULT = countryOptions.JP;\n\nexport default countryOptions;\n","// Muni file url\nconst MuniURL = 'https://maps.gsi.go.jp/js/muni.js';\nconst MuniRegex = /GSI\\.MUNI_ARRAY\\[\"\\d+\"\\]\\s*=\\s*'(.*?)';/g;\n\nimport axios from 'axios';\n\ninterface MuniRecord {\n prefCode: string;\n prefName: string;\n cityCode: string;\n cityName: string;\n}\n\ninterface MuniMap {\n [key: string]: MuniRecord;\n}\n\ninterface AddressResults {\n muniCd: string;\n lv01Nm: string;\n mesh_code?: string;\n notes?: string;\n}\n\n/**\n * parse muni.js\n * @param muniMap\n */\nconst parseMuniMap = (muniMap: string) => {\n const muniMapObj: MuniMap = {};\n const lines = muniMap.split('\\n');\n lines.forEach((line) => {\n if (MuniRegex.test(line)) {\n const muniRecord = parseMuniRecord(line);\n muniMapObj[muniRecord.cityCode] = muniRecord;\n }\n });\n return muniMapObj;\n};\n\n/**\n * parse muni record\n * @param line\n */\nconst parseMuniRecord = (line: string) => {\n const muniRecord = line.replace(MuniRegex, '$1');\n\n const muniRecordArray = muniRecord.split(',');\n\n // validate muni record\n if (muniRecordArray.length !== 4) {\n throw new Error(`invalid muni record: ${muniRecord}`);\n }\n\n let [prefCode, prefName, cityCode, cityName] = muniRecordArray;\n\n // if cityCode is not 5 digits, add 0 to the beginning\n cityCode = cityCode.padStart(5, '0');\n\n // if prefCode is not 2 digits, add 0 to the beginning\n prefCode = prefCode.padStart(2, '0');\n\n return {\n prefCode: prefCode,\n prefName: prefName,\n cityCode: cityCode,\n cityName: cityName,\n };\n};\n\n/**\n * Fetches the municipality map data from a specified URL.\n *\n * @returns {Promise<object>} A promise that resolves to the parsed municipality map data.\n *\n * @throws Will log an error message and return an empty object if the request fails.\n */\nconst getMuniMap = async () => {\n try {\n const response = await axios.get(MuniURL, {\n responseType: 'text',\n timeout: 500,\n });\n\n const muniMap = response.data;\n return parseMuniMap(muniMap);\n } catch (error) {\n console.log(`Failed to get muni map: ${error}`);\n return {};\n }\n};\n\n/**\n * converts muni code to address name.\n *\n * @param muniMap\n * @param muniCode\n */\nconst muniCodeToAddressName = (muniMap: MuniMap, muniCode: string) => {\n const muniRecord = muniMap[muniCode];\n if (!muniRecord) {\n throw new Error(`muni code ${muniCode} not found`);\n }\n\n const add = `${muniRecord.prefName}${muniRecord.cityName}`;\n return add.replace(/ /g, '');\n};\n\n/**\n * converts address result to address name.\n * @param muniMap\n * @param addressResults\n */\nconst addressResultsToAddressName = (\n muniMap: MuniMap,\n addressResults: AddressResults\n) => {\n const mc = addressResults.muniCd;\n const muniName = muniCodeToAddressName(muniMap, mc);\n const addrName = `${muniName}${addressResults.lv01Nm}`;\n return addrName;\n};\n\nconst getMuniMapLocations = async () => {\n const muniMap = await getMuniMap();\n // muniMap is a map of all cities and wards in Japan\n // key: city code, value: { prefCode, prefName, cityCode, cityName }\n // we need to convert this to a map of all locations in Japan\n // key: prefCode , value: { prefName, cities: { key: cityCode, value: { cityCode, cityName, wards: { key: wardCode, value: { wardCode, wardName } } } } }\n\n const muniMapLocations = {};\n Object.keys(muniMap).forEach((cityCode) => {\n const muniRecord = muniMap[cityCode];\n const { prefCode, prefName, cityName } = muniRecord;\n if (!muniMapLocations[prefCode]) {\n muniMapLocations[prefCode] = { prefName, cities: {} };\n }\n\n // if cityName contains ' ', it is a ward\n // otherwise, it is a city\n if (cityName.includes(' ')) {\n // ward name is after ' '\n const [name, wardName] = cityName.split(' ');\n // find city has the same name\n const city: any = Object.values(muniMap).find(\n (c: any) => c.cityName === name\n );\n if (!city) {\n console.log(`City ${name} not found in prefCode ${prefCode}`);\n } else {\n // add ward to city\n muniMapLocations[prefCode].cities[city.cityCode].wards[cityCode] = {\n prefCode,\n cityCode: cityCode,\n cityName: `${name}${wardName}`,\n bigCityFlag: '1',\n bigCityCode: city.cityCode,\n };\n }\n } else {\n muniMapLocations[prefCode].cities[cityCode] = {\n prefCode,\n cityCode,\n cityName,\n wards: {},\n };\n }\n });\n\n // assign bigCityFlag to each city\n Object.keys(muniMapLocations).forEach((prefCode) => {\n const pref = muniMapLocations[prefCode];\n Object.keys(pref.cities).forEach((cityCode) => {\n const city = pref.cities[cityCode];\n const isBigCity = Object.values(city.wards).length > 0;\n if (isBigCity) {\n city.bigCityFlag = '2';\n } else {\n // delete wards\n delete city.wards;\n // if city is tokyo then bigCityFlag is 3, otherwise 0\n if (city.prefCode === '13') {\n city.bigCityFlag = '3';\n } else {\n city.bigCityFlag = '0';\n }\n }\n });\n });\n\n return muniMapLocations;\n};\n\nexport { getMuniMap };\n","import { lngLatToGoogle } from 'global-mercator';\nimport axios from 'axios';\nimport { setupCache } from 'axios-cache-interceptor';\nimport {\n ReverseGeocodingOptions,\n ReverseGeocodingResult,\n ReverseGeocodingResultJP,\n} from './interfaces';\nimport countryOptions from './countryOptions';\nimport { getTile, getTileResult } from './utils';\n\nimport { getMuniMap } from './muni';\n\ntype LngLat = [number, number];\n\nconst api = setupCache(\n axios.create({\n timeout: 2000,\n }),\n {\n ttl: 60 * 60 * 24 * 1000, // 1 day\n }\n);\n\napi.interceptors.request.use((config) => {\n const fullUrl = `${config.baseURL}${config.url}?${new URLSearchParams(\n config.params\n ).toString()}`;\n console.log('Full URL:', fullUrl);\n return config;\n});\n\nconst defaultOptions = countryOptions.DEFAULT;\n\n/**\n * Performs reverse geocoding to obtain location information based on longitude and latitude.\n *\n * @param lnglat - The longitude and latitude coordinates.\n * @param options - Optional parameters for reverse geocoding.\n * @returns A promise that resolves to the reverse geocoding result.\n */\nconst openReverseGeocoder = async (\n lnglat: LngLat,\n options?: ReverseGeocodingOptions\n): Promise<ReverseGeocodingResult> => {\n const opt = { ...defaultOptions, ...options };\n const [x, y] = lngLatToGoogle(lnglat, opt.zoomBase);\n const tile = await getTile(x, y, opt, api);\n return getTileResult(tile, x, y, lnglat, opt);\n};\n\n/**\n * Performs reverse geocoding using the GSI (Geospatial Information Authority of Japan) API.\n * Given latitude and longitude coordinates, it returns the corresponding municipality code and city name.\n *\n * @param {Object} params - The parameters for the reverse geocoding request.\n * @param {number} params.lat - The latitude coordinate.\n * @param {number} params.lon - The longitude coordinate.\n * @returns {Promise<ReverseGeocodingResultJP>} A promise that resolves to an object containing the municipality code and city name.\n *\n * @example\n * const result = await gsiReverseGeocoder({ lat: 35.6895, lon: 139.6917 });\n * console.log(result); // { code: '13101', city: 'Chiyoda-ku' }\n */\nconst gsiReverseGeocoder = async ({\n lat,\n lon,\n}: {\n lat: number;\n lon: number;\n}) => {\n const response = await api.get(\n 'https://mreversegeocoder.gsi.go.jp/reverse-geocoder/LonLatToAddress',\n {\n responseType: 'json',\n params: {\n lat,\n lon,\n },\n }\n );\n const result = response.data;\n const {\n results: { muniCd: code, lv01Nm: city },\n } = result;\n return { code, city } as ReverseGeocodingResultJP;\n};\n\n/**\n * Retrieves the elevation for a given longitude and latitude using the GSI API.\n *\n * @param {Object} coordinates - The coordinates for which to get the elevation.\n * @param {number} coordinates.lon - The longitude of the location.\n * @param {number} coordinates.lat - The latitude of the location.\n * @returns {Promise<{ longitude: number, latitude: number, elevation: number }>}\n * A promise that resolves to an object containing the longitude, latitude, and elevation.\n */\nconst getElevation = async ({ lon, lat }: { lon: number; lat: number }) => {\n // first, get elevation from GSI\n const response = await api.get(\n 'https://mreversegeocoder.gsi.go.jp/general/dem/scripts/getelevation.php',\n {\n responseType: 'json',\n params: {\n lat,\n lon,\n },\n }\n );\n\n const elevation = parseFloat(response.data.elevation);\n return { longitude: lon, latitude: lat, elevation };\n};\n\n/**\n * Reverse geocodes the given longitude and latitude to obtain a city code.\n *\n * @param {Object} params - The parameters for reverse geocoding.\n * @param {number} params.lon - The longitude of the location.\n * @param {number} params.lat - The latitude of the location.\n *\n * @returns {Promise<ReverseGeocodingResult>} A promise that resolves to the reverse geocoding result.\n *\n * @throws Will attempt to use an alternative geocoding service if the primary service fails.\n */\nconst reverseGeocoder = async ({\n lon,\n lat,\n}: {\n lon: number;\n lat: number;\n}): Promise<ReverseGeocodingResult> => {\n // first, get city code from open reverse geocoder(local)\n try {\n const result = await openReverseGeocoder([lon, lat]);\n return result;\n } catch (error) {\n // if failed, get city code from GSI\n console.log('Failed to get city code from open reverse geocoder');\n return gsiReverseGeocoder({ lat, lon });\n }\n};\n\nexport { reverseGeocoder, getElevation, getMuniMap as getCityMap };\n","// import { geoContains } from 'd3-geo';\nimport axios, { AxiosInstance } from 'axios';\nimport { VectorTile } from 'mapbox-vector-tile';\nimport { ReverseGeocodingOptions, ReverseGeocodingResult } from './interfaces';\n\n/**\n * Get a tile from targeted country's tilesets by using x and y tile index\n * @param x x tile index\n * @param y y tile index\n * @param options ReverseGeocodingOptions\n * @param api Axios object\n * @returns VectorTile object\n */\nexport const getTile = async (\n x: number,\n y: number,\n options: ReverseGeocodingOptions,\n api: AxiosInstance = axios\n): Promise<VectorTile> => {\n const tileUrl = options.tileUrl\n .replace('{z}', String(options.zoomBase))\n .replace('{x}', String(x))\n .replace('{y}', String(y));\n\n let buffer;\n\n try {\n const res = await api.get(tileUrl, { responseType: 'arraybuffer' });\n buffer = Buffer.from(res.data, 'binary');\n } catch (error) {\n throw error;\n }\n\n const tile = new VectorTile(buffer);\n return tile;\n};\n\n/**\n * Get a result of reverse geocoding\n * @param tile VectorTile object\n * @param x x tile index\n * @param y y tile index\n * @param lnglat number[] longitude, latitude\n * @param options ReverseGeocodingOptions\n * @returns an object of result of reverse gecoding\n */\nexport const getTileResult = (\n tile: VectorTile,\n x: number,\n y: number,\n lnglat: [number, number],\n options: ReverseGeocodingOptions\n): ReverseGeocodingResult => {\n let layers = Object.keys(tile.layers);\n\n if (!Array.isArray(layers)) layers = [layers];\n\n let geocodingResult: ReverseGeocodingResult = {};\n layers.forEach((layerID) => {\n const layer = tile.layers[layerID];\n if (layer && options.layer === layer.name) {\n for (let i = 0; i < layer.length; i++) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const feature: any = layer.feature(i).toGeoJSON(x, y, options.zoomBase);\n if (layers.length > 1) feature.properties.vt_layer = layerID;\n\n const geojson = {\n type: 'FeatureCollection',\n features: [feature],\n };\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n // const res = geoContains(geojson as any, lnglat);\n // if (res) {\n // geocodingResult = options.getResult(feature);\n // }\n }\n }\n });\n return geocodingResult;\n};\n\n"],"names":["countryOptions","JP","zoomBase","tileUrl","layer","getResult","feature","_feature$properties","_feature$properties2","code","String","id","length","prefecture","properties","city","DEFAULT","MuniRegex","api","setupCache","axios","create","timeout","ttl","interceptors","request","use","config","fullUrl","baseURL","url","URLSearchParams","params","toString","console","log","defaultOptions","Promise","resolve","get","responseType","then","response","muniMapObj","data","split","forEach","line","test","muniRecord","replace","muniRecordArray","Error","prefCode","prefName","cityCode","cityName","padStart","parseMuniRecord","_catch","error","e","reject","_ref2","lon","lat","elevation","parseFloat","longitude","latitude","_ref3","lnglat","opt","_extends","openReverseGeocoder","_lngLatToGoogle","lngLatToGoogle","x","y","options","buffer","_temp2","_result","VectorTile","_temp","res","Buffer","from","getTile","tile","layers","Object","keys","Array","isArray","layerID","name","i","toGeoJSON","vt_layer","getTileResult","_ref","_result$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,CACNiC,IAAAA,EACAD,IAAAA,MAGLvB,KAAA,SATKC,GAUN,IACA4D,EADe5D,EAASE,KAEtB2D,QAEF,MAAO,CAAE9F,KAFgB6F,EAAZE,OAEEzF,KAFwBuF,EAAZG,OAEuB,EACpD,CAAC,MAAA5C,GAAA,OAAAxB,QAAAyB,OAAAD,EAAA,CAAA,CAqDU6C,CAAmB,CAAEzC,IAAAA,EAAKD,IAAAA,GAClC,GACH,CAAC,MAAAH,GAAA,OAAAxB,QAAAyB,OAAAD,EAED,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sk-global/js-msearch-gsi-jp",
|
|
3
3
|
"description": "A client library for APIs that presented by Geospatial Information Authority of Japan",
|
|
4
|
-
"version": "2.0.
|
|
4
|
+
"version": "2.0.3",
|
|
5
5
|
"source": "src/index.ts",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"module": "dist/index.module.js",
|