Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java GWT openlayers,DrawFeature线条样式_Java_Gwt_Openlayers_Gwt Openlayers - Fatal编程技术网

Java GWT openlayers,DrawFeature线条样式

Java GWT openlayers,DrawFeature线条样式,java,gwt,openlayers,gwt-openlayers,Java,Gwt,Openlayers,Gwt Openlayers,我正在使用gwt openlayers在地图上绘制一些线条。我想更改绘制要素线的外观。我注意到PathHandler类有setStyle方法,但使用此方法设置样式不会更改行外观 private DrawFeature createDrawFeature() { DrawFeatureOptions options = new DrawFeatureOptions(); options.onFeatureAdded(getStyle()); PathHandler hand

我正在使用gwt openlayers在地图上绘制一些线条。我想更改绘制要素线的外观。我注意到PathHandler类有setStyle方法,但使用此方法设置样式不会更改行外观

private DrawFeature createDrawFeature() {
    DrawFeatureOptions options = new DrawFeatureOptions();
    options.onFeatureAdded(getStyle());
    PathHandler handler = new PathHandler();
    handler.setStyle(style);
    return new DrawFeature(layer, handler, options );
}
private Style getStyle() {
    Style style = new Style();
    style.setStrokeColor("#ffffff");
    style.setStrokeWidth(2.0);
    return style;
}
我试图设置不同的样式选项,但没有效果。
有人知道如何更改DrawFeature line的外观吗?

如果草图(完成之前的特征)的样式不同,则绘制(点、路径或多边形)的处理程序负责

因此,要设置草图的样式,请执行以下操作:

    //Create a style. We want a blue dashed line.
    final Style drawStyle = new Style(); //create a Style to use
    drawStyle.setFillColor("white");
    drawStyle.setGraphicName("x");
    drawStyle.setPointRadius(4);
    drawStyle.setStrokeWidth(3);
    drawStyle.setStrokeColor("#66FFFF");
    drawStyle.setStrokeDashstyle("dash");

    //create a StyleMap using the Style
    StyleMap drawStyleMap = new StyleMap(drawStyle);

    //Create PathHanlderOptions using this StyleMap
    PathHandlerOptions phOpt = new PathHandlerOptions();
    phOpt.setStyleMap(drawStyleMap);   

    //Create DrawFeatureOptions and set the PathHandlerOptions (that have the StyleMap, that have the Style we wish)
    DrawFeatureOptions drawFeatureOptions = new DrawFeatureOptions();
    drawFeatureOptions.setHandlerOptions(phOpt);

    PathHandler pathHanlder = new PathHandler();

    // Create the DrawFeature control to draw on the map, and pass the DrawFeatureOptions to control the style of the sketch
    final DrawFeature drawLine = new DrawFeature(vectorLayer, pathHanlder, drawFeatureOptions);
    map.addControl(drawLine);
    drawLine.activate();

我还在she showcase中添加了一个示例:

谢谢,效果很好,但是最后一行呢(我的意思是画完之后)?它仍然有古老的淡橙色风格。好的,我找到了通过使用onFeatureAdded in drawfeature options public void onFeatureAdded(VectorFeature VectorFeature){VectorFeature.setStyle(getStyle());VectorFeature.redrawParent();}Falcon实现这一点的方法,这可能确实有效,但有点过分。您应该在vectorlayer上使用setStyle或setStyleMap方法。这样,只需在图层上设置一次样式。类似矢量层=新矢量(“矢量层”);最终样式drawStyle=新样式()//创建一个样式以使用drawStyle.setFillColor(“白色”);drawStyle.setGraphicName(“x”);drawStyle.设定点半径(4);拉深方式。设定行程宽度(3);drawStyle.setStrokeColor(“#66FFFF”);drawStyle.SetStrokedDashStyle(“短划线”);矢量图层设置样式(drawStyle);