The FeatureSlicer control allows user to draw a straight line with two end markers. Then User can move or stretch the line. When mouse hovers over closer to the line, position values can be reported to the user. This control exposes four key functions. Define onLineDrawn function if user wants to know when a line has been drawn. Define onLineStretched if user wants to know when a line has been stretched. Define onLineMoved function if user wants to know when a line has been moved. Define mouseoverLine function if user wants to know the line and mouse positions and the distance between the two when mouse hovers over the line or mouse is closer to the line within tolerance.toLine value.
Create a new control with the ALKMaps.Control.FeatureSlicer constructor. User can override some default options such as styles when calling the control constructor. It is only needed to add this control to the map control collection once. Then user can start or restart this control by calling activate function. After the control is activated, mouse up starts drawing the first marker, mouse move draws the line, and mouse up again finishes the drawing by adding the end marker. User can move the line by dragging the line. To stretch the line, user needs to drag any end marker of the line. Calling deactivate function will stop the control and remove user drawings as well as perform necessary clean up.
var ctlSlicer = new ALKMaps.Control.FeatureSlicer({ onLineDrawn: function(feature) { // Your code goes here. }, onLineStretched: function(feature){ // Your code goes here. }, onLineMoved: function(feature) { // Your code goes here. }, mouseoverLine: function(e) { // Your code goes here. } }); // A way to override some default options: var ctlSlicer = new ALKMaps.Control.FeatureSlicer({ tolerance: {toLine: 10, toLineEnd: 10}, // Both in pixels. nearTheLinePointerClass: "olDrawBox", overTheLineEndsPointerClass: "olControlFeatureSlicerOver", lineStyle: {strokeColor: "#ffff00", strokeWidth: 4}, lineEndStyle: {graphicName: "star", pointRadius: 8, strokeColor: "#000000", fillColor: "#ffffff", strokeWidth: 1, fillOpacity: 1 }, onLineDrawn: function(feature) { // Your code goes here. }, onLineStretched: function(feature){ // Your code goes here. }, onLineMoved: function(feature) { // Your code goes here. }, mouseoverLine: function(e) { // Your code goes here. } }); // User only needs to add this control the map control collection once. // Then user can start or restart this control by calling this activate function. ctlSlicer.activate(); // Stop the control. // Calling deactivate function will remove your drawings and perform necessary clean up. ctrlSlicer.deactivate();
ALKMaps. | The FeatureSlicer control allows user to draw a straight line with two end markers. |
Properties | |
citeCompliant | {Boolean} If set to true, coordinates of features drawn in a map extent crossing the date line won’t exceed the world bounds. |
documentDrag | {Boolean} If set to true, mouse dragging will continue even if the mouse cursor leaves the map viewport. |
layer | {ALKMaps.Layer.Vector} This is a temporary layer for drawing the line and line end markers. |
feature | {ALKMaps.Feature.Vector} |
dragCallbacks | {Object} The functions that are sent to the drag handler for callback. |
featureCallbacks | {Object} The functions that are sent to the feature handler for callback. |
lastPixel | {ALKMaps.Pixel} |
tolerance | {Object} Used to add nearTheLinePointerClass to the viewport when mouse hovers over the line or within the tolerance distance to the line and not within toLineEnd distance when mouses moves closer to one of the line end. |
nearTheLinePointerClass | {String} Style class name when mouse hovers over the line or within tolerance distance to the line. |
overTheLineEndsPointerClass | {String} Style class name when mouse hovers over line end markers. |
lineStyle | {Object} Line style. |
lineEndStyle | {Object} Line end markers style. |
onLineDrawn | {Function} Define this function if you want to know when a line has been drawn. |
onLineStretched | {Function} Define this function if you want to know when a line has been stretched. |
onLineMoved | {Function} Define this function if you want to know when a line has been moved. |
mouseoverLine | {Function} Define this function if you want to know the line and mouse positions and the distance between the two when mouse hovers over the line or mouse is closer to the line within tolerance.toLine value. |
enabled | {Boolean} When the control is active, set this to false to suspend its activities temporarily. |
Constructor | |
ALKMaps. | Create a new control to create the line which can be moved, or stretched later. |
Functions | |
destroy | Take care of things that are not handled in superclass |
activate | Activate the control and the feature handler. |
deactivate | Deactivate the control and all handlers. |
{ALKMaps.Layer.Vector} This is a temporary layer for drawing the line and line end markers. When the control is active, the layer will be added to the map. It will be removed when the control is deactivated.
{Object} Used to add nearTheLinePointerClass to the viewport when mouse hovers over the line or within the tolerance distance to the line and not within toLineEnd distance when mouses moves closer to one of the line end.
{ toLine: 10, // Default 10 pixels. toLineEnd: 10, // Default 10 pixels. }
{Function} Define this function if you want to know when a line has been drawn. The function should expect to receive one argument: the feature that has been drawn.
feature | {ALKMaps.Feature.Vector} The feature that has been drawn. The feature.geometry.CLASS_Name is “ALKMaps.Geometry.LineString”. |
feature: { geometry: { bounds: // ALKMaps.Bounds components: [ // ALKMaps.Geometry.Point ] } }
{Function} Define this function if you want to know when a line has been stretched. The function should expect to receive one argument: the feature that has been stretched.
feature | {ALKMaps.Feature.Vector} The feature that has been stretched. The feature.geometry.CLASS_Name is “ALKMaps.Geometry.LineString>”. |
{Function} Define this function if you want to know when a line has been moved. The function should expect to receive one argument: the feature that has been moved.
feature | {ALKMaps.Feature.Vector} The feature that has been stretched. The feature.geometry.CLASS_Name is “ALKMaps.Geometry.LineString”. |
{Function} Define this function if you want to know the line and mouse positions and the distance between the two when mouse hovers over the line or mouse is closer to the line within tolerance.toLine value. The function should expect to receive one argument.
dist | {Object} |
{ x0: -10234174.979102623, // closest x position on the line to the mouse x1: -10232777.849169, // mouse x position y0: 3487289.012295028, // closese y position on the line to the mouse y1: 3487362.9779974, // mouse y position distance: 1399.086479297978 // distance between the mouse the point on the line }
Take care of things that are not handled in superclass
destroy: function()
Activate the control and the feature handler.
activate: function()
Deactivate the control and all handlers.
deactivate: function()