java - GWT openlayers,DrawFeature 线条样式

标签 java gwt openlayers gwt-openlayers

我正在使用 gwt openlayers 在 map 上绘制一些线串。我想更改绘制要素线的外观。我注意到 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 线的外观?

最佳答案

如果草图的样式(完成之前的特征)由执行绘图(点、路径或多边形)的处理程序负责。

所以要设计你所做的草图:

    //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();

我还在她的展示中添加了一个示例:http://demo.gwt-openlayers.org/gwt_ol_showcase/GwtOpenLayersShowcase.html?example=DrawFeature%20style%20example

关于java - GWT openlayers,DrawFeature 线条样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20162191/

相关文章:

java - Hibernate 整数的跨字段验证?

java - 当我按下按钮时,如何在另一个 Activity 中创建一个新的 TextView?

java - 为什么 ArrayList<>.add() 不起作用?

GWT - 发出 GET 请求

javascript - openlayers 3 簇中的字体大小

java 窥孔优化初学者编译器

gwt - 文件路径 gwt 应用程序托管模式

gwt - 如何获取 Canvas 的宽度/高度?

javascript - 使用 OpenLayers,删除标记层和弹出窗口的正确方法是什么?

openlayers - 可以在 openlayer 中使用 nokia here REST map API 吗?