The map allows you to retrieve the objects that it visualizes at a particular location. Use the pickAt(x,y,radius) instance method of the Map to retrieve all objects at the screen position specified by the x and y parameters. You can retrieve objects from selectable layers only.

You also have the option to use the pickClosestObject(x,y,radius) instance method, to retrieve the first selectable object near the screen position specified by the x and y parameters.

Two other methods, pickAtRectangle and pickClosestObjectRectangle, allow you to retrieve objects visible in a specific rectangular area. You specify the rectangle by defining the position of its center point and its width and height.

By default, all those methods check if the view position overlaps with the shape visualized for the feature. If you also want to retrieve objects when the view position overlaps with the labels of the feature, you must use the optional paintRepresentations parameter. It specifies the paint representation used to retrieve features:

  • The feature body is used to retrieve an object: view/PaintRepresentation.BODY.

  • The feature label is used to retrieve an object: view/PaintRepresentation.LABEL.

If you leave this parameter out, only the feature bodies are used to retrieve the object.