Select to view content in your preferred language

Search and Directions Widget in same map

833
1
Jump to solution
10-28-2017 10:34 AM
DonaldShaw5
Emerging Contributor

Hello all, I am trying to implement the search and directions widget into a single map. I am having trouble getting both to populate inside the map. I have copied and pasted from the samples and am having no luck. I can get each to run in their own map but not together. Here is what I have so far:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>MyOwn</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
  <link rel="stylesheet" href="https://js.arcgis.com/3.22/dijit/themes/claro/claro.css">
  <link rel="stylesheet" href="https://js.arcgis.com/3.22/esri/css/esri.css">
  <style>
    html,
    body,
    #map {
      height: 100%;
      width: 100%;
      margin: 0;
      padding: 0;
    }
    #search {
      display: block;
      position: absolute;
      z-index: 3;
      top: 20px;
      left: 75px;
    }

</style>
  <script src="https://js.arcgis.com/3.22/"></script>
  <script>
    require([
      "esri/urlUtils", "esri/map","esri/dijit/Directions", "esri/dijit/Search", "dojo/parser","dijit/layout/BorderContainer", 
"dijit/layout/ContentPane","dojo/domReady!"


], function (urlUtils, Map,Directions, Search, parser) {
parser.parse();
urlUtils.addProxyRule({
urlPrefix: "route.arcgis.com",
proxyUrl: "/sproxy/"
});
urlUtils.addProxyRule({
urlPrefix: "traffic.arcgis.com",
proxyUrl: "/sproxy/"
});
var map = new Map("map", {
basemap: "gray",
center: [-119.417, 36.778], // lon, lat
zoom: 7
});

var search = new Search({
map: map
}, "search");
search.startup();


var directions = new Directions({
map: map
},"dir");
directions.startup();
});

</script>

</head>

<body class="claro">
<div data-dojo-type="dijit/layout/BorderContainer"
data-dojo-props="design:'headline', gutters:false"
style="width:100%;height:100%;">
<div data-dojo-type="dijit/layout/ContentPane"
data-dojo-props="region:'right'"
style="width:250px;">

<div id="dir"></div>
</div>
<div id="map"></div>
<div id="search"></div>
</div>

</body>
</html>
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Donald,

   I have made corrections to your code and comments. It is working now:

<!DOCTYPE html>
<html>
<!-- having lang="en" in the html tag was a major issue but I am not sure why-->

<head>
  <meta charset="UTF-8">
  <title>MyOwn</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
  <link rel="stylesheet" href="https://js.arcgis.com/3.22/dijit/themes/claro/claro.css">
  <link rel="stylesheet" href="https://js.arcgis.com/3.22/esri/css/esri.css">
  <style>
    html,
    body,
    #map {
      height: 100%;
      width: 100%;
      margin: 0;
      padding: 0;
    }

    #search {
      display: block;
      position: absolute;
      z-index: 3;
      top: 20px;
      left: 75px;
    }
  </style>
  <script src="https://js.arcgis.com/3.22/"></script>
  <script>
    require([
      "esri/urlUtils", "esri/map", "esri/dijit/Directions", "esri/dijit/Search", "dojo/parser", "dijit/layout/BorderContainer",
      "dijit/layout/ContentPane", "dojo/domReady!"


    ], function(urlUtils, Map, Directions, Search, parser) {
      parser.parse();
      urlUtils.addProxyRule({
        urlPrefix: "route.arcgis.com",
        proxyUrl: "/sproxy/"
      });
      urlUtils.addProxyRule({
        urlPrefix: "traffic.arcgis.com",
        proxyUrl: "/sproxy/"
      });
      var map = new Map("map", {
        basemap: "gray",
        center: [-119.417, 36.778], // lon, lat
        zoom: 7
      });

      var search = new Search({
        map: map
      }, "search");
      search.startup();


      var directions = new Directions({
        map: map
      }, "dir");
      directions.startup();
    });
  </script>

</head>

<body class="claro">
  <div data-dojo-type="dijit/layout/BorderContainer" data-dojo-props="design:'headline', gutters:false" style="width:100%;height:100%;">
    <div data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'right'" style="width:250px;">

      <div id="dir"></div>
    </div>
<!-- If you do not put the map in a ContentPane then it does not know to share the screen with the directions dijit content Pane -->
    <div id="map" data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'center'">
    </div>
    <div id="search"></div>
  </div>

</body>

</html>

View solution in original post

1 Reply
RobertScheitlin__GISP
MVP Emeritus

Donald,

   I have made corrections to your code and comments. It is working now:

<!DOCTYPE html>
<html>
<!-- having lang="en" in the html tag was a major issue but I am not sure why-->

<head>
  <meta charset="UTF-8">
  <title>MyOwn</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
  <link rel="stylesheet" href="https://js.arcgis.com/3.22/dijit/themes/claro/claro.css">
  <link rel="stylesheet" href="https://js.arcgis.com/3.22/esri/css/esri.css">
  <style>
    html,
    body,
    #map {
      height: 100%;
      width: 100%;
      margin: 0;
      padding: 0;
    }

    #search {
      display: block;
      position: absolute;
      z-index: 3;
      top: 20px;
      left: 75px;
    }
  </style>
  <script src="https://js.arcgis.com/3.22/"></script>
  <script>
    require([
      "esri/urlUtils", "esri/map", "esri/dijit/Directions", "esri/dijit/Search", "dojo/parser", "dijit/layout/BorderContainer",
      "dijit/layout/ContentPane", "dojo/domReady!"


    ], function(urlUtils, Map, Directions, Search, parser) {
      parser.parse();
      urlUtils.addProxyRule({
        urlPrefix: "route.arcgis.com",
        proxyUrl: "/sproxy/"
      });
      urlUtils.addProxyRule({
        urlPrefix: "traffic.arcgis.com",
        proxyUrl: "/sproxy/"
      });
      var map = new Map("map", {
        basemap: "gray",
        center: [-119.417, 36.778], // lon, lat
        zoom: 7
      });

      var search = new Search({
        map: map
      }, "search");
      search.startup();


      var directions = new Directions({
        map: map
      }, "dir");
      directions.startup();
    });
  </script>

</head>

<body class="claro">
  <div data-dojo-type="dijit/layout/BorderContainer" data-dojo-props="design:'headline', gutters:false" style="width:100%;height:100%;">
    <div data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'right'" style="width:250px;">

      <div id="dir"></div>
    </div>
<!-- If you do not put the map in a ContentPane then it does not know to share the screen with the directions dijit content Pane -->
    <div id="map" data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'center'">
    </div>
    <div id="search"></div>
  </div>

</body>

</html>