GWTOpenLayers - Move point doesn't work

42 views
Skip to first unread message

Jostein

unread,
Mar 30, 2015, 5:53:05 AM3/30/15
to google-we...@googlegroups.com
Hi

The code below creates a map and shows a point. The button below the map "Move point" should move the point a few hundred meters, but the point just disappears. What am I missing here?

public class Maptest implements EntryPoint {
private static final Projection DEFAULT_PROJECTION = new Projection(
"EPSG:4326");
VectorFeature pointFeature;
Vector markerLayer;
public void onModuleLoad() {
MapOptions defaultMapOptions = new MapOptions();
MapWidget mapWidget = new MapWidget("500px", "500px", defaultMapOptions);
OSM osmMapnik = OSM.Mapnik("Mapnik");
OSM osmCycle = OSM.CycleMap("CycleMap");
//mapWidget.getMap().addControl(new LayerSwitcher());

osmMapnik.setIsBaseLayer(true);
osmCycle.setIsBaseLayer(true);

mapWidget.getMap().addLayer(osmMapnik);
mapWidget.getMap().addLayer(osmCycle);
markerLayer = new Vector("Marker layer");
mapWidget.getMap().addLayer(markerLayer);
LonLat lonLat = new LonLat(10.44136762, 63.39698564);
lonLat.transform("EPSG:4326", mapWidget.getMap().getProjection()); //transform lonlat (provided in EPSG:4326) to OSM coordinate system (the map projection)
mapWidget.getMap().setCenter(lonLat, 12);
// Tegner et punkt
Style pointStyle = new Style();
pointStyle.setFillColor("red");
pointStyle.setStrokeColor("green");
pointStyle.setStrokeWidth(2);
pointStyle.setFillOpacity(0.9);

final Point point = new Point(10.44136762, 63.39698564);
point.transform(DEFAULT_PROJECTION, new Projection(mapWidget
.getMap().getProjection())); // transform point to OSM
// coordinate system
pointFeature = new VectorFeature(point, pointStyle);
markerLayer.addFeature(pointFeature);
//pointId = point.getId();
Button b = new Button("Move point");
b.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
pointFeature.move(new LonLat(10.44215018, 63.35392463));
}
});
VerticalPanel v = new VerticalPanel();
v.add(mapWidget);
v.add(b);
RootLayoutPanel.get().add(v);
}
}

Ignacio Baca Moreno-Torres

unread,
Mar 30, 2015, 10:24:27 AM3/30/15
to google-we...@googlegroups.com
I think that you forget to transform the destination LonLat in the click handler as you did in the center point and the feature point.
Reply all
Reply to author
Forward
0 new messages