Vector routeLayer = new Vector("route"); List<Point> pointList = new ArrayList<Point>(); Projection defaultProj = new Projection(DEFAULT_PROJECTION); // DEFAULT_PROJECTION = "EPSG:4326" Projection mapProj = new Projection(mapWidget.getMap().getProjection()); for (String coord : KML.split(" ")) { String[] xyz = coord.split(","); if (xyz.length == 3) { Point point = new Point(Double.parseDouble(xyz[0]), Double.parseDouble(xyz[1])); // lon,lat point.transform(defaultProj, mapProj); pointList.add(point); } } LineString geometry = new LineString(pointList.toArray(new Point[pointList.size()])); Style style = new Style(); style.setStrokeColor("#0033ff"); style.setStrokeWidth(5); routeLayer.addFeature(new VectorFeature(geometry, style)); mapWidget.getMap().addLayer(routeLayer);
/** * Creates the style. * * @return the style */ private Style createStyle() { Style style = new Style(); style.setStrokeColor("#000000"); style.setStrokeWidth(1); style.setFillColor("#FF0000"); style.setFillOpacity(0.5); style.setPointRadius(5); style.setStrokeOpacity(1.0); return style; }
//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();