I saw the example Draggable labels: wiki.thinkgeo.com/wiki/Map_S…ng_Samples
This project will be later completed to show how to save the state of the dragged labels from the SimpleMarkerOverlay and reload them.
However I did not see anything related to this (saving the states of dragged labels for reloading) in the source code? should I download all the source code to see that part of codes?
Or is there another example for saving such states?
Thanks,
State saving for example Draggable labels to reload?
Hi Guangming,
It’s easy to save status back. You can just loop all marker and assign their new position back to feature.
In the sample we use marker to show label and data is saved in shape file. So each time you reload the map, the label should show in the point location.
If your scenario have a special label layer, for example, your data layer is “MajorCities.shp” and your label layer is “MajorCitiesLabel.shp”, you can use the following code to adjust your label.
This code will get new location from marker and assign it back to label shape file.
private void wpfMap1_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
LayerOverlay layerOverlay = wpfMap1.Overlays[“LayerOverlay”] as LayerOverlay;
ShapeFileFeatureLayer labelLayer = layerOverlay.Layers[“labelLayer”] as ShapeFileFeatureLayer;
labelLayer.Open();
labelLayer.FeatureSource.BeginTransaction();
SimpleMarkerOverlay simpleMarkerOverlay = wpfMap1.Overlays[“SimpleMarkerOverlay”] as SimpleMarkerOverlay;
foreach (Marker marker in simpleMarkerOverlay.Markers)
{
Feature feature = labelLayer.FeatureSource.GetFeatureById(marker.Tag as string, ReturningColumnsType.NoColumns);
PointShape tmpPoint = new PointShape(marker.Position.X, marker.Position.Y);
tmpPoint.Id = feature.Id;
Feature tmpFeature = new Feature(tmpPoint, feature.ColumnValues);
labelLayer.FeatureSource.UpdateFeature(tmpFeature);
}
labelLayer.FeatureSource.CommitTransaction();
labelLayer.Close();
}
Please modify it and make it works in your project, wish that’s helpful.
Regards,
Don
great, thanks. In my case, the label layer would be just in memory with the current session and the label location change is user specific and no need to save back to the server.
Thanks,
I want to ask a related question: The print function will take these changed locations of the labels and print them out? no extra codes are needed to manipulate printing functions?
Thanks,
Hi GuangMing,
I think the marker should be print correct after you moved it.
But if it won’t work well, you can try setting it back to label layer and clear all markers after label layer show.
Regards,
Don