JS in View:
function editShapeCallback(result) {
debugger;
var features = Map1.getFeaturesFromJson(result.get_responseData());
var editOverlay = Map1.getEditOverlay();
editOverlay = Map1.getLayersByName(“EditOverlay”)
editOverlay.addFeatures(features);
//Map1.setEditSetting(EditSettings.Reshape);
//Map1.setEditSetting(EditSettings.Resize);
//Map1.setEditSetting(EditSettings.Rotate);
//Map1.setEditSetting(EditSettings.Drag);
Map1.getDynamicOverlay().redraw(true);
Map1.setDrawMode(“Modify”);
}
Controller:
<MapActionFilter()> _
Function EditShape(map As Map, args As GeoCollection(Of Object)) As String
Dim dynamicOverlay As LayerOverlay = map.CustomOverlays(“DynamicOverlay”)
'Dim shapeLayer As InMemoryFeatureLayer = DirectCast(dynamicOverlay.Layers(“sql2008Layer”), InMemoryFeatureLayer)
'Dim featureJson As String = MapHelper.ConvertFeaturesToJson(shapeLayer.InternalFeatures)
'shapeLayer.InternalFeatures.Clear()
'Return featureJson
'Dim dynamicOverlay As LayerOverlay = map.CustomOverlays(“DynamicOverlay”)
Dim sqlLayer As MsSql2008FeatureLayer = New MsSql2008FeatureLayer(ConfigurationManager.ConnectionStrings(“Connection”).ToString, “CADASTROMUNICIPAL_NEW”, “id”)
sqlLayer.Open()
'Dim features As Collection(Of Feature) = sqlLayer.FeatureSource.GetAllFeatures(ReturningColumnsType.AllColumns)
Dim featureIds As New Collection(Of String)() From {“13159”}
'Dim a As Feature = sqlLayer.FeatureSource.GetFeaturesByIds(featureIds, ReturningColumnsType.NoColumns)(0)
Dim featuresJson As String = MapHelper.ConvertFeaturesToJson(sqlLayer.FeatureSource.GetFeaturesByIds(featureIds, ReturningColumnsType.NoColumns))
sqlLayer.Close()
Return featuresJson
End Function
In above JS var editOverlay = Map1.getEditOverlay(); is return null value what is the problem??
getEditOverlay() function return null value
Hi Vivek,
Here are two ways to init the EditOverlay.
• Call the Map1.setDrawMode method to make the map under drawing mode, for example: Map1.setDrawMode(‘Rectangle’);
• Call the Map1.getMapParser().initDrawControls() method before getting the editoverlay in the callback section.
If the issue still exists,please feel free to let us know.
Best regards,
Thank you Johnny
After add your code it returns a value, but now problem is that it copy a same shape on original shape
Means I want to edit original shape but currently copy of that same shape is created on original shape
please reply as soon as possible
My code after add your code is as below:
function editShapeCallback(result) {
var features = Map1.getFeaturesFromJson(result.get_responseData());
Map1.getMapParser().initDrawControls();
var editOverlay = Map1.getEditOverlay();
editOverlay.addFeatures(features);
Map1.getDynamicOverlay().redraw(true);
Map1.setDrawMode("Modify");
}
Vivek,
Sorry It seems i missed something, please try the below codes before getting the editOeverlay:
var parser = this.getMapParser();
if (!parser.editOverlay) {
parser.initDrawControls();
}
thanks,
Johnny
Thank you for reply,
I try your code,
But there is still same problem shape is copy on original shape
and after copy new shape we can edit copy shape not in original shape.
please reply as soon as posible
Vivek,
We try to recreate the “copy on original shape” issue but failed. Could you please tell us your scenario? Or a runnable sample is highly appreciate.
The attached files are out test codes based on our HowDoI sample => DrawEditShapes, please have a look.
Waiting for your feedback.
Thanks,
11502_javascript.txt (979 Bytes)
11502_server.txt (1.34 KB)
This is the scenario:
1) When I run my project there is one shape saved in my database so its display
2) When I click on this shape its select (Actually create a new copy)
3) Now I again click on that shape then its select (Select area of new copy)
4) When I drag that it see that actually copy is generated
So actually I can edit a newly created Shape not original one this is the problem…
Hello Vivek,
Thanks for the details. I can see what’s the issue here now. The reason is because here are two overlays in the map after the Edit callback. The one is the editoverlay and the other one is the ms sql overlay. So, The simplest way is we can set the MsSql2008FeatureLayer invisible in the EditShape action and we set it back to visible in the SaveMap action.
Here I attached two related files to show what I am saying and hope it can fix this issue.
Thanks,
Johnny
001_11502_Controller.txt (1.94 KB)
001_11502_View.txt (5.98 KB)
Hi Vivek,
I found out the root of the issue based on your codes. In the EditShapeNew action, the visible property apply to the new layer rather than the mssqlfeaturelayer stored in DynamicOverlay, which means it doesn’t affect the original Ms sql layer on the map. So, please modify the EditShapeNew action like the below:
<MapActionFilter()> _
Function EditShapeNew(ByVal map As Map, ByVal args As GeoCollection(Of Object)) As String
Try
Dim clickPosition As New PointShape(Convert.ToDouble(args(0)), Convert.ToDouble(args(1)))
Dim dynamicOverlay As LayerOverlay = DirectCast(map.CustomOverlays(“DynamicOverlay”), LayerOverlay)
Dim mssqlFeatureLayer As MsSql2008FeatureLayer = DirectCast(dynamicOverlay.Layers(“sql2008Layer”), MsSql2008FeatureLayer)
mssqlFeatureLayer.Open()
Dim editFeature As Feature
'Dim closestFeatures As Collection(Of Feature) = mssqlFeatureLayer.FeatureSource.GetFeaturesNearestTo(clickPosition, GeographyUnit.Meter, 5, New String() {})
Dim closestFeatures1 As Collection(Of Feature) = mssqlFeatureLayer.FeatureSource.GetAllFeatures(New String() {})
’ if we want to edit features within a range, we can pass a rectange shape rather than the click position to serve and then calling method “mssqlFeatureLayer.FeatureSource.GetFeaturesInsideBoundingBox” to get all the editing features
If closestFeatures1.Count > 0 Then
editFeature = closestFeatures1(0)
End If
If mssqlFeatureLayer.IsVisible = True Then
mssqlFeatureLayer.IsVisible = False
End If
Dim featureJson As String = MapHelper.ConvertFeaturesToJson(New Collection(Of Feature) From {editFeature})
mssqlFeatureLayer.Close()
Return featureJson
Catch ex As Exception
Return vbNull
End Try
End Function
Thank You So Much Johnny
Its work perfect
Can You give me some suggestion for below?
Whenever I click on any shape to edit all other shapes are hide due to our this code:
If mssqlFeatureLayer.IsVisible = True Then
mssqlFeatureLayer.IsVisible = False
End If
and then When I click on save again all shapes are visible.
So now is there any other way to do edit without hiding the layer???
Hi Vivek,
I think there is a workaround for your case, but this might bring a performance issue if the database stores a large number of records. Here is the details about the workaround:
1. In the view page, when we init the map, we use the inMemoryFeatureLayer instead of the MsSqlFeaturelayer. And we fill all the features from the MsSqlFeatureLayer into the inMemoryFeatureLayer.
2. In the EditShapeNew action, we also use the inMemoryFeatureLayer rather than MsSqlFeaturelayer. Then when we found the closest features, we remove those features from the inMemoryFeatureLayer without hiding the inMemoryFeatureLayer. Without hiding the layer will keep the other shapes in the inMemoryFeatureLayer are visible.
3. In the SaveShape action, we insert the edited features into inMemoryFeatureLayer and at the same time update those features in MsSqlFeaturelayer.
Hope you can understand what I mean.
If there is still any thing confused, feel free to let us know.
Thanks,
Johnny
Thank you very much Johnny for help…
Vivek,
You are welcome.
If any other questions, please feel free to let us know.
Thanks,
Johnny