Revision d8487d07
Added by Andreas Kohlbecker over 5 years ago
src/main/java/eu/etaxonomy/cdm/vaadin/component/common/GeoLocationField.java | ||
---|---|---|
8 | 8 |
*/ |
9 | 9 |
package eu.etaxonomy.cdm.vaadin.component.common; |
10 | 10 |
|
11 |
import org.apache.commons.lang3.StringUtils; |
|
11 | 12 |
import org.apache.log4j.Logger; |
13 |
import org.vaadin.addon.leaflet.LCircle; |
|
12 | 14 |
import org.vaadin.addon.leaflet.LMap; |
13 | 15 |
import org.vaadin.addon.leaflet.LMarker; |
14 | 16 |
import org.vaadin.addon.leaflet.LOpenStreetMapLayer; |
17 |
import org.vaadin.addon.leaflet.LeafletClickEvent; |
|
15 | 18 |
|
16 | 19 |
import com.vaadin.data.fieldgroup.BeanFieldGroup; |
17 | 20 |
import com.vaadin.data.fieldgroup.FieldGroup; |
... | ... | |
52 | 55 |
|
53 | 56 |
private LMap map = new LMap(); |
54 | 57 |
private LMarker mapMarker = new LMarker(); |
58 |
private LCircle errorRadiusMarker = null; |
|
55 | 59 |
|
56 | 60 |
private CssLayout mapWrapper; |
57 | 61 |
|
... | ... | |
87 | 91 |
|
88 | 92 |
map = new LMap(); |
89 | 93 |
map.addBaseLayer(new LOpenStreetMapLayer(), null); |
90 |
map.setDraggingEnabled(false);
|
|
94 |
map.setDraggingEnabled(true);
|
|
91 | 95 |
map.setScrollWheelZoomEnabled(false); |
92 | 96 |
map.removeControl(map.getLayersControl()); |
97 |
map.addClickListener(e -> refreshMap(e)); |
|
98 |
// map.getZoomControl().addListener(ClickEvent.class, target, method); |
|
93 | 99 |
|
94 | 100 |
root.setColumnExpandRatio(2, 1.0f); |
95 | 101 |
root.setRowExpandRatio(1, 1.0f); |
... | ... | |
111 | 117 |
latitudeField.setBuffered(false); |
112 | 118 |
latitudeField.addValueChangeListener(e -> updateMap()); |
113 | 119 |
|
120 |
errorRadiusField.addValueChangeListener( e -> updateMap()); |
|
121 |
|
|
114 | 122 |
addStyledComponents(longitudeField, latitudeField, errorRadiusField, referenceSystemField, longLatParsed); |
115 | 123 |
addSizedComponent(root); |
116 | 124 |
|
... | ... | |
122 | 130 |
return root; |
123 | 131 |
} |
124 | 132 |
|
125 |
// /** |
|
126 |
// * @param longitudeField2 |
|
127 |
// * @param value |
|
128 |
// * @return |
|
129 |
// */ |
|
130 |
// private void updateParsedValue(TextField field, String value) { |
|
131 |
// field.setComponentError(null); |
|
132 |
// updateMap(); |
|
133 |
// } |
|
134 |
|
|
135 | 133 |
/** |
136 | 134 |
* |
137 | 135 |
*/ |
... | ... | |
139 | 137 |
// using the string representations for UI display |
140 | 138 |
longLatParsed.setValue(longitudeField.getValue() + "/" + latitudeField.getValue()); |
141 | 139 |
map.removeComponent(mapMarker); |
140 |
if(errorRadiusMarker != null){ |
|
141 |
map.removeComponent(errorRadiusMarker); |
|
142 |
} |
|
142 | 143 |
Double longitude = (Double) longitudeField.getConverter().convertToModel(longitudeField.getValue(), Double.class, null); |
143 | 144 |
Double latitude = (Double) latitudeField.getConverter().convertToModel(latitudeField.getValue(), Double.class, null); |
144 | 145 |
logger.debug("panning map to " + longitude + "/" + latitude); |
145 | 146 |
if(longitude != null && latitude != null){ |
146 | 147 |
map.setZoomLevel(10); |
148 |
if(!StringUtils.isEmpty(errorRadiusField.getValue())){ |
|
149 |
try{ |
|
150 |
double errorRadius = Double.parseDouble(errorRadiusField.getValue()); |
|
151 |
if(errorRadius > 0){ |
|
152 |
errorRadiusMarker = new LCircle(latitude, longitude, errorRadius); |
|
153 |
errorRadiusMarker.setColor("#ff0000"); |
|
154 |
errorRadiusMarker.setWeight(1); |
|
155 |
map.addComponents(errorRadiusMarker); |
|
156 |
} |
|
157 |
} catch(Exception e){ /* IGNORE */ } |
|
158 |
} |
|
147 | 159 |
mapMarker.setPoint(new org.vaadin.addon.leaflet.shared.Point(latitude, longitude)); |
148 | 160 |
map.addComponents(mapMarker); |
149 | 161 |
map.setCenter(latitude, longitude); |
... | ... | |
153 | 165 |
} |
154 | 166 |
} |
155 | 167 |
|
168 |
protected void refreshMap(LeafletClickEvent e) { |
|
169 |
logger.debug("map click"); |
|
170 |
} |
|
171 |
|
|
156 | 172 |
/** |
157 | 173 |
* {@inheritDoc} |
158 | 174 |
*/ |
Also available in: Unified diff
fix #7916 visualizing the error radius in the GeolocationField map