openlayers ol-ext 如何排除变换中的特征
openlayers ol-ext how to exclude features on transform
我有一个绘图工具,它使用来自 ol-ext 的转换交互。有没有办法从变换中排除某些形状?例如,我想排除转换 LineString。
transformInteraction = new interaction.Transform({
features: this.props.drawnShapes, // null at initialization
layers: map.getLayers().getArray().filter(l => l.get("transformable")),
hitTolerance: 5,
translateFeature: true,
translate: true,
keepAspectRatio: events.condition.shiftKeyOnly,
rotate: true
});
或者有没有办法在初始化后设置可变形特征?
您只需要在 ol.interaction.Transform
对象构造函数中使用 filter
键。 http://viglino.github.io/ol-ext/examples/interaction/map.interaction.transform.html 的源代码摘录向您展示了如何使用它来限制作业以排除行。
var interaction = new ol.interaction.Transform (
{ addCondition: ol.events.condition.shiftKeyOnly,
// filter: function(f,l) { return f.getGeometry().getType()==='Polygon'; },
// layers: [vector],
hitTolerance: 2,
translateFeature: $("#translateFeature").prop('checked'),
scale: $("#scale").prop('checked'),
rotate: $("#rotate").prop('checked'),
keepAspectRatio: $("#keepAspectRatio").prop('checked') ? ol.events.condition.always : undefined,
translate: $("#translate").prop('checked'),
stretch: $("#stretch").prop('checked')
});
我有一个绘图工具,它使用来自 ol-ext 的转换交互。有没有办法从变换中排除某些形状?例如,我想排除转换 LineString。
transformInteraction = new interaction.Transform({
features: this.props.drawnShapes, // null at initialization
layers: map.getLayers().getArray().filter(l => l.get("transformable")),
hitTolerance: 5,
translateFeature: true,
translate: true,
keepAspectRatio: events.condition.shiftKeyOnly,
rotate: true
});
或者有没有办法在初始化后设置可变形特征?
您只需要在 ol.interaction.Transform
对象构造函数中使用 filter
键。 http://viglino.github.io/ol-ext/examples/interaction/map.interaction.transform.html 的源代码摘录向您展示了如何使用它来限制作业以排除行。
var interaction = new ol.interaction.Transform (
{ addCondition: ol.events.condition.shiftKeyOnly,
// filter: function(f,l) { return f.getGeometry().getType()==='Polygon'; },
// layers: [vector],
hitTolerance: 2,
translateFeature: $("#translateFeature").prop('checked'),
scale: $("#scale").prop('checked'),
rotate: $("#rotate").prop('checked'),
keepAspectRatio: $("#keepAspectRatio").prop('checked') ? ol.events.condition.always : undefined,
translate: $("#translate").prop('checked'),
stretch: $("#stretch").prop('checked')
});