wrld.js

Using the Marker Controller and Searchbar together

This example shows how you can use the marker controller and searchbar together to easily display search results.

To use the components in this example, you will have to include JQuery, wrld.css as shown in the code sample below.

<!DOCTYPE HTML>
<html>
  <head>
    <script src="https://cdn-webgl.wrld3d.com/wrldjs/dist/latest/wrld.js"></script>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.1/leaflet.css" rel="stylesheet" />

    <link href="https://cdn-webgl.wrld3d.com/wrldjs/addons/resources/latest/css/wrld.css" rel="stylesheet"/>
    <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
    <script src="https://cdn-webgl.wrld3d.com/wrldjs/addons/searchbar/latest/searchbar.js"></script>
    <script src="https://cdn-webgl.wrld3d.com/wrldjs/addons/marker_controller/latest/marker_controller.js"></script>

  </head>
  
  <body>
  <div style="position: relative">
    <div id="widget-container" class="wrld-widget-container"></div>
    <div id="map" style="height: 400px"></div>
    <script>
      var map = L.Wrld.map("map", "your_api_key_here", {
        center: [37.79505, -122.40815],
        zoom: 15
      });

      var searchbarConfig = {
        apiKey: "your_api_key_here",
        outdoorSearchMenuItems: [
          {name: "Around Me", searchTag: "", iconKey: "aroundme"},
          {name: "Tourism", searchTag: "tourist_info", iconKey: "tourist_info"}
        ],
        locationJumps: [
          {name: "San Francisco", latLng: [37.7952, -122.4028]}
        ]
      };
      var searchbar = new WrldSearchbar("widget-container", map, searchbarConfig);
      var markerController = new WrldMarkerController(map, { searchbar: searchbar });
      searchbar.on("searchresultselect", goToResult);

      function goToResult(event) {
        markerController.selectMarker(event.result.sourceId);
        map.setView(event.result.location.latLng, 15);
      }
    </script>

  </div>
  </body>
</html>
v0.1.1452