Hi all
I'd like my map to display two different popups. 'If' I click on the feature layer it return the popup related to that layer, 'Else' if I click anywhere other than the feature it returns a different popup.
I currently have two separate maps , each with their own different type of popup.
1. On this map you only return a popup if you hit the feature (street line): this has a customContent template directly related to the feature layer. Clicking anywhere else nothing is returned.
const customContent = new CustomContent({
outFields: ["*"],
creator: (event) => {
const location = view.popup.location;
const locationContent = `X: ${location.x.toFixed(0)}<br>Y: ${location.y.toFixed(0)}<br>`;
const name = `<font size='3px'><b>Street:</b> ${event.graphic.attributes["SITE_NAME"]}<br><b>Town:</b> ${event.graphic.attributes["TOWN_NAME"]}<br>`;
const link = `<br><a href=\"https://east-riding-self.test.achieveservice.com/service/Dangerous_building_or_structure_issue?` +
`street=${event.graphic.attributes["SITE_NAME"]}&town=${event.graphic.attributes["TOWN_NAME"]}&USRN=${event.graphic.attributes["SITE_CODE"]}&Easting=${location.x.toFixed(0)}&Northing=${location.y.toFixed(0)}"` +
` rel="nofollow ugc" style="display: block; height: 60px; width: 242px; background: #CC5500; color: #ffffff; text-align: center; font-weight: bold; font-size: 140%; line-height: 60px; padding: 7px; font-family: Arial; border-radius: 8px; text-decoration: none;">Report a traffic safety concern</a>`;
return name + link;
},
});
const template = new PopupTemplate({
outFields: ["*"],
content: [customContent],
});
const streetLayer = new FeatureLayer({
url: "https://services6.arcgis.com/Qptn479QktK11k72/arcgis/rest/services/New_Achieve_Streets_layer/FeatureServer/0",
outFields: ["*"],
});
streetLayer.maxScale=350;
streetLayer.minScale=2500;
streetLayer.popupTemplate = template;
map.add(streetLayer);
2. On this map you can click anywhere and it returns the popup (it never interacts with the feature layer).
view.popup.autoOpenEnabled = false;
view.on("click", (event) => {
if (view.scale <= 2500) {
const x = Math.round(event.mapPoint.x * 1) / 1;
const y = Math.round(event.mapPoint.y * 1) / 1;
view.popup.open({
content: `<a href=\"https://east-riding-self.test.achieveservice.com/service/Fly_posting_or_illegal_signs?` + `Easting=${x}&Northing=${y}"` + `target="_blank" rel="nofollow ugc" style="display: block; height: 60px; width: 242px; background: #CC5500; color: #ffffff; text-align: center; font-weight: bold; font-size: 160%; line-height: 60px; padding: 6px; font-family: Arial; border-radius: 7px; text-decoration: none;">Report fly-posting or an illegal sign</a>`,
location: event.mapPoint
});
}
});
I've tried putting the two sets of code onto the same map. However the '2' code (click anywhere) just seems to override everything and if I click on the feature (street layer) it just displays the 2nd popup.
I'm guessing I need a, 'If' you hit the feature display that popup, 'Else' display the click anywhere popup.
How do I go about this please? My attempts have failed.
Thanks Ricky