I am new to javascript and am playing around with customizing the CMV template https://github.com/cmv/cmv-app. I am trying to customize my info windows for my layers, and have had some luck modifying the identify.js file. I would like to use the same info window setup (fields and formatting) for more than one layer in my map service, but I can't figure out how to do that. I've tried to just add an array ([6,7]), and also tried adding a for loop to loop through the array with no luck. I don't get any errors, just no info windows load when I tried to use the array or loop through it:
msArray = [6,7];
for (var i = 0; i < msArray.length; i++) { define({map:!0,mapClickMode:!0,mapRightClickMenu:!0,identifyLayerInfos:!0,identifyTolerance:5,identifies:{
mapSets:{msArray[i]:{title:"Map Sets",description: "<b>Name:</b> {Sheet Label}<br><b>County:</b> {County}<br><b>Route:</b> {Route}<br><b>Postmile:</b> {Postmile}<br><b>Map Type:</b> {Map Type}\
<br><b>Hanging File:</b> {Hanging File}<br><b>Revision Date:</b> {Revision Date}<br><b>Original Draft Decade:</b> {Original Draft Decade}<br><b>Coordinate System:</b> {Coordinate System} \
<br><br><div align=center>{image_path}</div>"}};
}
Here's the code that works, when I reference one layer only (layer id in the code below is 6):
define({map:!0,mapClickMode:!0,mapRightClickMenu:!0,identifyLayerInfos:!0,identifyTolerance:5,identifies:{
mapSets:{6:{title:"Map Sets",description: "<b>Name:</b> {Sheet Label}<br><b>County:</b> {County}<br><b>Route:</b> {Route}<br><b>Postmile:</b> {Postmile}<br><b>Map Type:</b> {Map Type}\
<br><b>Hanging File:</b> {Hanging File}<br><b>Revision Date:</b> {Revision Date}<br><b>Original Draft Decade:</b> {Original Draft Decade}<br><b>Coordinate System:</b> {Coordinate System} \
<br><br><div align=center>{image_path}</div>"}},
UPDATE: Latest code posted below, using function provided in solution. Second function does not work:
define(function () {
function createSharedTemplateMS () {
return {
title:"Map Sets",
description: [
'<b>Name:</b> {Sheet Label}<br>',
'<b>County:</b> {County}<br>',
'<b>Route:</b> {Route}<br>',
'<b>Postmile:</b> {Postmile}<br>',
'<b>Map Type:</b> {Map Type} <br>',
'<b>Hanging File:</b> {Hanging File}<br>',
'<b>Revision Date:</b> {Revision Date}<br>',
'<b>Original Draft Decade:</b> {Original Draft Decade}<br>',
'<b>Coordinate System:</b> {Coordinate System}<br><br>',
'<div align=center>{image_path}</div>'
].join('')
};
}
return {
map:true,
mapClickMode:true,
mapRightClickMenu:true,
identifyLayerInfos:true,
identifyTolerance:5,
identifies: {
mapSets: {
6: createSharedTemplateMS(),
7: createSharedTemplateMS(),
8: createSharedTemplateMS(),
9: createSharedTemplateMS(),
10: createSharedTemplateMS(),
11: createSharedTemplateMS(),
12: createSharedTemplateMS()
}
}
};
});
define(function () {
function createSharedTemplatePrcl () {
return {
title:"Parcels",
description: [
'<b>Name:</b> {Name}<br>',
'<b>County:</b> {County}<br>',
'<b>Route:</b> {Route}<br>',
'<b>Postmile:</b> {Postmile}',
'<br><b>Description:</b> {Description}<br>',
'<b>Area:</b> {Area}<br>',
'<b>Map Sheet:</b> {Map Sheet}<br>',
'<b>Parcel Type:</b> {Parcel Type}<br>',
'<b>Parcel Phase:</b> {Parcel Phase}',
'<br><b>Geometry Quality:</b> {Geometry Quality}<br>',
'<b>Source:</b> {Source}<br><br>',
'<br><div align=center>{doc_path}</div>'
].join('')
};
}
return {
map:true,
mapClickMode:true,
mapRightClickMenu:true,
identifyLayerInfos:true,
identifyTolerance:5,
identifies: {
mapSets: {
1: createSharedTemplatePrcl(),
2: createSharedTemplatePrcl(),
3: createSharedTemplatePrcl(),
4: createSharedTemplatePrcl()
}
}
};
});