Hey I am new to using esri and have not been able to find a solution for this but is it possible to be able to make a layer active and display with a url string?
This is my code below.
require([
'esri/Map',
'esri/views/MapView',
'esri/layers/FeatureLayer',
'esri/widgets/LayerList',
'esri/request',
'esri/layers/GroupLayer',
'esri/layers/MapImageLayer',
'esri/PopupTemplate',
], (Map, MapView, FeatureLayer, LayerList, esriRequest, GroupLayer) => {
const template = {
title: '{name}',
content: '{comments}',
};
// request GeoJson data from USGS remote server
let url =
esriRequest(url, {
responseType: 'json',
}).then(function (response) {
// The requested data
let geoJson = response.data;
console.log(response.data);
});
// Create GroupLayer with the two MapImageLayers created above
// as children layers.
const firstLayer = new FeatureLayer({
title: 'Phase 1',
visible: true,
definitionExpression: 'phase = 1',
});
const secondLayer = new FeatureLayer({
title: 'Phase 2',
visible: false,
definitionExpression: 'phase = 2',
});
const thirdLayer = new FeatureLayer({
title: 'Phase 3',
visible: false,
definitionExpression: 'phase = 3',
});
const fourthLayer = new FeatureLayer({
title: 'Phase 4',
visible: false,
definitionExpression: 'phase = 4',
});
const fifthLayer = new FeatureLayer({
title: 'Phase 5',
visible: false,
definitionExpression: 'phase = 5',
});
firstLayer.popupTemplate = template;
secondLayer.popupTemplate = template;
thirdLayer.popupTemplate = template;
fourthLayer.popupTemplate = template;
fifthLayer.popupTemplate = template;
const demographicGroupLayer = new GroupLayer({
title: 'Closures',
visible: true,
// visibilityMode: 'exclusive',
// layers: [zeroLayer],
layers: [
fifthLayer,
fourthLayer,
thirdLayer,
secondLayer,
firstLayer,
],
});
const map = new Map({
basemap: 'hybrid',
layers: [demographicGroupLayer],
});
const view = new MapView({
container: 'viewDiv',
map: map,
center: [-81.643005, 38.3577], //Longitude, latitude
zoom: 15,
});
// Creates actions in the LayerList.
function defineActions(event) {
// The event object contains an item property.
// is is a ListItem referencing the associated layer
// and other properties. You can control the visibility of the
// item, its title, and actions using this object.
const item = event.item;
if (item.title === 'Closures') {
// An array of objects defining actions to place in the LayerList.
// By making this array two-dimensional, you can separate similar
// actions into separate groups with a breaking line.
item.actionsSections = [
[
{
title: 'Go to full extent',
className: 'esri-icon-zoom-out-fixed',
id: 'full-extent',
},
{
title: 'Layer information',
className: 'esri-icon-description',
id: 'information',
},
],
[
{
title: 'Increase opacity',
className: 'esri-icon-up',
id: 'increase-opacity',
},
{
title: 'Decrease opacity',
className: 'esri-icon-down',
id: 'decrease-opacity',
},
],
];
}
}
view.when(() => {
// Create the LayerList widget with the associated actions
// and add it to the top-right corner of the view.
const layerList = new LayerList({
view: view,
// executes for each ListItem in the LayerList
listItemCreatedFunction: defineActions,
});
// Add widget to the top right corner of the view
view.ui.add(layerList, 'top-left');
});
// map.add(featureLayer);
// featureLayer.popupTemplate = template;
});