ThinkGeo.com    |     Documentation    |     Premium Support

Get features rendered in a given coordinate

Hi.

I’m using MapSuite WebAPI to render PointShape features on a map and I want to handle mouse clicks on them.

I’m using OpenLayers 3 on the client side, so my idea is:

  • Get the click (world/screen) coordinates and zoom level in the browser
  • Use MapSuite WebAPI to find if those coordinates are inside a feature symbol

I’m assuming if the API is smart enough to render the symbols in the right coordinates, it can translate click coordinates to pixel position.

Is it possible to find out if a given coordinate is inside the rendered symbols below?

Hi Darlan_Batista,

It’s hard to make sure whether a point is inside a symbol.

We can adjust whether a point is inside a feature in map, but the symbol is rendered by other way. In fact it looks like a style, and will be rendered on the fly, so it cannot be handled by spatial query. The logic can only handle the click point and the shape location, or an target area around the shape location, they should be world coordinates.

If you want to do something for the shape, maybe you can try to build marker for them and click on marker will fire the event on it.

Regards,

Ethan

Hi Ethan. Thanks for your answer.

I could use an area around the point location, but this area should change depending on the zoom level.
Is there any way I can get a ratio of meters(or other real-world measure)/pixel at a given zoom level?

I’m using fixed-size circles to display my points. So if such ratio exists I could do the following steps:

  1. Get click coordinates and current zoom level
  2. Get the corresponding pixel area for the zoom level
  3. Get all points inside the circle { certer = click coordinates; radius = (iconRadius * pixelLength) }
  4. Create a circle for each point inside, and check which one has the click coordinates in it

Is it possible?

If it’s not, is it possible to define an EllipseShape in pixels?

Hi Ethan.

I could get the meter/pixel ration from OpenLayers, but the spatial queries are not working well.
Here is what I’ve got:

// Create Layer
var proj4 = new Proj4Projection(
    Proj4Projection.GetDecimalDegreesParametersString(),
    Proj4Projection.GetSphericalMercatorParametersString()
);

if(!proj4.IsOpen) proj4.Open();

var feature = new Feature(new PointShape(-108.558944, 45.149776));
var memoryLayer = new InMemoryFeatureLayer(new List<FeatureSourceColumn>(), new List<Feature>() { feature });

if (!memoryLayer.IsOpen) memoryLayer.Open();
            
memoryLayer.FeatureSource.Projection = proj4;
memoryLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = new PointStyle(PointSymbolType.Circle, new GeoSolidBrush(GeoColor.StandardColors.Green), new GeoPen(GeoColor.StandardColors.Red, 5), 20);
memoryLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

// Create Click Feature
var clickLongitude = -108.558944;
var clickLatitude = 45.149776;
var clickRadiusInMeter = 1000;
var click = new PointShape(clickLongitude, clickLatitude);
var clickFeature = new EllipseShape(click, clickRadiusInMeter, GeographyUnit.DecimalDegree, DistanceUnit.Meter);

// Get Features Inside Click Area
var featuresContaining = memoryLayer.QueryTools.GetFeaturesContaining(clickFeature, ReturningColumnsType.AllColumns);
var featuresWithinDistance = memoryLayer.QueryTools.GetFeaturesWithinDistanceOf(clickFeature, GeographyUnit.DecimalDegree, DistanceUnit.Meter, 1000, ReturningColumnsType.AllColumns);
var featuresCrossing = memoryLayer.QueryTools.GetFeaturesCrossing(clickFeature, ReturningColumnsType.AllColumns);
var featuresIntersecting = memoryLayer.QueryTools.GetFeaturesIntersecting(clickFeature, ReturningColumnsType.AllColumns);

If you run the code above, no features are returned in any query. I wonder what I’m missing.

Hi Darlan_Batista,

You assign projection to the layer, so when you do spatial query for this layer, you need to make the “clickFeature” also be spherical mercator projection.

You should want to change the code like this:

            var click = new PointShape(clickLongitude, clickLatitude);
            click = proj4.ConvertToExternalProjection(click) as PointShape;
            var clickFeature = new EllipseShape(click, clickRadiusInMeter, GeographyUnit.Meter, DistanceUnit.Meter);

Regards,

Ethan

Thanks, Ethan.

It’s working.

Hi Darlan,

I am glad to hear that’s helpful.

Regards,

Ethan