-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Line arrows example #3343
Line arrows example #3343
Conversation
Thanks for any review |
* @template T | ||
* @api | ||
*/ | ||
ol.geom.LineString.prototype.forEachSegments = function(callback) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
forEachSegments
-> forEachSegment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, will change
Note: an icon is used for the arrow but it should be possible to use a |
@elemoine @tsauerwein: any other comments? |
No more objections from my side. |
Looking again… |
It looks good to me. I just note that the style function will generate a lot of garbage if there is a lot of lines and segments. I know that this is not a problem in that particular example, but it would be good to always show good practices to users. Instead of So with this your example's style function could look like this: var lineStyle = new ol.style.Style({
stroke: new ol.style.Stroke({
// …
})
});
var arrowStyle = new ol.style.Style({
image: new ol.style.Icon({
// …
})
});
function styleFunction(feature, resolution, callback) {
callback(lineStyle);
feature.getGeometry().forEachSegment(function(start, end) {
var dx = end[0] - start[0];
var dy = end[1] - start[1];
var rotation = Math.atan2(dy, dx);
arrowStyle.setGeometry(new ol.geom.Point(end));
arrowStyle.getImage().setRotation(-rotation);
callback(arrowStyle);
});
} Note something to do in this PR, but as a separate PR possibly. |
Thanks for the review |
Add an example than shows how to draw arrows to a linestring (end of each segment)