## Leaflet-geosearch 無法在 TB Widget 使用 debug 過程 ### TB Widgets 1. 在 custom widget 的 resource 加入 `https://unpkg.com/leaflet-geosearch@3.0.0/dist/geosearch.css` & `https://unpkg.com/leaflet-geosearch@3.0.6/dist/geosearch.umd.js` 2. javascript 加入 ``` const searchControl = new GeoSearch .GeoSearchControl({ provider: new GeoSearch .OpenStreetMapProvider(), style: 'bar', }); self.ctx.map.map.map.addControl(searchControl); ``` 3. error code ``` TypeError: Cannot read properties of undefined (reading 'indexOf') at i.addTo (1429.78ad974abf171bee.js:1:460023) at i.addControl (1429.78ad974abf171bee.js:1:460478) at self.onInit (eval at createWidgetControllerDescriptor (7502.4ed12aa91baa5378.js:1:5892535), <anonymous>:16:26) at 7502.4ed12aa91baa5378.js:1:5976808 at ct.<computed> (polyfills.0507304945bea4e4.js:1:29718) at Y.invokeTask (polyfills.0507304945bea4e4.js:1:7467) at k.runTask (polyfills.0507304945bea4e4.js:1:2794) at invokeTask (polyfills.0507304945bea4e4.js:1:8554) at V.J.useG.invoke (polyfills.0507304945bea4e4.js:1:8455) at V.args.<computed> (polyfills.0507304945bea4e4.js:1:29421) ``` 4. 透過 source code host tb-web 後使用 browser dev tools ( F12 ) 在發生錯誤的 `i.addTo` 設立 breakpoint debug 發現 leaflet-geosearch 的 control 物件沒有 `pos` 屬性,對照 npm 版本發現不一致,統一改為 `3.9.0` 後可正常運作。 `https://unpkg.com/leaflet-geosearch@3.9.0/dist/geosearch.css` `https://unpkg.com/leaflet-geosearch@3.9.0/dist/geosearch.umd.js` ### CE Source Code 1. npm install leaflet-geosearch 2. npm install @type/google.maps 3. 修改 `src\app\modules\home\components\widget\lib\maps\providers\openstreet-map.ts` 後可正常運作 ``` ... import { SearchControl, OpenStreetMapProvider } from 'leaflet-geosearch'; ... const searchControl = SearchControl({ provider: new OpenStreetMapProvider(), style: 'bar', }); map.addControl(searchControl); ... ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up