Let's follow the component's self-explaining name to try out it behaviour :
ol.interaction.defaults sample.interactions block in the ol.Map object as follows:var map = new ol.Map({
...
interactions: ol.interaction.defaults({
shiftDragZoom: false
}).extend([new ol.interaction.DragRotateAndZoom()]),
...
});First, as it can conflict with ol.interaction.DragRotateAndZoom, we deactivated the shiftDragZoom interaction by setting it to false. We chose this option, but it was also possible to change the key to activate the function using the condition property.
You also saw the now-common pattern to add interactions to existing default interaction using an array within the extend block. Practically, you also learned how to use the behavior.
Now, let's jump to the next interaction.
This interaction, according to the official documentation API, is for handling input of vector data by drag and drop. We already saw an example of using this in Chapter 5, Using Vector Layers.
The only additional thing that you can add is that when you drop the file after dragging it, when the event is triggered, you can get not only the features or their projection (experimental), but you can also get the filename. It can be useful, for example, to give a name to the layer, imagining we use the component together with a layer tree.
How did we deduce that it was also possible to retrieve this information? We did this simply by inspecting the API at http://openlayers.org/en/v3.0.0/apidoc/ol.interaction.DragAndDrop.html. It mentions the function signature when an event is fired, as follows:
addfeatures(ol.interaction.DragAndDropEvent).You can see that ol.interaction.DragAndDropEvent is involved. If you inspect its API definition, you will see and not be really surprised to discover members are features, files, and projections.
Just as a quick reminder, here are the DragAndDrop options (experimental):
|
Name |
Type |
Description |
|---|---|---|
|
|
|
These are the format constructors. |
|
|
|
This is the target projection. By default, the map's view's projection is used. |
Now, let's continue with another interaction implying always a drag-related event.
The official documentation describes this interaction as:
"Allowing the user to zoom the map by clicking and dragging on the map, normally combined with an ol.events.condition that limits it to when the Shift key is held down."
When reviewing ol.interaction.DragBox and seeing that it's the base class for ol.interaction.DragZoom, we already give you some hints for other use cases based on the same logic. It can be to select features based on a rectangular selection, to draw a rectangle, or to use it as a bounding box to generate and draw other shapes, such as ellipsoids and circles.
Let's look at how you can, for example, get the drawn rectangle as a GeoJSON string, where you've done a selection. Here, we suppose you are working on your desktop as mouse interaction is not available with mobile devices.