Hi,
As shown in below figure. there are one layer(indicate as a red points) which I am adding as overlays.LayerOverlay. Now When I click on particular point I want to highlight that point, so how it is possible?
Highlight Layer Data on map when click
I am trying using below code:
Dim position As New PointShape(Double.Parse(args(0).ToString()), Double.Parse(args(1).ToString()))
Dim staticOverlay As LayerOverlay = DirectCast(map.CustomOverlays("myLayer"), LayerOverlay)
Dim dynamicOverlay As LayerOverlay = DirectCast(map.CustomOverlays("HightLightDynamicOverlay"), LayerOverlay)
Dim shapeFileLayer As MsSql2008FeatureLayer = DirectCast(staticOverlay.Layers("my_Layer"), MsSql2008FeatureLayer)
Dim highLightLayer As InMemoryFeatureLayer = DirectCast(dynamicOverlay.Layers("HighLightLayer"), InMemoryFeatureLayer)
highLightLayer.InternalFeatures.Clear()
Dim projection As New Proj4Projection()
projection.MemoryMode = Proj4MemoryMode.Unmanaged
projection.ExternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(32723)
projection.InternalProjectionParametersString = Proj4Projection.GetGoogleMapParametersString()
projection.Open()
Dim p1 As PointShape = TryCast(projection.ConvertToExternalProjection(position), PointShape)
Dim editFeature As Feature
shapeFileLayer.Close()
shapeFileLayer.Open()
Dim selectedFeatures As Collection(Of Feature) = shapeFileLayer.QueryTools.GetFeaturesNearestTo(p1, GeographyUnit.Meter, 1, New String() {})
shapeFileLayer.Close()
projection.Close()
If selectedFeatures.Count > 0 Then
editFeature = selectedFeatures(0)
End If
For Each feature As Feature In selectedFeatures
highLightLayer.InternalFeatures.Add(feature.Id, feature)
Next
Dim featureJson As String = MapHelper.ConvertFeaturesToJson(New Collection(Of Feature) From {editFeature})
Return featureJson
In this code clicked point is fetched in "selectedFeatures" and also
highLightLayer.InternalFeatures.Add(feature.Id, feature)
above statement execute,
but that point is not highlight on the map.
So What is the problem??
Hi Vivek,
Since it is an ajax call and you just add the features into the hightlight overlay in the server side, beside the server side, we need to refresh the layer in the client side to make the map update in the callback. So, we need some thing like the below codes:
Map1.ajaxCallAction(
’@ViewContext.RouteData.Values[“Controller”].ToString()’
,
‘ClickOnMap’
, { x: e.worldXY.lon, y: e.worldXY.lat },
function
(result) {
Map1.redrawLayer(
“HighlightOverlay”
);
})
Besides, we don’t need to return the JsonFeatures to the client.
Hope it helps.
Thanks,
Troy
Thanks Troy.
I already used above ajax code, and I resolve this issue now.
Now point is highlight which I clicked, but problem is it takes too much of time to highlight.
Dim selectedFeatures As Collection(Of Feature) = shapeFileLayer.QueryTools.GetFeaturesNearestTo(p1, GeographyUnit.Meter, 1, New String() {})
Above Line takes to much time to get feature.
I also try:
Dim selectedFeatures As Collection(Of Feature) = shapeFileLayer.QueryTools.GetFeaturesContaning(p1, New String() {})
But in this selectedFeatures is null.
So what I can do to speed up the process?
Hi Vivek,
Okay, good to hear the hightlight is works now.
For the performance issue, the reason “GetFeaturesNearestTo” will take too much time is because this method will get all the features in this layer at first and then do the filter. Besides, as your layer is using MsSql2008FeatureLayer and that is also a reason to make the speed down.
When using the “GetFeaturesContaning” and you got nothing of features, I think it is as all the features in the layer are point type, and it is impossible to say a point to contain a point. So we can’t get any features in this way.
I think the option is we can use the GetFeaturesWithinDistanceOf to instead:
Dim
radius
As
Double
= 1000
’ meter
Dim
clickPoint
As
New
PointShape()
While
allPossibleResults.Count < 0
radius *= 10
Dim
selectedFeatures
As
Collection(Of Feature) = shapeFileLayer.GetFeaturesWithinDistanceOf(clickPoint, GeographyUnit.Meter, DistanceUnit.Meter, radius, ReturningColumnsType.NoColumns)
…
End
While
Hope it helps.
Thanks,
Troy
Thanks Troy.
Using your code, point is highlight much faster than previous one.
Thanks its works well.
Vivek,
Good to hear it works.
Thanks,
Troy
Hi Troy…
When I click on the map its pass the wrong coordinate to the function, so thats why wrong point is highlight, I am passing the coordinates from view to controller using java script as below:
x = e.worldXY.lon;
y = e.worldXY.lat;
I am also try using,
var lonlat = Map1.getLonLatFromPixel(new OpenLayers.Pixel(e.x, e.y));
x = lonlat.lon;
y = lonlat.lat;
but still it pass the wrong coordinate like if I clicked on 485652.222235 512252.25545 that it was pass some other point coordinate like 556585.256252 6585545.25423
So what is the problem??
Hi Vivek,
Sorry to reply you late, Troy is busy for new release these days.
I have a question here, if the coordinate not the same between client side and server side, could we know which one is correct?
I guess maybe that’s because the projection, I am not sure but I think maybe you can try to reprojection the client side coordinate to see whether it will get correct value.
Regards,
Don
Hi Vivek,
Sorry to reply you late, Troy is busy for new release these days.
I have a question here, if the coordinate not the same between client side and server side, could we know which one is correct?
I guess maybe that’s because the projection, I am not sure but I think maybe you can try to reprojection the client side coordinate to see whether it will get correct value.
Regards,
Don
Hi,
Thanks Don,
Yes problem is due to difference between projection,
I convert the source projection into destination projection and done with this issue.
Hi Vivek,
That’s good you solved the problem.
Any question please let us know.
Regards,
Don