index.html
<html> <head> <meta charset="utf-8"> <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no"> <title>ArcGIS API for JavaScript Tutorials: Create a Starter App</title> <style> html, body, #viewDiv { padding: 0; margin: 0; height: 100%; width: 100%; } </style> <script type="text/javascript"> dojoConfig = { async: true, packages: [ { name: "widgets", location: "modules/widgets" // or wherever you keep your custom code } ] }; </script> <link rel="stylesheet" href="https://js.arcgis.com/4.18/esri/themes/light/main.css"> <script src="https://js.arcgis.com/4.18/"></script> <script type="text/javascript" src="main.js"></script> </head> <body> <div id="viewDiv"></div> </body> </html>
main.js
require([
"esri/Map",
"esri/views/MapView",
"dojo/ready",
"widgets/searchWidget"
], function(Map, MapView,ready) {
ready(function () {
var map = new Map({
basemap: "topo-vector"
});
var view = new MapView({
container: "viewDiv",
map: map,
center: [-118.80500, 34.02700], // longitude, latitude
zoom: 13
});
var widget = new searchWidget(view)
});
});
widget.js
define(["esri/widgets/Search"], function(Search) {
var search
return{
searchWidget: function(view){
search = new Search({
view: view
});
view.ui.add(search, 'top-right');
}
}
});