Utilize Mapbox as the source for VGeosearch services

Utilizing mapbox as a provider for VGeosearch has been my recent project.

In certain scenarios where the user is Chinese, I need to initialize a map using mapbox (due to coordinate rules) and in other cases utilize Google maps. All of this is managed through Vue2-leaflet.

Here's the snippet of my code :

Vue template :

<template>
  <LMap>
    <LTileLayer :url="isChinese ? mapBoxUrl : googleMapsUrl" />

    <Vue2LeafletGoogleMutant
      v-if="!isChinese"
      :apikey="appParameters.googleMapKey"
      :lang="appParameters.language"
    />

    <VGeosearch
      id="geosearch"
      :options="{
        provider: geosearchOptions.provider,
        style: 'bar',
        showMarker: geosearchOptions.showMarker,
        autoClose: geosearchOptions.autoClose,
        searchLabel: geosearchOptions.searchLabel,
      }"
    />
  </LMap>
</template>

Typescript :

export default class Map extends Vue {
  // Some things I deleted beacause no interest

  @Getter(ReferencesGetter.country, { namespace: ReferencesModule.name })
  readonly getCountry!: (code: string) => Country;

  @Getter(UserGetter.hasNationality, { namespace: UserModule.name })
  readonly isUserInChina!: (country: Country) => boolean;

  readonly mapBoxUrl = `https://api.mapbox.com/styles/v1/mapbox/streets-zh-v1/tiles/{z}/{x}/{y}{r}?access_token=${this.appParameters.mapBoxKey}`;

  readonly googleMapsUrl = 'http://{s}.tile.osm.org/{z}/{x}/{y}.png';

  isChinese = false;

  geosearchOptions = {} as SearchControlProps;

  async mounted() {
    // this returns true in my use case
    this.isChinese = this.isUserInChina(this.getCountry(CountryIsoCodes.China));
    this.geosearchOptions = {
      provider: this.isChinese
        ? new OpenStreetMapProvider({
          'accept-language': CountryIsoCodes.China.toLowerCase(),
        })
        : new GoogleProvider({
          params: {
            key: this.appParameters.googleMapKey,
            language: this.appParameters.language,
            region: this.appParameters.language,
          },
        }),
      showMarker: true,
      autoClose: true,
      searchLabel: this.$t('message.action.enterAddress'),
    };
  }
}

Everything works smoothly when the user is not Chinese. However, in the alternate scenario, I repeatedly encounter the same error :

https://i.sstatic.net/4mcxd.png

While the map loads correctly, the geosearch functionality fails to operate properly.

Answer №1

Straightforward response.

It is not possible to define props after the initialization process. Therefore, trying to set it within the mounted function will not be successful.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How to access the component instance in Angular through router events

I am currently working on incorporating a title service into my Angular 10 application. My goal is to subscribe to router events, access the activated route's component, check if it has a title() getter, and then use that information to set the page&a ...

Searching for TypeScript type definitions for the @Angular libraries within Angular 2

After updating my application to Angular2 v2.0.0-rc.1, I am encountering TypeScript compile errors and warnings when webpack bundles my application. These messages appear for any @angular packages referenced in my TypeScript source files: ERROR in ./src/a ...

Unable to retrieve a string from one function within another function

Three functions are responsible for triggering POST API calls, with the intention of returning a success or failure message to whoever invokes them (Observable<string>). In an effort to avoid repetition, I introduced a new function to retrieve succe ...

Guide on passing mixins as properties and implementing them in child components with Vue.js

I am facing a situation where I have a parent component that contains two child components named add and edit. These components share some common properties, and I would like to utilize mixins to achieve this. To do so, I have added an object called mix to ...

Establishing properties while creating a fresh instance of a class

I am currently working on developing an invoice application using TypeScript. In my project, I have created an Invoice class with several properties and objects. However, when attempting to set the properties of an item object within the Invoice class usin ...

Is there a way to trigger a request to the backend when the user closes or refreshes the browser?

My Objective: I am working on a lobby feature that updates automatically when a player leaves. Using backend requests and sockets, the lobby is updated to display the current list of players after someone exits. The Challenge: I am faced with the issue ...

Learning to utilize the i18n library with React Vite

The developer console is showing the following message: i18next::translator: missingKey en translation suche suche Here is the file structure of my project: vite.config.ts i18n.js test/ src/ components/InputSearch.tsx routes/ public/ de/translation. ...

What causes two variables of identical types to exhibit varying behaviors based on their creation methods?

What causes the types of tuple and tuple2 to be different even though both nums and nums2 are of type (0 | 1 | 2)[]? // const nums: (0 | 1 | 2)[] const nums: (0 | 1 | 2)[] = []; // let tuple: (0 | 1 | 2)[] let tuple = [nums[0], nums[1]]; // const nums2: ...

Tips for incorporating declaration .d.ts files into your TypeScript project

I have come across much literature discussing the purpose of declaration .d.ts files, but I haven't found much information on how to actually implement them. It seems that these files can be automatically generated using the typescript compiler. This ...

Assigning the identical function to multiple buttons in Ionic version 2

I designed an eye icon button for toggling password visibility. However, I have a specific page that needs to serve as the "password recovery" page. In this particular page, there are 3 input fields, each with the same toggle button attached to them... ...

organize the values based on their priority using reactjs

I'm facing a challenge involving two arrays of objects: array1 and array2. I need to display only three values from both arrays, with priority given to array1. The requirements are as follows: if array1 contains 3 elements, all three should be shown. ...

Implementing a feature to effortlessly select all or unselect all with just a few clicks in the filter checkboxes using React

I've implemented a checkbox filter function, but I'm trying to enhance it by adding an option for checking all or unchecking all checkboxes. Additionally, I would like to integrate TypeScript into the code. Any guidance on how to achieve this wou ...

Using dynamic parameters in React Router v4

Looking to implement dynamic routing in my React app using React-Router v4. I am aiming to construct the following address: http://localhost:7777/oceanside-yaht-club/booking/search where oceanside-yaht-club can change based on the customer. However, my ...

Angular 8's array verification feature lacks the ability to recognize preexisting elements

I've been trying to add and delete items in an array when a user selects or deselects the same item. However, it appears that either my array is not working properly or there is a bug in my code causing it to fail. <div class="grp-input"> ...

Tips for concealing text in ion-option ionic2

Is there a way to hide text within an ion-option? I'm looking to conceal or remove certain text from displaying in an ion-option without deleting the underlying data. This is important as I want users to be able to choose it. <ion-select [(ngModel ...

Optimal method for presenting informative content at the top of a webpage: Harnessing the power of JavaScript

Could you check out the image linked above? There appears to be a css animation on the bright yellow arrow. Issue: I am working on a page where I need to guide users' attention (possibly with a yellow arrow) and have it disappear automatically ...

Update the TypeScript definitions in the index.d.ts file using the npm command, by overriding it with the reference types

After running npm install, I noticed that the index.d.ts file contains a reference to the wrong path: /// <reference types="[WrongPath]"/>. As someone new to npm, TypeScript, and web development in general, I'm wondering if it's possible t ...

Creating a stationary Map in Typescript: A step-by-step guide

I am attempting to create a static Map that will store key value pairs with strings only. These values are meant to be constant and never change. Here is an example of what I'm trying to achieve: static KEY_VALUE_PAIR: Map<string, string>: { & ...

It appears that I am encountering an issue when attempting to utilize the async pipe operator

<div class="image" *ngFor="let entry of (currentUserData | async)?.entries"></div> Error message: The term 'currentUserData' is not recognized. Please check the component declaration, template variable declarations, and element refe ...

TypeDoc is having trouble locating the Angular 2 modules

Currently, I am attempting to create documentation files using TypeDoc. When executing TypeDoc with the command below: /node_modules/.bin/typedoc --module system --target ES5 --exclude *.spec.ts* --experimentalDecorators --out typedoc app/ --ignoreCompile ...