Store Locator Widget - Baidu

Woosmap Store Locator Widget displaying store on Baidu Map

  1. Example
  2. Running the Sample Locally

Example

Store Locator Widget - Baidu
        const storeLocatorConfig = {
  theme: {
    primary_color: "#00754a",
  },
  maps: {
    provider: "baidu",
    apiKey: "oUQDfIp2b7qNxIuSaghaeip7",
  },
  woosmapView: {
    baiduMapStyle: {
      style: "light",
      // style: "dark"
      // style: "grassgreen"
      // style: 'midnight',
      // style: 'pink',
      // style: 'bluish',
      // style: "hardedge"
    },
    initialCenter: {
      lat: 31.230780461545375,
      lng: 121.36283503342771,
    },
    initialZoom: 13,
    breakPoint: 14,
    tileStyle: {
      color: "#00754a",
      size: 13,
      minSize: 6,
    },
    style: {
      default: {
        icon: {
          url: "https://images.woosmap.com/starbucks-marker.svg",
          scaledSize: {
            height: 40,
            width: 34,
          },
        },
        selectedIcon: {
          url: "https://images.woosmap.com/starbucks-marker-selected.svg",
          scaledSize: {
            height: 50,
            width: 43,
          },
        },
      },
    },
  },
};

function isMobileDevice(): boolean {
  return window.innerWidth < 500;
}

function initStoreLocator(): void {
  const webapp = new window.WebApp("map", "YOUR_API_KEY");
  webapp.setConf(storeLocatorConfig);
  webapp.render(isMobileDevice());
}

initStoreLocator();

declare global {
  // currently, the WebApp typings are not exported, so we use `any` here
  interface Window {
    WebApp: new (elementId: string, projectKey: string) => any;
  }
}

    
        const storeLocatorConfig = {
  theme: {
    primary_color: "#00754a",
  },
  maps: {
    provider: "baidu",
    apiKey: "oUQDfIp2b7qNxIuSaghaeip7",
  },
  woosmapView: {
    baiduMapStyle: {
      style: "light",
      // style: "dark"
      // style: "grassgreen"
      // style: 'midnight',
      // style: 'pink',
      // style: 'bluish',
      // style: "hardedge"
    },
    initialCenter: {
      lat: 31.230780461545375,
      lng: 121.36283503342771,
    },
    initialZoom: 13,
    breakPoint: 14,
    tileStyle: {
      color: "#00754a",
      size: 13,
      minSize: 6,
    },
    style: {
      default: {
        icon: {
          url: "https://images.woosmap.com/starbucks-marker.svg",
          scaledSize: {
            height: 40,
            width: 34,
          },
        },
        selectedIcon: {
          url: "https://images.woosmap.com/starbucks-marker-selected.svg",
          scaledSize: {
            height: 50,
            width: 43,
          },
        },
      },
    },
  },
};

function isMobileDevice() {
  return window.innerWidth < 500;
}

function initStoreLocator() {
  const webapp = new window.WebApp("map", "YOUR_API_KEY");

  webapp.setConf(storeLocatorConfig);
  webapp.render(isMobileDevice());
}

initStoreLocator();

    
        /*
 * Always set the map height explicitly to define the size of the div element
 * that contains the map.
 */
#map {
  height: 100%;
}

/*
 * Optional: Makes the sample page fill the window.
 */
html,
body {
  height: 100%;
  margin: 0;
  padding: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Helvetica Neue, Arial, Noto Sans, sans-serif, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol, Noto Color Emoji;
}


    
        <html>
  <head>
    <title>Store Locator Widget - Baidu</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta charset="utf-8" />

    <script src="https://webapp.woosmap.com/webapp.js"></script>

    <link rel="stylesheet" type="text/css" href="./style.css" />
    <script type="module" src="./index.js"></script>
  </head>
  <body>
    <div id="map"></div>
  </body>
</html>

    

Running the Sample Locally

Before you can run this sample on your local machine, you need to have Git and Node.js installed. If they’re not already installed, follow these instructions to get them set up.

Once you have Git and Node.js installed, you can run the sample by following these steps:

  1. Clone the repository and navigate to the directory of the sample.

  2. Install the necessary dependencies.

  3. Start running the sample.

Here are the commands you can use in your terminal to do this:

Shell
        git clone -b sample/store-locator-widget-baidu https://github.com/woosmap/js-samples.git
cd js-samples
npm i
npm start

    

You can experiment with other samples by switching to any branch that starts with the pattern sample/SAMPLE_NAME.

Shell
        git checkout sample/SAMPLE_NAME
npm i
npm start

    
Was this article helpful?
Have more questions? Submit a request