hi…
Currently I am working with display google map and also with mssql2008 database. I want to add/edit shapes on that map. So, how can I add/edit with mssql2008featurelayer with my application and save shapes in database also. My application is in mvc3, if you have an example with this solution with mvc application please give.
Thanks & Regards
SAMIR
How can I add/edit shapes on google map at the time of working with mssql2008 database
Hi Samir,
Thanks for your post, would you please
use attached code in “DrawEditShapesController.txt” to replace “DrawEditShapesController.cs” in “InteractiveOverlays” in “Controllers” in “CSharp HowDoISamples Razor for Debug”
And
use attached code in “DrawEditShapesView.txt” to replace "DrawEditShapes.cshtml"in “InteractiveOverlays” in “Views” in "CSharp HowDoISamples Razor for Debug"
Here is a guiding vedio for your information:screencast.com/t/mXnKI11c
Hope it helps
Summer
DrawEditShapesView.txt (5.77 KB)
DrawEditShapesController.txt (1.72 KB)
hi… summer
Thank you for your reply. Here is my code which used but, I can’t edit or delete my shapes with this can you please help. And my code is in vb.
Reply as early as possible.
<mapactionfilter()>
Function EditShape(map As Map, args As GeoCollection(Of Object)) As String
Dim sqlLayer As New MsSql2008FeatureLayer(ConfigurationManager.ConnectionStrings(“Connection”).ToString, “TableName”, “TableId”)
sqlLayer.Open()
Dim featureIds As New Collection(Of String)() From { _
“1” _
}
Dim dynamicOverlay As LayerOverlay = map.CustomOverlays(“DynamicOverlay”)
Dim shapeLayer As MsSql2008FeatureLayer = dynamicOverlay.Layers(“sql2008Layer”)
shapeLayer.Open()
Dim featuresJson As String = MapHelper.ConvertFeaturesToJson(shapeLayer.FeatureSource.GetFeaturesByIds(featureIds, ReturningColumnsType.NoColumns))
sqlLayer.Close()
Return featuresJson
End Function
Thanks & regards
SAMIR </mapactionfilter()>
Hi Samir,
Thanks for your information, after EditShape(), then the shape should be displayed, then the displayed shape need to be clicked to edit it. After editing it, the save button should be clicked to save the edited shape to call “SaveMap()”. The save button is in following location:
if you have any more question , please feel free to let us know.
Best Regards
Summer
hi… summer
Yes you are right but, when I select any shape and then click on edit button it can’t display the image which you are given into the screen shot (Means, blue round image around the shape). So, I can’t edit it with given code in previous post.
Thanks & regards
SAMIR
Hi Samir,
After calling shapeLayer.FeatureSource.GetFeaturesByIds(featureIds, ReturningColumnsType.NoColumns), Would you please provide me the returned features’wkt for a further test.
Waiting for your further information
Summer
hi… summer
I can’t get return from the Return featuresJson. It gives null like “[]”. So, is there any error with my code. Please reply as early as possible.
Thanks & regards,
SAMIR
Hi Samir,
Would you please replace your code with attached code, now it should be displayed
Hope it helps
Summer
Post11480.txt (583 Bytes)
hi… summer
I already used that code with my application, but it also return blank "[]" with FeatureJson. There is some another problem, Can you please reply as early as possible.
Thanks & regards,
SAMIR
Hi Samir,
would you please try to use following code to get the wkt?
Feature a = shapeLayer.FeatureSource.GetFeaturesByIds(featureIds, ReturningColumnsType.NoColumns)[0];
a.GetWellKnownText();
if a is still null, then would you please check if there is a record whose column “TableId” has a value 1 in your table
another thing I am a little confused is that from the name “TalbeId”, it doesn’t seem to be a records id column.
we should use:
Dim sqlLayer As New MsSql2008FeatureLayer(ConfigurationManager.ConnectionStrings(“Connection”).ToString, “TableName”, RecordIDColumn)
Waiting for your further information.
Summer
hi… summer
Thank you once again,
Yes this is id column of my table. And I have used your code with
Feature a = shapeLayer.FeatureSource.GetFeaturesByIds(featureIds, ReturningColumnsType.NoColumns)[0];
a.GetWellKnownText();
But, it gives an error, which are given below : ArgumentOutOfRangeException was unhandled by user code
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
And my code after changed as per you code is here : Please reply as early as possible. If any changes required in this code
Function EditShape(map As Map, args As GeoCollection(Of Object)) As String
Dim sqlLayer As New MsSql2008FeatureLayer(ConfigurationManager.ConnectionStrings("Connection").ToString, "TableName", "Tableid")
sqlLayer.Open()
Dim featureIds As New Collection(Of String)() From { _
"1" _
}
Dim dynamicOverlay As LayerOverlay = map.CustomOverlays("DynamicOverlay")
Dim a As Feature = sqlLayer.FeatureSource.GetFeaturesByIds(featureIds, ReturningColumnsType.NoColumns)(0)
a.GetWellKnownText()
sqlLayer.Close()
Return a.ToString
End Function
Thanks & regards
SAMIR
Hi Samir,
Would you please export your data to a .sql file, and send it to us to restore your data on our sql server, then we could debug it deeper.
Waiting for your further information
Best Regards
Summer
Hi… summer
Thank you very much for your help summer. But, I can’t send the data, because of security can you please send me a solution for that as early as possible.
Thanks & regards
SAMIR
Hi Samir,
I guess it may be because the records with ids you provided don’t exist in the data table
Would you please try:
Dim sql2008Layer As New MsSql2008FeatureLayer(connectString, “TableName”, “featureIdColumn”)
sql2008Layer.Open()
Dim features As Collection(Of Feature) = sql2008Layer.FeatureSource.GetAllFeatures(ReturningColumnsType.AllColumns)
‘ using the featureIds value (copy from your web sample) to test with the below codes
Dim a As Feature = sqlLayer.FeatureSource.GetFeaturesByIds(featureIds, ReturningColumnsType.NoColumns)
Then, Following steps:
1.Make sure we can get all the features or the features is not empty.
2.Make sure the returned features’ id value can be searched on the “featureIdColumn” column in sql database records.
3.Make sure the “featureIds” collection exist in “featureIdColumn” column rather than a Guid value collection.
Just note again, please pay more attentions to the “featureIdColumn”,”featureIds”, and the actual value of the returned features’ id.
If there is still no feature returned, please let us know.
Another thing for your information is that actually we don’t need all your data to test but just your table structure and two or three records to test. It will be highly appreciated if your table structure and two or three records could be provided.
Thanks,
Summer
hi… summer
Thanks for your reply.
When I use this as per your suggestion :
Dim features As Collection(Of Feature) = sql2008Layer.FeatureSource.GetAllFeatures(ReturningColumnsType.AllColumns)
I got this error :
Value of type ‘System.Collections.ObjectModel.Collection(Of ThinkGeo.MapSuite.Core.Feature)’ cannot be converted to ‘ThinkGeo.MapSuite.Core.Feature’.
And more thing is that I clarify, In my table there is not any ‘autoincrement’ or ‘primary key’ columns. It is because of that I can’t edit map ?
Thanks & Regards,
SAMIR
Hi Samir,
Actually, there should be a field in the table, the field should play a role of identifier for record. In the following image there the field “recid” is playing this role, so that we could use :
Dim sql2008Layer As New MsSql2008FeatureLayer(connectString, TableName, “recid”);
Would you please check if there is a field in your talbe that is a identifier for record? If not, would you please try to add one?
Waiting for your further information.
Summer
hi…
Thanks for your reply. Can you please give the solution for this error when I use this as per your suggestion :
Dim features As Collection(Of Feature) = sql2008Layer.FeatureSource.GetAllFeatures(ReturningColumnsType.AllColumns)
I got this error :
Value of type ‘System.Collections.ObjectModel.Collection(Of ThinkGeo.MapSuite.Core.Feature)’ cannot be converted to ‘ThinkGeo.MapSuite.Core.Feature’.
As per your request I attached with this my database structure and some records from my db.
And one more thing is that, in your code which is given below. At the place of {“1”}, how can I get the featureid of shape on which user clicked for edit and how can I get this id ? Please, reply as early as possible.
Dim features As Collection(Of Feature) = sqlLayer.FeatureSource.GetAllFeatures(ReturningColumnsType.AllColumns)
Dim featureIds As New Collection(Of String)() From {“1”}
Dim a As Feature = sqlLayer.FeatureSource.GetFeaturesByIds(featureIds, ReturningColumnsType.NoColumns)(0)
Thanks & regards,
SAMIR
DB_Data.txt (2.37 KB)
Hi… summer
Can you please reply with solution as early as possible. Because my project is pending because of this issue.
Thanks & regards,
SAMIR
Samir,
We tested your data and seemed everything was fine on our end. the below is the watching view of features:
In our test codes, we created a table named “Test1” and we use the “geodb_oid” as the featureIdColumn, which will map to the feature id value.
As for the question how to get the featureIds, we can refer to the sample under HowDoI sample=> InteractiveMap=>AddAClickEvent. When we click on a feature on the map, we do a ajax call to the server with the current click position. In the server side, we handle the position to search a closest feature as the edit feature. Please have a look on the attached two files:HomeController.txt and View.txt.
Hope those will help.
Thanks,
HomeController.txt (2.19 KB)
View.txt (1.28 KB)
Hi… summer
I am using your code like this :
Dim clickPosition As New PointShape(Convert.ToDouble(args(0)), Convert.ToDouble(args(1)))
Dim connectionStr As String = ConfigurationManager.ConnectionStrings(“Connection”).ToString
Dim mssqlFeatureLayer As New MsSql2008FeatureLayer(connectionStr, “TableName”, “geodb_oid”) ’ The “geodb_oid” value is mapping the feature id value.
mssqlFeatureLayer.Open()
Dim editFeature As Feature
Dim closestFeatures As Collection(Of Feature) = mssqlFeatureLayer.FeatureSource.GetFeaturesNearestTo(clickPosition, GeographyUnit.DecimalDegree, 5, 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 closestFeatures.Count > 0 Then
editFeature = closestFeatures(0)
End If
Dim featureJson As String = MapHelper.ConvertFeaturesToJson(New Collection(Of Feature) From {editFeature})
Return featureJson
I got 2 count with “args As GeoCollection(Of Object)”.
But, I can’t get any value with this code : It gives “0”, if you have any solution for that. Please give me as early as possible. And one more thing is that can we get this with “GeographyUnit.Meter” or not ?
Dim closestFeatures As Collection(Of Feature) =
mssqlFeatureLayer.FeatureSource.GetFeaturesNearestTo(clickPosition,
GeographyUnit.DecimalDegree, 5, New String() {})
And I have one more question is that with following javascript function.
function editShapeCallback(result) {
debugger;
var features = Map1.getFeaturesFromJson(result.get_responseData());
var editOverlay = Map1.getEditOverlay(); /////////////////// It gives null value. Please give solution for that as early as possible.
editOverlay.addFeatures(features);
Map1.getDynamicOverlay().redraw(true);
Map1.setDrawMode(“Modify”);
}
Thanks & regards,
SAMIR