Hi,
The web client API has a function named "CancelLatestFeature". This is great for an undo function in the client.
However, is there a similar function or functionality to enable deleting an arbitray feature in editOverlay client-side ?
Cheers.
Hi,
The web client API has a function named "CancelLatestFeature". This is great for an undo function in the client.
However, is there a similar function or functionality to enable deleting an arbitray feature in editOverlay client-side ?
Cheers.
Hi Lars,
I think you could simply write a function called “RemoveAFeature” in your client side Javascript code to remove a feature from the EditOverlay. The code could be like this:
function RemoveAFeature() {
// i is the index of the feature you want to remove.
var editLayer = tempMap.getLayersByName('EditOverlay');
editLayer[0].removeFeatures(editLayer[0].features[i]);
}
Hope this helps and any more questions please let us know.
Thanks,
Sun
Hi Sun,
Thanks. Ok, it's possible. But how to tie this in with what the user selects ?
When the user selects a specific feature for editing, is there a way in the client interface to retrieve the id of that feature ? Without the id, I'm unable to delete the right (i.e. selected) feature.
Or is there an event that fires whenever the user selects a feature for editing ?
Cheers.
Lars I,
We could implement this in two ways, one is to register a event "featureselected", and another one is to implement callback function onSelect which will be called when a feature is selected. The code maybe like below:
var olMap;
var removeFeature, editLayer;
var OnMapCreated = function(map) {
olMap = map;
}
function addPolygon() {
Map1.SetDrawMode("Polygon");
editLayer = olMap.getLayersByName('EditOverlay')[0];
editLayer.events.register("featureselected", this, featureSelected);
}
function deletePolygon() {
removeFeature = new OpenLayers.Control.SelectFeature(editLayer, { onSelect: deleteFeature });
olMap.addControl(removeFeature);
removeFeature.activate();
}
function featureSelected(featureObject) {
alert("featureSelected");
alert(featureObject.feature.id);
}
function deleteFeature(feature) {
alert("deleteFeature");
alert(feature.id);
editLayer.removeFeatures(feature);
feature.destroy();
}
Thanks,
Johnny
Ho Johnny,
Thanks, it works - almost. I'm still trying to wrap my head around how to use OpenLayers in the Map Suite wrapper, and your example is great and informative.
However, there seems to be a problem with deleting the last feature in the editLayer. I don't know whether it's some hitch in OpenLayers or Map Suite, but I just wanted to mention it.
I suppose I can test for the number of features left in the editLayer, and do a "layer clean" instead of a delete if only one feature is left. I don't know whether it'll do the trick, but it's worth a try.
Cheers.
Lars I,
If you want to delete the last feature in the EditOverlay, you could refer to the DrawEditShapes sample in our installed samples which you can find its source code at “Samples\MapShapes\DrawEditShapes.aspx”. You just need to call CancelLatestFeature function of Map1 object, Map1 is the ID of map control.
Thanks,
Khalil
HI all,
Sorry about this, it was my server-side processing that bugged me out :-/
No worries then after all :-)
Hi again,
Ah worries after all. It still doesn't work !
I've tried both removeFeatures(), destroyFeatures() _and_ CancelLatestFeature(), and neither of them works !
I'm having my JS routine tell me the number of features before and after the deletion, and it reports the correct number. And the display looks good, deleted features are removed. But whenever I post back (i.e. save) to the server, all features are suddenly present in the Map1.EditOverlay.Features collection, and the collection count is not zero.
And your own sample doesn't work either. If I digitize two polygons, save them, edit them and click "delete shape" twice, both features are gone from the display. If I then do a save, both features are restored to the display ! If I only delete one, and save, it's gone, just as I'm experiencing in my own app.
I'm running Firefox 3.5.7, but I don't think that ought to matter.
Thanks.
Lars I,
Thank you for handing in this issue, we have fixed it since last public released. Here is a workaround for you temporarily. Please see the attachment, and paste it after the opening tag of form.
Any more questions please let me know.
Thanks,
Khalil
1730-SynchronizeFeatures.txt (1.88 KB)
Thanks Khalil, but it does seem unreasonably complicated.
What's the overall idea and purpose of this work-around, and what is "MultiMap" a reference to ??
Thanks.
Lars I,
“MultiMap” is an array which is defined in our WebEdition client-api and contains client ids for all map controls in one page. For example, if you have two map controls which have id of “Map1” and “Map2” respectively in one page, so “MultiMap” will be “[‘Map1’,‘Map2’’]”.
And the overall idea and purpose of this workaround is to synchronise the EditOverlay of Map control on the client side and server side. This issue is caused by that when you have clicked “delete shape” twice, both features are gone from the display on the client side but they are still exist on the server side, so then do a save, both features are restored to the display. You need to synchronise between client and server when you submit the form. We implement this through hidden filed which contains all features of editOverlay.
Thanks,
Khalil