search widget+4.6

2663
34
12-31-2017 02:15 AM
anjelinaponkerat
Occasional Contributor II

Hi

I,m using search widget in 3d view by 4.6 version , but I can not use my feature service!! why? this is my sample:

      var search = new Search({
        sources: [{
          featureLayer: new FeatureLayer("https://services.arcgis.com/b6gLrKHqgkQb393u/arcgis/rest/services/TaxParcelQuery/FeatureServer/0", {
            outFields: ["*"],
            infoTemplate: new InfoTemplate("Parcels", "Owner name: ${OWNERNME1}</br>Parcel ID: ${PARCELID}</br>Site address: ${SITEADDRESS}")
          }),
          outFields: ["OWNERNME1","PARCELID","SITEADDRESS"],
          displayField: "OWNERNME1",
          suggestionTemplate: "${PARCELID}: ${SITEADDRESS}",
          name: "Parcels",
          placeholder: "example: Shawn Smith",
          enableSuggestions: true
      }],
        view: view
      }, "search");


      search.startup();
0 Kudos
34 Replies
RobertScheitlin__GISP
MVP Emeritus

Anjelina,

   Attention to detail is going to cause you issues all the time. There is No "InfoTemplate" in the 4.x API it is now PopupTemplate (line 5).

      var search = new Search({
        sources: [{
          featureLayer: new FeatureLayer("https://services.arcgis.com/b6gLrKHqgkQb393u/arcgis/rest/services/TaxParcelQuery/FeatureServer/0", {
            outFields: ["*"],
            popupTemplate: new PopupTemplate("Parcels", "Owner name: ${OWNERNME1}</br>Parcel ID: ${PARCELID}</br>Site address: ${SITEADDRESS}")
          }),
          outFields: ["OWNERNME1","PARCELID","SITEADDRESS"],
          displayField: "OWNERNME1",
          suggestionTemplate: "${PARCELID}: ${SITEADDRESS}",
          name: "Parcels",
          placeholder: "example: Shawn Smith",
          enableSuggestions: true
      }],
        view: view
      }, "search");


      search.startup();
anjelinaponkerat
Occasional Contributor II

I changed it but didnt work!!:

var search = new Search({
sources: [{
featureLayer: new FeatureLayer("https://services.arcgis.com/b6gLrKHqgkQb393u/arcgis/rest/services/TaxParcelQuery/FeatureServer/0", {
outFields: ["*"],

}),
outFields: ["OWNERNME1","PARCELID","SITEADDRESS"],
displayField: "OWNERNME1",
name: "Parcels",
placeholder: "example: Shawn Smith",
enableSuggestions: true
}],
view: view
}, "search");


search.startup();

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Anjelina,

   Must be something else in your code then because this works fine for me:

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
  <title>Intro to SceneView - Create a 3D map - 4.6</title>
  <style>
    html,
    body,
    #viewDiv {
      padding: 0;
      margin: 0;
      height: 100%;
      width: 100%;
    }
  </style>

  <link rel="stylesheet" href="https://js.arcgis.com/4.6/esri/css/main.css">
  <script src="https://js.arcgis.com/4.6/"></script>

  <script>
    require([
      "esri/Map",
      "esri/views/SceneView",
      "esri/layers/FeatureLayer",
      "esri/widgets/Search",
      "dojo/domReady!"
    ], function(Map, SceneView, FeatureLayer, Search) {

      var map = new Map({
        basemap: "streets",
        ground: "world-elevation"
      });

      var view = new SceneView({
        container: "viewDiv",
        map: map,
        scale: 50000000,
        center: [-101.17, 21.78]
      });
      
      var search = new Search({
        sources: [{
          featureLayer: new FeatureLayer("https://services.arcgis.com/b6gLrKHqgkQb393u/arcgis/rest/services/TaxParcelQuery/FeatureServer/0", {
            outFields: ["*"]
//notice you should not have a trailing comma if there is nothing else after the last property.
          }),
          outFields: ["OWNERNME1","PARCELID","SITEADDRESS"],
          displayField: "OWNERNME1",
          name: "Parcels",
          placeholder: "example: Shawn Smith",
          enableSuggestions: true
        }],
        view: view
      }, "search");
      
      // Add the search widget to the top right corner of the view
      view.ui.add(search, {
        position: "top-right"
      });

    });
  </script>
</head>

<body>
  <div id="viewDiv"></div>
  <div id="search"></div>
</body>
</html>‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
anjelinaponkerat
Occasional Contributor II

ok, but when I use my own map service for ground and base map the search tools can not navigate to result!!!

{


var ExaggeratedElevationLayer = BaseElevationLayer.createSubclass({
properties: {
exaggeration: 2.5
},

// The load() method is called when the layer is added to the map
// prior to it being rendered in the view.

load: function() {
this._elevation = new ElevationLayer({
url: "http://localhost:6080/arcgis/rest/services/dem_90/ImageServer"
});

// wait for the elevation layer to load before resolving load()
this.addResolvingPromise(this._elevation.load());
},

// Fetches the tile(s) visible in the view
fetchTile: function(level, row, col) {
// calls fetchTile() on the elevationlayer for the tiles
// visible in the view
return this._elevation.fetchTile(level, row, col)
.then(function(data) {

var exaggeration = this.exaggeration;

// `data` is an object that contains the
// the width of the tile in pixels,
// the height of the tile in pixels,
// and the values of each pixel
data.values.forEach(function(value, index, values) {
// each value represents an elevation sample for the
// given pixel position in the tile. Multiply this
// by the exaggeration value
values[index] = value * exaggeration;
});

return data;
}.bind(this));
}
});
/*****************************************************************
* Create two TileLayer instances. One pointing to a
* cached map service depicting U.S. male population and the other
* pointing to a layer of roads and highways.
*****************************************************************/
var transportationLyr = new TileLayer({
url: "http://localhost:6080/arcgis/rest/services/new/MapServer",
// This property can be used to uniquely identify the layer
id: "streets",
visible: false
});

var housingLyr = new TileLayer({
url: "http://localhost:6080/arcgis/rest/services/land/MapServer",
id: "ny-housing",
opacity: 0.3


});

/*****************************************************************
* Layers may be added to the map in the map's constructor
*****************************************************************/
var map = new Map({

ground: {
layers: [
new ExaggeratedElevationLayer()
]
}


});

/*****************************************************************
* Or they may be added to the map using map.add()
*****************************************************************/
map.add(transportationLyr);

var view = new SceneView({
container: "viewDiv",
map: map


});
map.add(housingLyr);

var search = new Search({
sources: [{
featureLayer: new FeatureLayer("http://localhost:6080/arcgis/rest/services/city/FeatureServer/0", {
outFields: ["*"]
//notice you should not have a trailing comma if there is nothing else after the last property.
}),
outFields: ["town"],
displayField: "town",
name: "town",
placeholder: "example: texas",
zoomScale:100000,
maxResults:6,
maxSuggestions:120,
autoNavigate: true,
supportsPagination: true,
}],
view: view
}, "search");

// Add the search widget to the top right corner of the view
view.ui.add(search, {
position: "top-right"
});


/*****************************************************************
* The map handles the layers' data while the view and layer views
* take care of renderering the layers
*****************************************************************/
view.on("layerview-create", function(event) {
if (event.layer.id === "ny-housing") {
// Explore the properties of the population layer's layer view here
console.log("LayerView for male population created!", event.layerView);
}
if (event.layer.id === "streets") {
// Explore the properties of the transportation layer's layer view here
// Explore the properties of the transportation layer's layer view here
console.log("LayerView for streets created!", event.layerView);
}
});

/*****************************************************************
* Layers are promises that resolve when loaded, or when all their
* properties may be accessed. Once the population layer has loaded,
* the view will animate to it's initial extent.
*****************************************************************/
view.when(function() {
housingLyr.when(function() {
view.goTo(housingLyr.fullExtent);
});
});

var streetsLyrToggle = dom.byId("streetsLyr");

/*****************************************************************
* The visible property on the layer can be used to toggle the
* layer's visibility in the view. When the visibility is turned off
* the layer is still part of the map, which means you can access
* its properties and perform analysis even though it isn't visible.
*******************************************************************/
on(streetsLyrToggle, "change", function() {
transportationLyr.visible = streetsLyrToggle.checked;
});

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Anjelina,

   Is this layer actually a cached layer localhost:6080/arcgis/rest/services/land/MapServer?

Are all the layer the same WKID?

0 Kudos
anjelinaponkerat
Occasional Contributor II

yes

All of them are  102100 wkid and have cash.

my feature service and my ground are on 10.5  and my basemap is on 10.2.2

0 Kudos
anjelinaponkerat
Occasional Contributor II

All of them are  102100 wkid and have cash.

 

my feature service and my ground are on 10.5  and my basemap is on 10.2.2

What should I do?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Anjelina,

  Try smaller steps when debugging. Don't use your basemap or elevation layer and see if you can get the Search widget to work with your layer. Then if you get that working then try adding one of your Basemaps.

0 Kudos
anjelinaponkerat
Occasional Contributor II

I can use search widget  with esri ground and base map, but I have problem with my own

0 Kudos