Select to view content in your preferred language

Anchor Popup to Result Point

503
1
Jump to solution
12-12-2023 10:13 AM
TristanG
Emerging Contributor

So, I have a map and some points on it. When someone clicks on a point to view the popup(popupTemplate), and then zooms in, the popup is anchored to the exact point where they clicked, so it could be a few streets away if they zoom in.

Is there a way to anchor the popups to open on the spot of the symbol that was clicked?

I attached an image, so ideally, I'd want the popup to be centered from that blue dot

0 Kudos
1 Solution

Accepted Solutions
JoelBennett
MVP Regular Contributor

This isn't the prettiest thing, but it works; I would recommend adding it directly after creating your MapView. 

reactiveUtils.when(() => view.popup?.actions, ()=>{
	view.popup.watch("selectedFeatureIndex, visible, location", function(newValue, oldValue, propertyName, target) {
		if ((target.visible) && (target.selectedFeatureIndex === 0) && (target.selectedFeature.geometry?.type == "point") && (!target.selectedFeature.geometry.equals(target.location)))
			target.location = target.selectedFeature.geometry.clone();
	});
});

 

(Note that reactiveUtils is esri/core/reactiveUtils)

View solution in original post

1 Reply
JoelBennett
MVP Regular Contributor

This isn't the prettiest thing, but it works; I would recommend adding it directly after creating your MapView. 

reactiveUtils.when(() => view.popup?.actions, ()=>{
	view.popup.watch("selectedFeatureIndex, visible, location", function(newValue, oldValue, propertyName, target) {
		if ((target.visible) && (target.selectedFeatureIndex === 0) && (target.selectedFeature.geometry?.type == "point") && (!target.selectedFeature.geometry.equals(target.location)))
			target.location = target.selectedFeature.geometry.clone();
	});
});

 

(Note that reactiveUtils is esri/core/reactiveUtils)