我一直在关注本教程:http : //workshop.pgrouting.org/chapters/geoext_client.html#select-the-start-and-final-destination
它包含一个在以下代码示例中定义的Openlayers.Control.DrawFeatures控件。您还可以在作者评论的行中看到“如果要对起点应用特殊样式,则应在此处进行”。问题是:我不知道如何在此设置中应用样式,并且无法以这种方式使用DrawFeatures控件找到任何示例。
如何使用此DrawFeatures控件使起点使用与终点不同的样式?
DrawPoints = OpenLayers.Class(OpenLayers.Control.DrawFeature, {
// this control is active by default
autoActivate: true,
initialize: function(layer, options) {
// only points can be drawn
var handler = OpenLayers.Handler.Point;
OpenLayers.Control.DrawFeature.prototype.initialize.apply(
this, [layer, handler, options]
);
},
drawFeature: function(geometry) {
OpenLayers.Control.DrawFeature.prototype.drawFeature.apply(
this, arguments
);
if (this.layer.features.length == 1) {
// we just draw the startpoint
// note: if we want to apply a special style to the
// start point we should do this here
} else if (this.layer.features.length == 2) {
// we just draw the finalpoint
// note: if we want to apply a special style to the
// final point we should do this here
// we have all what we need; we can deactivate ourself.
this.deactivate();
}
}
});