<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
<title>DevLabs - Search and Geocode</title>
<style>
html, body, #viewDiv {
padding: 0;
margin: 0;
height: 100%;
width: 100%;
}
</style>
<script>
require([
"esri/Map",
"esri/views/MapView",
"esri/widgets/Search",
"esri/layers/FeatureLayer",
"dojo/domReady!"
], function(Map, MapView, Search, FeatureLayer) {
var map = new Map({
basemap: "streets-vector"
});
// Add the layer to the map
var trailsLayer = new FeatureLayer({
});
//map.add(trailsLayer); // Optionally add layer to map
// Add the layer to the map
var trailsLayer2 = new FeatureLayer({
});
map.add(trailsLayer2); // Optionally add layer to map
// Add the layer to the map
var trailsLayer3 = new FeatureLayer({
});
map.add(trailsLayer3); // Optionally add layer to map
var view = new MapView({
container: "viewDiv",
map: map,
zoom: 19,
center: [0.46564130, 51.736810] // longitude, latitude
});
// Search
var search = new Search({
view: view
});
search.defaultSource.withinViewEnabled = false; // Limit search to visible map area only
view.ui.add(search, "top-right"); // Add to the map
// Add the trailheads as a search source
search.sources.push({
featureLayer: trailsLayer,
searchFields: ["Postcode", "UPRN", "ADDRESS" ],
displayField: "Postcode",
exactMatch: false,
outFields: ["*"],
resultGraphicEnabled: true,
name: "Postcode",
placeholder: "example: CM2 0HU",
popupTemplate: { // autocasts as new popupTemplate()
title: "Post Code: {Postcode}</br>UPRN: {UPRN}</br>ADDRESS: {ADDRESS}",
overwriteActions: true
}
});
search.sources.push({
featureLayer: trailsLayer2,
searchFields: [ "UPRN", "ADDRESS" ],
displayField: "ADDRESS",
exactMatch: false,
outFields: ["*"],
resultGraphicEnabled: true,
name: "Inborough Addresses",
placeholder: "example: CM2 0HU",
popupTemplate: { // autocasts as new popupTemplate()
title: "Post Code: {Postcode}</br>UPRN: {UPRN}</br>ADDRESS: {ADDRESS}",
overwriteActions: true
}
});
search.sources.push({
featureLayer: trailsLayer3,
searchFields: ["WARD_N" ],
displayField: "WARD_N",
exactMatch: false,
outFields: ["*"],
resultGraphicEnabled: true,
name: "Wards",
placeholder: "example: CM2 0HU",
popupTemplate: { // autocasts as new popupTemplate()
title: "Post Code: {Postcode}</br>UPRN: {UPRN}</br>ADDRESS: {ADDRESS}",
overwriteActions: true
}
});
function searchcomplete( search-complete) {
view.popup.open({
activeSourceIndex: Number,
errors: Error[],
numResults: Number,
searchTerm: String,
results: Object[],
});
},
searchWidget.on("search-complete", searchcomplete);
});</script>
</head>
<body>
<div id="viewDiv"></div>
</body>
</html>