Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed issue in unregistering editable extension.
- Loading branch information
Showing
3 changed files
with
126 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
src/test/java/org/vaadin/addon/leaflet/demoandtestapp/TogglingEditing.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
package org.vaadin.addon.leaflet.demoandtestapp; | ||
|
||
import com.vaadin.ui.Button; | ||
import com.vaadin.ui.Button.ClickEvent; | ||
import com.vaadin.ui.Button.ClickListener; | ||
import com.vaadin.ui.Component; | ||
import com.vaadin.ui.HorizontalLayout; | ||
import com.vaadin.ui.Notification; | ||
import org.vaadin.addon.leaflet.*; | ||
import org.vaadin.addon.leaflet.editable.FeatureModifiedEvent; | ||
import org.vaadin.addon.leaflet.editable.FeatureModifiedListener; | ||
import org.vaadin.addon.leaflet.editable.LEditable; | ||
import org.vaadin.addon.leaflet.shared.Point; | ||
import org.vaadin.addonhelpers.AbstractTest; | ||
import org.vaadin.viritin.layouts.MHorizontalLayout; | ||
|
||
public class TogglingEditing extends AbstractTest implements | ||
FeatureModifiedListener { | ||
|
||
private LPolygon polygon; | ||
|
||
@Override | ||
public String getDescription() { | ||
return "Test leaflet draws editing feature"; | ||
} | ||
|
||
private LMap leafletMap; | ||
private LEditable lEditing; | ||
|
||
@Override | ||
public Component getTestComponent() { | ||
leafletMap = new LMap(); | ||
leafletMap.setCustomInitOption("editable", true); | ||
leafletMap.setHeight("300px"); | ||
leafletMap.setCenter(0, 0); | ||
leafletMap.setZoomLevel(0); | ||
leafletMap.addLayer(new LTileLayer( | ||
"http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png")); | ||
|
||
|
||
polygon = new LPolygon(new Point(0, 0), new Point(30, 30), | ||
new Point(30, 0)); | ||
|
||
leafletMap.addComponents(polygon); | ||
|
||
leafletMap.addClickListener(new LeafletClickListener() { | ||
|
||
@Override | ||
public void onClick(LeafletClickEvent event) { | ||
System.out.println("Clicked"); | ||
} | ||
}); | ||
|
||
return leafletMap; | ||
} | ||
|
||
@Override | ||
protected void setup() { | ||
super.setup(); | ||
|
||
HorizontalLayout tools = new MHorizontalLayout(); | ||
|
||
for (final Component c : leafletMap) { | ||
if (c instanceof AbstractLeafletVector) { | ||
Button button = new Button("Edit" | ||
+ c.getClass().getSimpleName()); | ||
button.addClickListener(new ClickListener() { | ||
|
||
@Override | ||
public void buttonClick(ClickEvent event) { | ||
if (lEditing != null && lEditing.getParent() != null) { | ||
lEditing.remove(); | ||
} | ||
lEditing = new LEditable((AbstractLeafletVector) c); | ||
lEditing.addFeatureModifiedListener(new FeatureModifiedListener() { | ||
|
||
@Override | ||
public void featureModified( | ||
FeatureModifiedEvent event) { | ||
Notification.show("Modified :" + ((AbstractLeafletVector) c).getGeometry().toText()); | ||
} | ||
}); | ||
} | ||
}); | ||
tools.addComponent(button); | ||
} | ||
} | ||
|
||
tools.addComponent(new Button("Stop editing", | ||
new Button.ClickListener() { | ||
@Override | ||
public void buttonClick(ClickEvent event) { | ||
if (lEditing.getParent() != null) { | ||
lEditing.remove(); | ||
} | ||
} | ||
})); | ||
|
||
tools.addComponent(new Button("Add hole", | ||
new Button.ClickListener() { | ||
@Override | ||
public void buttonClick(ClickEvent event) { | ||
lEditing = new LEditable(polygon); | ||
lEditing.newHole(); | ||
leafletMap.zoomToContent(polygon); | ||
} | ||
})); | ||
|
||
content.addComponent(tools); | ||
|
||
leafletMap.setSizeFull(); | ||
content.setExpandRatio(leafletMap, 1); | ||
|
||
} | ||
|
||
@Override | ||
public void featureModified(FeatureModifiedEvent event) { | ||
Notification.show("Edited" | ||
+ event.getModifiedFeature().getClass().getSimpleName()); | ||
} | ||
} |