Show measurement tooltip on geometry change instead of relying on pointermove
This commit is contained in:
+20
-9
@@ -103,27 +103,19 @@ var pointerMoveHandler = function(evt) {
|
|||||||
}
|
}
|
||||||
/** @type {string} */
|
/** @type {string} */
|
||||||
var helpMsg = 'Click to start drawing';
|
var helpMsg = 'Click to start drawing';
|
||||||
/** @type {ol.Coordinate|undefined} */
|
|
||||||
var tooltipCoord = evt.coordinate;
|
|
||||||
|
|
||||||
if (sketch) {
|
if (sketch) {
|
||||||
var output;
|
|
||||||
var geom = (sketch.getGeometry());
|
var geom = (sketch.getGeometry());
|
||||||
if (geom instanceof ol.geom.Polygon) {
|
if (geom instanceof ol.geom.Polygon) {
|
||||||
output = formatArea(/** @type {ol.geom.Polygon} */ (geom));
|
|
||||||
helpMsg = continuePolygonMsg;
|
helpMsg = continuePolygonMsg;
|
||||||
tooltipCoord = geom.getInteriorPoint().getCoordinates();
|
|
||||||
} else if (geom instanceof ol.geom.LineString) {
|
} else if (geom instanceof ol.geom.LineString) {
|
||||||
output = formatLength( /** @type {ol.geom.LineString} */ (geom));
|
|
||||||
helpMsg = continueLineMsg;
|
helpMsg = continueLineMsg;
|
||||||
tooltipCoord = geom.getLastCoordinate();
|
|
||||||
}
|
}
|
||||||
measureTooltipElement.innerHTML = output;
|
|
||||||
measureTooltip.setPosition(tooltipCoord);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
helpTooltipElement.innerHTML = helpMsg;
|
helpTooltipElement.innerHTML = helpMsg;
|
||||||
helpTooltip.setPosition(evt.coordinate);
|
helpTooltip.setPosition(evt.coordinate);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -172,10 +164,28 @@ function addInteraction() {
|
|||||||
createMeasureTooltip();
|
createMeasureTooltip();
|
||||||
createHelpTooltip();
|
createHelpTooltip();
|
||||||
|
|
||||||
|
var listener;
|
||||||
draw.on('drawstart',
|
draw.on('drawstart',
|
||||||
function(evt) {
|
function(evt) {
|
||||||
// set sketch
|
// set sketch
|
||||||
sketch = evt.feature;
|
sketch = evt.feature;
|
||||||
|
|
||||||
|
/** @type {ol.Coordinate|undefined} */
|
||||||
|
var tooltipCoord = evt.coordinate;
|
||||||
|
|
||||||
|
listener = sketch.getGeometry().on('change', function(evt) {
|
||||||
|
var geom = evt.target;
|
||||||
|
var output;
|
||||||
|
if (geom instanceof ol.geom.Polygon) {
|
||||||
|
output = formatArea(/** @type {ol.geom.Polygon} */ (geom));
|
||||||
|
tooltipCoord = geom.getInteriorPoint().getCoordinates();
|
||||||
|
} else if (geom instanceof ol.geom.LineString) {
|
||||||
|
output = formatLength( /** @type {ol.geom.LineString} */ (geom));
|
||||||
|
tooltipCoord = geom.getLastCoordinate();
|
||||||
|
}
|
||||||
|
measureTooltipElement.innerHTML = output;
|
||||||
|
measureTooltip.setPosition(tooltipCoord);
|
||||||
|
});
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
draw.on('drawend',
|
draw.on('drawend',
|
||||||
@@ -187,6 +197,7 @@ function addInteraction() {
|
|||||||
// unset tooltip so that a new one can be created
|
// unset tooltip so that a new one can be created
|
||||||
measureTooltipElement = null;
|
measureTooltipElement = null;
|
||||||
createMeasureTooltip();
|
createMeasureTooltip();
|
||||||
|
ol.Observable.unByKey(listener);
|
||||||
}, this);
|
}, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user