Hi,
I would like to select features one by one using a combination of CTRL+Left Mouse Button. This obviously require the map’s edit mode to be POINT. How would I go about doing that?
Thanks,
Chris
Selecting multiple features using CTRL key + left mouse button
Hi Chris,
In order to make sure we can select the features on client side, we have to make sure the features are vectors layer rather than Image layer. Currently, only the EditOverlay and HighlightOverlay are vector layers in client side. The below codes show how to select multi features on a editOverlay with SelectFeature control, please check it:
Server side:
Map1.EditOverlay.Features.Add(“Polygon”, new Feature(BaseShape.CreateShapeFromWellKnownData(“POLYGON((10 60,40 70,30 85, 10 60))”)));
Map1.EditOverlay.Features.Add(“Multipoint”, new Feature(BaseShape.CreateShapeFromWellKnownData(“MULTIPOINT(12 20, 30 20,40 20, 12 30, 30 30, 40 30)”)));
Map1.EditOverlay.Features.Add(“Line”, new Feature(BaseShape.CreateShapeFromWellKnownData(“LINESTRING(60 60, 70 70,75 60, 80 70, 85 60,95 80)”)));
Map1.EditOverlay.Features.Add(“Rectangle”, new Feature(new RectangleShape(65, 30, 90, 15)));
Client Side:
var selectControl;
function disableSelectControl() {
if (selectControl) {
selectControl.deactivate();
}
}
function enableSelectControl() {
Map1.SetDrawMode(‘Normal’);
var olMap = Map1.GetOpenLayersMap();
if (olMap.getLayersByName(“EditOverlay”).length > 0 && selectControl == null) {
selectControl = new OpenLayers.Control.SelectFeature(olMap.getLayersByName(“EditOverlay”)[0], {
toggleKey: “shiftKey”, //shift key removes from selection
multipleKey: “ctrlKey”, // ctrl key adds to selection
box: true
});
olMap.addControl(selectControl);
selectControl.activate();
}
}
Of course you can add any Vector layers to selectFeature Control. More details on Vector Layer, please refer to dev.openlayers.org/releases/OpenLayers-2.13.1/doc/apidocs/files/OpenLayers/Layer/Vector-js.html
Any questions, please feel free to let us know.
Thanks,
Troy