gl = new ArrayList<>();
87 | for (Component c : this) {
88 | LeafletLayer l = (LeafletLayer) c;
89 | gl.add(l.getGeometry());
90 | }
91 | return new GeometryFactory().buildGeometry(gl);
92 | }
93 |
94 | @Override
95 | public void bringToFront() {
96 | getRpcProxy(ILayerClientRpc.class).bringToFront();
97 | }
98 |
99 | @Override
100 | public void bringToBack() {
101 | getRpcProxy(ILayerClientRpc.class).bringToBack();
102 | }
103 |
104 | }
105 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/LOpenStreetMapLayer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Vaadin Community.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.vaadin.addon.leaflet;
18 |
19 | /**
20 | * A layer that uses OSM tiles.
21 | *
22 | * Be sure to check if your usage comforts to their usage policy. For more
23 | * serious usage, you should most likely buy TMS service e.g. from mapbox.com.
24 | */
25 | public class LOpenStreetMapLayer extends LTileLayer {
26 |
27 | public LOpenStreetMapLayer() {
28 | super("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png");
29 | setAttributionString("Map data © OpenStreetMap contributors");
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/LPolygon.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet;
2 |
3 | import org.locationtech.jts.geom.Geometry;
4 | import org.locationtech.jts.geom.Polygon;
5 | import org.vaadin.addon.leaflet.shared.LeafletPolylineState;
6 | import org.vaadin.addon.leaflet.jsonmodels.PointArray;
7 | import org.vaadin.addon.leaflet.jsonmodels.PointMultiArray;
8 | import org.vaadin.addon.leaflet.shared.Point;
9 | import org.vaadin.addon.leaflet.util.JTSUtil;
10 |
11 | import java.util.Arrays;
12 | import java.util.List;
13 | import static org.vaadin.addon.leaflet.util.JTSUtil.toLeafletPointArray;
14 |
15 | public class LPolygon extends AbstractLeafletVector {
16 |
17 | private PointMultiArray points = new PointMultiArray();
18 |
19 | @Override
20 | protected LeafletPolylineState getState() {
21 | return (LeafletPolylineState) super.getState();
22 | }
23 |
24 | public LPolygon(Point... points) {
25 | setPoints(points);
26 | }
27 |
28 | public LPolygon(Polygon polygon) {
29 | setGeometry(polygon);
30 | }
31 |
32 | public LPolygon setGeometry(Polygon polygon) {
33 | setGeometryWithoutRepaint(polygon);
34 | markAsDirty();
35 | return this;
36 | }
37 |
38 | /**
39 | * Sets the geometry without triggering repaint on the client side. Can be used
40 | * by add-ons that modify vector on the client side
41 | *
42 | * @param polygon the geometry
43 | */
44 | public void setGeometryWithoutRepaint(Polygon polygon) {
45 | Point[] exterior = toLeafletPointArray(polygon.getExteriorRing());
46 | PointMultiArray pointMultiArray = new PointMultiArray();
47 | pointMultiArray.add(new PointArray(exterior));
48 | for (int i = 0; i < polygon.getNumInteriorRing(); i++) {
49 | pointMultiArray.add(new PointArray(toLeafletPointArray(polygon.getInteriorRingN(i))));
50 | }
51 | points = pointMultiArray;
52 | }
53 |
54 | @Override
55 | public void beforeClientResponse(boolean initial) {
56 | super.beforeClientResponse(initial);
57 | getState().geometryjson = points.asJson();
58 | }
59 |
60 | public void setPoints(Point... array) {
61 | PointArray outerbounds = new PointArray(Arrays.asList(array));
62 | if (points.size() == 0) {
63 | points.add(outerbounds);
64 | } else {
65 | points.set(0, outerbounds);
66 | }
67 | markAsDirty();
68 | }
69 |
70 | public LPolygon setPointsAndholes(Point[][] pointsAndHoles) {
71 | points = new PointMultiArray();
72 | for (int i = 0; i < pointsAndHoles.length; i++) {
73 | Point[] pa = pointsAndHoles[i];
74 | points.add(new PointArray(pa));
75 | }
76 | markAsDirty();
77 | return this;
78 | }
79 |
80 | public Point[] getPoints() {
81 | PointArray outerRing = points.get(0);
82 | return outerRing.toArray(new Point[outerRing.size()]);
83 | }
84 |
85 | @Override
86 | public Geometry getGeometry() {
87 | return JTSUtil.toPolygon(this);
88 | }
89 |
90 | public LPolygon addHole(Point... hole) {
91 | points.add(new PointArray(hole));
92 | return this;
93 | }
94 |
95 | public LPolygon setHoles(Point[]... holes) {
96 | for (Point[] hole : holes) {
97 | addHole(hole);
98 | }
99 | return this;
100 | }
101 |
102 | public List getHoles() {
103 | return points.subList(1, points.size());
104 | }
105 |
106 | /**
107 | * Removes all null values from the geometry.
108 | */
109 | public void sanitizeGeometry() {
110 | points.sanitize();
111 | }
112 |
113 | }
114 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/LPolyline.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet;
2 |
3 | import org.locationtech.jts.geom.Geometry;
4 | import org.vaadin.addon.leaflet.shared.LeafletPolylineState;
5 | import org.vaadin.addon.leaflet.jsonmodels.PointArray;
6 | import org.vaadin.addon.leaflet.shared.Point;
7 | import org.vaadin.addon.leaflet.util.JTSUtil;
8 |
9 | import org.locationtech.jts.geom.Geometry;
10 | import org.locationtech.jts.geom.LineString;
11 |
12 | import java.util.List;
13 |
14 | public class LPolyline extends AbstractLeafletVector {
15 |
16 | private PointArray points;
17 |
18 | @Override
19 | protected LeafletPolylineState getState() {
20 | return (LeafletPolylineState) super.getState();
21 | }
22 |
23 | public LPolyline(Point... points) {
24 | setPoints(points);
25 | }
26 |
27 | public LPolyline(org.locationtech.jts.geom.LineString jtsLineString) {
28 | this(JTSUtil.toLeafletPointArray(jtsLineString));
29 | }
30 |
31 | @Override
32 | public void beforeClientResponse(boolean initial) {
33 | super.beforeClientResponse(initial);
34 | getState().geometryjson = points.asJson();
35 | }
36 |
37 | public void setPoints(Point... array) {
38 | setPointsWithoutRepaint(array);
39 | markAsDirty();
40 | }
41 |
42 | public void setPoints(List points) {
43 | this.points = new PointArray(points);
44 | markAsDirty();
45 | }
46 |
47 | public void setPointsWithoutRepaint(Point... points) {
48 | this.points = new PointArray(points);
49 | }
50 |
51 | public Point[] getPoints() {
52 | return points.toArray(new Point[points.size()]);
53 | }
54 |
55 | @Override
56 | public Geometry getGeometry() {
57 | final LineString line = JTSUtil.toLineString(this);
58 | if(line.isSimple() && line.isClosed())
59 | {
60 | return JTSUtil.toLinearRing(this);
61 | }
62 | return line;
63 | }
64 |
65 | public void setGeometry(LineString lineString) {
66 | setPoints(JTSUtil.toLeafletPointArray(lineString));
67 | }
68 |
69 | public void setGeometryWithoutRepaint(LineString lineString) {
70 | setPointsWithoutRepaint(JTSUtil.toLeafletPointArray(lineString));
71 | }
72 |
73 | /**
74 | * Removes all null values from the geometry.
75 | */
76 | public void sanitizeGeometry() {
77 | points.sanitize();
78 | }
79 |
80 | }
81 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/LPopup.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet;
2 |
3 | import org.locationtech.jts.geom.Geometry;
4 | import org.vaadin.addon.leaflet.shared.LeafletPopupState;
5 | import org.vaadin.addon.leaflet.shared.PopupServerRpc;
6 | import org.vaadin.addon.leaflet.shared.Point;
7 | import org.vaadin.addon.leaflet.shared.PopupState;
8 | import org.vaadin.addon.leaflet.util.JTSUtil;
9 |
10 | import org.locationtech.jts.geom.Geometry;
11 |
12 | /**
13 | * Standalone Popup to be displayed on the map.
14 | */
15 | public class LPopup extends AbstractLeafletDivOverlay {
16 |
17 | @Override
18 | protected LeafletPopupState getState() {
19 | return (LeafletPopupState) super.getState();
20 | }
21 |
22 | public LPopup(double lat, double lon) {
23 | this();
24 | getState().point = new Point(lat, lon);
25 | }
26 |
27 | public LPopup() {
28 | registerRpc(new PopupServerRpc() {
29 |
30 | @Override
31 | public void closed() {
32 | close();
33 | }
34 | });
35 | }
36 |
37 | public LPopup(Point point) {
38 | this();
39 | getState().point = point;
40 | }
41 |
42 | private LMap getMap() {
43 | return (LMap) getParent();
44 | }
45 |
46 | public LPopup(org.locationtech.jts.geom.Point jtsPoint) {
47 | this(JTSUtil.toLeafletPoint(jtsPoint));
48 | }
49 |
50 | public LPopup setContent(String htmlContent) {
51 | return (LPopup) super.setContent(htmlContent);
52 | }
53 |
54 | public void close() {
55 | getMap().removeComponent(this);
56 | }
57 |
58 | @Override
59 | public Geometry getGeometry() {
60 | return JTSUtil.toPoint(getState().point);
61 | }
62 |
63 | public PopupState getPopupState() {
64 | return getState().popupState;
65 | }
66 |
67 | public void setPopupState(PopupState popupState){
68 | getState().popupState = popupState;
69 | }
70 |
71 | public void setCloseButton(boolean closeButtonVisible) {
72 | getState().popupState.closeButton = closeButtonVisible;
73 | }
74 |
75 | public void setCloseOnClick(boolean closeOnMapClick) {
76 | getState().popupState.closeOnClick = closeOnMapClick;
77 | }
78 |
79 | }
80 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/LRectangle.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet;
2 |
3 | import org.vaadin.addon.leaflet.shared.Point;
4 |
5 | import org.vaadin.addon.leaflet.shared.LeafletRectangleState;
6 | import org.vaadin.addon.leaflet.shared.Bounds;
7 |
8 | public class LRectangle extends LPolygon {
9 |
10 | public LRectangle(Point sw, Point ne) {
11 | this(new Bounds(sw, ne));
12 | }
13 |
14 | public LRectangle(Bounds b) {
15 | super();
16 | setBounds(b);
17 | }
18 |
19 | public void setBounds(Bounds bounds) {
20 | getState().bounds = bounds;
21 | setPoints(
22 | new Point(bounds.getSouthWestLat(), bounds.getSouthWestLon()),
23 | new Point(bounds.getNorthEastLat(), bounds.getSouthWestLon()),
24 | new Point(bounds.getNorthEastLat(), bounds.getNorthEastLon()),
25 | new Point(bounds.getSouthWestLat(), bounds.getNorthEastLon()));
26 | }
27 |
28 | public Bounds getBounds() {
29 | return getState().bounds;
30 | }
31 |
32 | @Override
33 | protected LeafletRectangleState getState() {
34 | return (LeafletRectangleState) super.getState();
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/LTileLayer.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet;
2 |
3 | import org.vaadin.addon.leaflet.shared.LeafletTileLayerState;
4 | import java.util.HashMap;
5 | import java.util.Map;
6 |
7 | public class LTileLayer extends LGridLayer {
8 |
9 | public LTileLayer() {
10 | super();
11 | }
12 |
13 | public LTileLayer(String url) {
14 | this();
15 | setUrl(url);
16 | }
17 |
18 | @Override
19 | protected LeafletTileLayerState getState() {
20 | return (LeafletTileLayerState) super.getState();
21 | }
22 |
23 | public String getUrl() {
24 | return getState().url;
25 | }
26 |
27 | public void setUrl(String url) {
28 | getState().url = url;
29 | }
30 |
31 | public Boolean getDetectRetina() {
32 | return getState().detectRetina;
33 | }
34 |
35 | public void setDetectRetina(Boolean detectRetina) {
36 | getState().detectRetina = detectRetina;
37 | }
38 |
39 | public Boolean getTms() {
40 | return getState().tms;
41 | }
42 |
43 | public void setTms(Boolean tms) {
44 | getState().tms = tms;
45 | }
46 |
47 | public Integer getMinZoom() {
48 | return getState().minZoom;
49 | }
50 |
51 | public void setMinZoom(Integer minZoom) {
52 | getState().minZoom = minZoom;
53 | }
54 |
55 | public Integer getMaxZoom() {
56 | return getState().maxZoom;
57 | }
58 |
59 | public void setMaxZoom(Integer maxZoom) {
60 | getState().maxZoom = maxZoom;
61 | }
62 |
63 | public String[] getSubDomains() {
64 | return getState().subDomains;
65 | }
66 |
67 | public void setSubDomains(String... string) {
68 | getState().subDomains = string;
69 | }
70 |
71 | public Map getCustomOptions() {
72 | return getState().customOptions;
73 | }
74 |
75 | public void setCustomOptions(Map customOptions) {
76 | getState().customOptions = customOptions;
77 | }
78 |
79 | public void setCustomOption(String optionName, String optionValue) {
80 | if (getState().customOptions == null) {
81 | getState().customOptions = new HashMap();
82 | }
83 | getState().customOptions.put(optionName, optionValue);
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/LTooltip.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet;
2 |
3 | import org.locationtech.jts.geom.Geometry;
4 | import org.vaadin.addon.leaflet.shared.LeafletTooltipState;
5 | import org.vaadin.addon.leaflet.shared.Point;
6 | import org.vaadin.addon.leaflet.shared.TooltipState;
7 | import org.vaadin.addon.leaflet.util.JTSUtil;
8 |
9 | /**
10 | * Standalone Tooltip to be displayed on the map.
11 | */
12 | public class LTooltip extends AbstractLeafletDivOverlay {
13 |
14 | @Override
15 | protected LeafletTooltipState getState() {
16 | return (LeafletTooltipState) super.getState();
17 | }
18 |
19 | public LTooltip() {
20 | }
21 |
22 | public LTooltip(double lat, double lon) {
23 | getState().point = new Point(lat, lon);
24 | }
25 |
26 | public LTooltip(Point point) {
27 | getState().point = point;
28 | }
29 |
30 | private LMap getMap() {
31 | return (LMap) getParent();
32 | }
33 |
34 | public LTooltip(org.locationtech.jts.geom.Point jtsPoint) {
35 | this(JTSUtil.toLeafletPoint(jtsPoint));
36 | }
37 |
38 | @Override
39 | public LTooltip setContent(String htmlContent) {
40 | return (LTooltip) super.setContent(htmlContent);
41 | }
42 |
43 | public void close() {
44 | getMap().removeComponent(this);
45 | }
46 |
47 | @Override
48 | public Geometry getGeometry() {
49 | return JTSUtil.toPoint(getState().point);
50 | }
51 |
52 | public TooltipState getTooltipState() {
53 | return getState().tooltipState;
54 | }
55 |
56 | public void setTooltipState(TooltipState tooltipState) {
57 | getState().tooltipState = tooltipState;
58 | }
59 |
60 | public void setPane(String pane) {
61 | getState().tooltipState.pane = pane;
62 | }
63 |
64 | public void setOffset(Point p) {
65 | getState().tooltipState.offset = p;
66 | }
67 |
68 | public void setDirection(String direction) {
69 | getState().tooltipState.direction = direction;
70 | }
71 |
72 | public void setPermanent (boolean permanent) {
73 | getState().tooltipState.permanent = permanent;
74 | }
75 |
76 | public void setSticky(boolean sticky) {
77 | getState().tooltipState.sticky = sticky;
78 | }
79 |
80 | public void setInteractive(boolean interactive) {
81 | getState().tooltipState.interactive = interactive;
82 | }
83 |
84 | public void setOpacity(double opacity) {
85 | getState().tooltipState.opacity = opacity;
86 | }
87 |
88 | }
89 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/LWmsLayer.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet;
2 |
3 | import org.vaadin.addon.leaflet.shared.Crs;
4 | import org.vaadin.addon.leaflet.shared.LeafletWmsLayerState;
5 |
6 | public class LWmsLayer extends LTileLayer {
7 |
8 | private Crs lCrs;
9 |
10 | @Override
11 | protected LeafletWmsLayerState getState() {
12 | return (LeafletWmsLayerState) super.getState();
13 | }
14 |
15 | public String getLayers() {
16 | return getState().layers;
17 | }
18 |
19 | public void setLayers(String layers) {
20 | getState().layers = layers;
21 | }
22 |
23 | public String getStyles() {
24 | return getState().layerStyles;
25 | }
26 |
27 | public void setStyles(String styles) {
28 | getState().layerStyles = styles;
29 | }
30 |
31 | public String getFormat() {
32 | return getState().format;
33 | }
34 |
35 | public void setFormat(String format) {
36 | getState().format = format;
37 | }
38 |
39 | public Boolean getTransparent() {
40 | return getState().transparent;
41 | }
42 |
43 | public void setTransparent(Boolean transparent) {
44 | getState().transparent = transparent;
45 | }
46 |
47 | public String getVersion() {
48 | return getState().version;
49 | }
50 |
51 | public void setVersion(String version) {
52 | getState().version = version;
53 | }
54 |
55 | public Crs getCrs() {
56 | return lCrs;
57 | }
58 |
59 | /**
60 | * Specify the CRS to use for the layer.
61 | *
62 | * @param lc The CRS to use (one from a limited range)
63 | */
64 | public void setCrs(Crs lc) {
65 | this.lCrs = lc;
66 | getState().crsName = lc.getName();
67 | }
68 |
69 | public void setViewparams(String viewparams) {
70 | getState().viewparams = viewparams;
71 | }
72 |
73 | public String getViewparams() {
74 | return getState().viewparams;
75 | }
76 |
77 | public void setCQLFilter(String cqlFilter)
78 | {
79 | getState().cqlFilter = cqlFilter;
80 | }
81 |
82 | public String getCQLFilter()
83 | {
84 | return getState().cqlFilter;
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/LeafletBaseLayerChangeEvent.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet;
2 |
3 | import com.vaadin.event.ConnectorEvent;
4 | import com.vaadin.server.ClientConnector;
5 |
6 | public class LeafletBaseLayerChangeEvent extends ConnectorEvent {
7 |
8 | private String name;
9 |
10 | public LeafletBaseLayerChangeEvent(ClientConnector source, String name) {
11 | super(source);
12 | this.name = name;
13 | }
14 |
15 | public String getName() {
16 | return name;
17 | }
18 |
19 | }
20 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/LeafletBaseLayerChangeListener.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet;
2 |
3 | import com.vaadin.util.ReflectTools;
4 |
5 | import java.lang.reflect.Method;
6 |
7 | public interface LeafletBaseLayerChangeListener {
8 |
9 | static final Method METHOD = ReflectTools.findMethod(LeafletBaseLayerChangeListener.class, "onBaseLayerChange", LeafletBaseLayerChangeEvent.class);
10 |
11 | void onBaseLayerChange(LeafletBaseLayerChangeEvent event);
12 | }
13 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/LeafletClickEvent.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet;
2 |
3 | import org.vaadin.addon.leaflet.shared.Point;
4 |
5 | import com.vaadin.event.ConnectorEvent;
6 | import com.vaadin.shared.MouseEventDetails;
7 | import com.vaadin.ui.Component;
8 |
9 | public class LeafletClickEvent extends ConnectorEvent {
10 |
11 | private final Point point;
12 | private final MouseEventDetails mouseEvent;
13 |
14 | public LeafletClickEvent(Component source, Point p, MouseEventDetails d) {
15 | super(source);
16 | this.point = p;
17 | this.mouseEvent = d;
18 | }
19 |
20 | /**
21 | * @return the geographical point where the event happened.
22 | */
23 | public Point getPoint() {
24 | return point;
25 | }
26 |
27 | public double getClientX() {
28 | return mouseEvent.getClientX();
29 | }
30 |
31 | public double getClientY() {
32 | return mouseEvent.getClientY();
33 | }
34 |
35 | public double getRelativeX() {
36 | return mouseEvent.getRelativeX();
37 | }
38 |
39 | public double getRelativeY() {
40 | return mouseEvent.getRelativeY();
41 | }
42 |
43 | public MouseEventDetails getMouseEvent() {
44 | return mouseEvent;
45 | }
46 |
47 | @Override
48 | public String toString() {
49 | return "LeafletClickEvent{" + "point=" + point + ", mouseEvent=" + mouseEvent + '}';
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/LeafletClickListener.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet;
2 |
3 | import java.lang.reflect.Method;
4 |
5 |
6 | import com.vaadin.util.ReflectTools;
7 |
8 | public interface LeafletClickListener {
9 |
10 | static final Method METHOD = ReflectTools.findMethod(LeafletClickListener.class, "onClick", LeafletClickEvent.class);
11 |
12 | void onClick(LeafletClickEvent event);
13 | }
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/LeafletContextMenuEvent.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet;
2 |
3 | import com.vaadin.shared.MouseEventDetails;
4 | import com.vaadin.ui.Component;
5 | import org.vaadin.addon.leaflet.shared.Point;
6 |
7 | public class LeafletContextMenuEvent extends LeafletClickEvent {
8 |
9 | LeafletContextMenuEvent(Component c, Point p, MouseEventDetails d) {
10 | super(c, p, d);
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/LeafletContextMenuListener.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet;
2 |
3 | import com.vaadin.util.ReflectTools;
4 | import java.lang.reflect.Method;
5 |
6 | public interface LeafletContextMenuListener {
7 |
8 | static final Method METHOD = ReflectTools.findMethod(LeafletContextMenuListener.class, "onContextMenu", LeafletContextMenuEvent.class);
9 |
10 | void onContextMenu(LeafletContextMenuEvent event);
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/LeafletLayer.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet;
2 |
3 | import com.vaadin.ui.Component;
4 | import org.locationtech.jts.geom.Geometry;
5 |
6 | /**
7 | * Marker interface to be implemented by all server side counterparts for
8 | * Leaflets ILayer interface.
9 | */
10 | public interface LeafletLayer extends Component {
11 |
12 | /**
13 | * @return The geometry of the layer or null if the layer covers everything
14 | * (e.g. various tile layers).
15 | */
16 | Geometry getGeometry();
17 |
18 | void bringToFront();
19 | void bringToBack();
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/LeafletLoadEvent.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet;
2 |
3 | import com.vaadin.event.*;
4 | import com.vaadin.server.*;
5 |
6 | public class LeafletLoadEvent extends ConnectorEvent
7 | {
8 | public LeafletLoadEvent(ClientConnector source)
9 | {
10 | super(source);
11 | }
12 | }
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/LeafletLoadListener.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet;
2 |
3 | import java.lang.reflect.*;
4 |
5 | import org.vaadin.addon.leaflet.shared.EventId;
6 |
7 | import com.vaadin.util.*;
8 |
9 | public interface LeafletLoadListener
10 | {
11 | static final Method METHOD = ReflectTools.findMethod(
12 | LeafletLoadListener.class, EventId.LOAD, LeafletLoadEvent.class);
13 |
14 | void onLoad(LeafletLoadEvent event);
15 | }
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/LeafletLoadingEvent.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet;
2 |
3 | import com.vaadin.event.*;
4 | import com.vaadin.server.*;
5 |
6 | public class LeafletLoadingEvent extends ConnectorEvent
7 | {
8 | public LeafletLoadingEvent(ClientConnector source)
9 | {
10 | super(source);
11 | }
12 | }
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/LeafletLoadingListener.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet;
2 |
3 | import java.lang.reflect.*;
4 |
5 | import org.vaadin.addon.leaflet.shared.EventId;
6 |
7 | import com.vaadin.util.*;
8 |
9 | public interface LeafletLoadingListener
10 | {
11 | static final Method METHOD = ReflectTools.findMethod(
12 | LeafletLoadingListener.class, EventId.LOADING, LeafletLoadingEvent.class);
13 |
14 | void onLoading(LeafletLoadingEvent event);
15 | }
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/LeafletLocateEvent.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet;
2 |
3 | import com.vaadin.event.ConnectorEvent;
4 | import com.vaadin.server.ClientConnector;
5 | import org.vaadin.addon.leaflet.shared.Point;
6 |
7 | public class LeafletLocateEvent extends ConnectorEvent {
8 | private final Double accuracy;
9 | private final Double altitude;
10 | private final Double speed;
11 | private Point point;
12 |
13 | public LeafletLocateEvent(ClientConnector source, Point p, Double a, Double altitude, Double speed) {
14 | super(source);
15 | this.point = p;
16 | this.accuracy = a;
17 | this.altitude = altitude;
18 | this.speed = speed;
19 | }
20 |
21 | public Point getPoint() {
22 | return point;
23 | }
24 |
25 | public Double getAccuracy() {
26 | return accuracy;
27 | }
28 |
29 | public Double getAltitude() {
30 | return altitude;
31 | }
32 |
33 | public Double getSpeed() {
34 | return speed;
35 | }
36 |
37 | @Override
38 | public String toString() {
39 | return point.toString() + " a: " + accuracy + " alt:" + altitude;
40 | }
41 | }
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/LeafletLocateListener.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet;
2 |
3 | import com.vaadin.util.ReflectTools;
4 | import org.vaadin.addon.leaflet.shared.EventId;
5 |
6 | import java.lang.reflect.Method;
7 |
8 | public interface LeafletLocateListener {
9 |
10 | static final Method METHOD = ReflectTools.findMethod(LeafletLocateListener.class, EventId.LOCATE, LeafletLocateEvent.class);
11 |
12 | void onLocate(LeafletLocateEvent event);
13 |
14 | }
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/LeafletMouseOutEvent.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet;
2 |
3 | import org.vaadin.addon.leaflet.shared.Point;
4 |
5 | import com.vaadin.event.ConnectorEvent;
6 | import com.vaadin.server.ClientConnector;
7 |
8 | public class LeafletMouseOutEvent extends ConnectorEvent {
9 | private Point point;
10 |
11 | public LeafletMouseOutEvent(ClientConnector source, Point p) {
12 | super(source);
13 | this.point = p;
14 | }
15 |
16 | public Point getPoint() {
17 | return point;
18 | }
19 |
20 | }
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/LeafletMouseOutListener.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet;
2 |
3 | import java.lang.reflect.Method;
4 |
5 |
6 | import com.vaadin.util.ReflectTools;
7 | import org.vaadin.addon.leaflet.shared.EventId;
8 |
9 | public interface LeafletMouseOutListener {
10 |
11 | static final Method METHOD = ReflectTools.findMethod(LeafletMouseOutListener.class, EventId.MOUSEOUT, LeafletMouseOutEvent.class);
12 |
13 | void onMouseOut(LeafletMouseOutEvent event);
14 | }
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/LeafletMouseOverEvent.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet;
2 |
3 | import org.vaadin.addon.leaflet.shared.Point;
4 |
5 | import com.vaadin.event.ConnectorEvent;
6 | import com.vaadin.server.ClientConnector;
7 |
8 | public class LeafletMouseOverEvent extends ConnectorEvent {
9 | private Point point;
10 |
11 | public LeafletMouseOverEvent(ClientConnector source, Point p) {
12 | super(source);
13 | this.point = p;
14 | }
15 |
16 | public Point getPoint() {
17 | return point;
18 | }
19 |
20 | }
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/LeafletMouseOverListener.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet;
2 |
3 | import java.lang.reflect.Method;
4 |
5 |
6 | import com.vaadin.util.ReflectTools;
7 | import org.vaadin.addon.leaflet.shared.EventId;
8 |
9 | public interface LeafletMouseOverListener {
10 |
11 | static final Method METHOD = ReflectTools.findMethod(LeafletMouseOverListener.class, EventId.MOUSEOVER, LeafletMouseOverEvent.class);
12 |
13 | void onMouseOver(LeafletMouseOverEvent event);
14 | }
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/LeafletMoveEndEvent.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet;
2 |
3 | import org.vaadin.addon.leaflet.shared.Bounds;
4 | import org.vaadin.addon.leaflet.shared.Point;
5 |
6 | import com.vaadin.event.ConnectorEvent;
7 | import com.vaadin.server.ClientConnector;
8 |
9 | public class LeafletMoveEndEvent extends ConnectorEvent {
10 |
11 | private Bounds bounds;
12 | private double zoomLevel;
13 | private Point center;
14 |
15 | public LeafletMoveEndEvent(ClientConnector source, Bounds bounds, Point center, double zoomlevel) {
16 | super(source);
17 | this.bounds = bounds;
18 | this.center = center;
19 | this.zoomLevel = zoomlevel;
20 | }
21 |
22 | public Bounds getBounds() {
23 | return bounds;
24 | }
25 |
26 | public Point getCenter() {
27 | return center;
28 | }
29 |
30 | public double getZoomLevel() {
31 | return zoomLevel;
32 | }
33 |
34 | }
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/LeafletMoveEndListener.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet;
2 |
3 | import java.lang.reflect.Method;
4 |
5 |
6 | import com.vaadin.util.ReflectTools;
7 |
8 | public interface LeafletMoveEndListener {
9 |
10 | static final Method METHOD = ReflectTools.findMethod(LeafletMoveEndListener.class, "onMoveEnd", LeafletMoveEndEvent.class);
11 |
12 | void onMoveEnd(LeafletMoveEndEvent event);
13 | }
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/LeafletOverlayAddEvent.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet;
2 |
3 | import com.vaadin.event.ConnectorEvent;
4 | import com.vaadin.server.ClientConnector;
5 |
6 | public class LeafletOverlayAddEvent extends ConnectorEvent {
7 |
8 | private String name;
9 |
10 | public LeafletOverlayAddEvent(ClientConnector source, String name) {
11 | super(source);
12 | this.name = name;
13 | }
14 |
15 | public String getName() {
16 | return name;
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/LeafletOverlayAddListener.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet;
2 |
3 | import com.vaadin.util.ReflectTools;
4 |
5 | import java.lang.reflect.Method;
6 |
7 | public interface LeafletOverlayAddListener {
8 |
9 | static final Method METHOD = ReflectTools.findMethod(LeafletOverlayAddListener.class, "onOverlayAdd", LeafletOverlayAddEvent.class);
10 |
11 | void onOverlayAdd(LeafletOverlayAddEvent event);
12 | }
13 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/LeafletOverlayRemoveEvent.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet;
2 |
3 | import com.vaadin.event.ConnectorEvent;
4 | import com.vaadin.server.ClientConnector;
5 |
6 | public class LeafletOverlayRemoveEvent extends ConnectorEvent {
7 |
8 | private String name;
9 |
10 | public LeafletOverlayRemoveEvent(ClientConnector source, String name) {
11 | super(source);
12 | this.name = name;
13 | }
14 |
15 | public String getName() {
16 | return name;
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/LeafletOverlayRemoveListener.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet;
2 |
3 | import com.vaadin.util.ReflectTools;
4 |
5 | import java.lang.reflect.Method;
6 |
7 | public interface LeafletOverlayRemoveListener {
8 |
9 | static final Method METHOD = ReflectTools.findMethod(LeafletOverlayRemoveListener.class, "onOverlayRemove", LeafletOverlayRemoveEvent.class);
10 |
11 | void onOverlayRemove(LeafletOverlayRemoveEvent event);
12 | }
13 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/Widgetset.gwt.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/client/AbstractControlConnector.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.client;
2 |
3 | import org.vaadin.addon.leaflet.shared.LeafletControlState;
4 | import org.peimari.gleaflet.client.Map;
5 | import org.peimari.gleaflet.client.control.Control;
6 |
7 | import com.google.gwt.core.client.Scheduler;
8 | import com.google.gwt.core.client.Scheduler.ScheduledCommand;
9 | import com.vaadin.client.ServerConnector;
10 | import com.vaadin.client.communication.StateChangeEvent;
11 | import com.vaadin.client.extensions.AbstractExtensionConnector;
12 |
13 | public abstract class AbstractControlConnector extends
14 | AbstractExtensionConnector {
15 |
16 | private T control;
17 | private Map map;
18 |
19 | @Override
20 | protected void extend(final ServerConnector target) {
21 | // non tree updates in V7 :(, map might not exist when this is called
22 | Scheduler.get().scheduleFinally(new ScheduledCommand() {
23 | @Override
24 | public void execute() {
25 | getMap().addControl(getControl());
26 | }
27 | });
28 | }
29 |
30 | protected T getControl() {
31 | if (control == null) {
32 | control = createControl();
33 | }
34 | return control;
35 | }
36 |
37 | protected abstract T createControl();
38 |
39 | @Override
40 | public void onUnregister() {
41 | super.onUnregister();
42 | if (getMap() != null) {
43 | getMap().removeControl(control);
44 | }
45 | }
46 |
47 | protected Map getMap() {
48 | if (map == null) {
49 | LeafletMapConnector p = (LeafletMapConnector) getParent();
50 | if (p != null) {
51 | map = p.getMap();
52 | }
53 | }
54 | return map;
55 | }
56 |
57 | @Override
58 | public void onStateChanged(final StateChangeEvent stateChangeEvent) {
59 | super.onStateChanged(stateChangeEvent);
60 | Scheduler.get().scheduleFinally(new ScheduledCommand() {
61 | @Override
62 | public void execute() {
63 | doStateChange(stateChangeEvent);
64 | if (stateChangeEvent.hasPropertyChanged("position")
65 | && getState().position != null) {
66 | getControl().setPosition(getState().position.toString());
67 | }
68 | }
69 | });
70 | }
71 |
72 | @Override
73 | public LeafletControlState getState() {
74 | return (LeafletControlState) super.getState();
75 | }
76 |
77 | /**
78 | * Deferred state change where layers have been created and added
79 | *
80 | * @param stateChangeEvent the event
81 | */
82 | protected void doStateChange(StateChangeEvent stateChangeEvent) {
83 |
84 | }
85 |
86 | @Override
87 | public LeafletMapConnector getParent() {
88 | return (LeafletMapConnector) super.getParent();
89 | }
90 |
91 | }
92 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/client/AbstractDefaultControl.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.client;
2 |
3 | import org.peimari.gleaflet.client.control.Control;
4 |
5 | import com.vaadin.client.ServerConnector;
6 | import com.vaadin.client.communication.StateChangeEvent;
7 |
8 | public abstract class AbstractDefaultControl extends
9 | AbstractControlConnector {
10 |
11 | private boolean removed;
12 |
13 | public AbstractDefaultControl() {
14 | super();
15 | }
16 |
17 | @Override
18 | protected void extend(ServerConnector target) {
19 | // NOP, skip reattaching default control
20 | }
21 |
22 | protected void doStateChange(StateChangeEvent stateChangeEvent) {
23 | if(!getState().enabled) {
24 | getMap().removeControl(getControl());
25 | removed = true;
26 | } else if(removed) {
27 | getMap().addControl(getControl());
28 | removed = false;
29 | }
30 | }
31 |
32 | }
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/client/AbstractLeafletVectorConnector.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.client;
2 |
3 | import org.vaadin.addon.leaflet.shared.AbstractLeafletVectorState;
4 | import org.vaadin.addon.leaflet.shared.LeafletMarkerClientRpc;
5 | import com.google.gwt.core.client.JsonUtils;
6 | import org.peimari.gleaflet.client.AbstractPath;
7 | import org.peimari.gleaflet.client.PathOptions;
8 |
9 | import com.google.gwt.core.client.Scheduler;
10 | import com.google.gwt.core.client.Scheduler.ScheduledCommand;
11 | import com.vaadin.client.ServerConnector;
12 |
13 | public abstract class AbstractLeafletVectorConnector
14 | extends AbstractLeafletLayerConnector {
15 |
16 | public AbstractLeafletVectorConnector() {
17 | registerRpc(LeafletMarkerClientRpc.class, new LeafletMarkerClientRpc() {
18 |
19 | @Override
20 | public void openTooltip() {
21 | Scheduler.get().scheduleDeferred(new ScheduledCommand() {
22 | @Override
23 | public void execute() {
24 | getVector().openTooltip();
25 | }
26 | });
27 | }
28 |
29 | @Override
30 | public void closeTooltip() {
31 | getVector().closeTooltip();
32 | }
33 |
34 | @Override
35 | public void openPopup() {
36 | Scheduler.get().scheduleDeferred(
37 | new Scheduler.ScheduledCommand() {
38 |
39 | @Override
40 | public void execute() {
41 | getVector().openPopup();
42 | }
43 | });
44 | }
45 |
46 | @Override
47 | public void closePopup() {
48 | getVector().closePopup();
49 | }
50 |
51 | });
52 |
53 | }
54 |
55 | protected AbstractPath getVector() {
56 | return (AbstractPath) getLayer();
57 | }
58 |
59 | @Override
60 | protected O createOptions() {
61 | AbstractLeafletVectorState s = getState();
62 | O o = JsonUtils.safeEval(s.vectorStyleJson);
63 |
64 | if (s.bubblingMouseEvents != null) {
65 | o.setBubblingMouseEvents(s.bubblingMouseEvents);
66 | }
67 |
68 | if (s.clickable != null) {
69 | o.setClickable(s.clickable);
70 | }
71 | if (s.pointerEvents != null) {
72 | o.setPointerEvents(s.pointerEvents);
73 | }
74 | if (s.className != null) {
75 | o.setClassName(s.className);
76 | }
77 |
78 | final String tooltip = getState().tooltip;
79 | if (tooltip != null) {
80 | Scheduler.get().scheduleFinally(new ScheduledCommand() {
81 | @Override
82 | public void execute() {
83 | getVector().bindTooltip(tooltip, LeafletTooltipConnector.tooltipOptionsFor(getState().tooltipState,
84 | AbstractLeafletVectorConnector.this));
85 | }
86 | });
87 | }
88 |
89 | final String popup = getState().popup;
90 | if (popup != null) {
91 | Scheduler.get().scheduleFinally(new ScheduledCommand() {
92 |
93 | @Override
94 | public void execute() {
95 | getVector().bindPopup(
96 | popup,
97 | LeafletPopupConnector
98 | .popupOptionsFor(getState().popupState, AbstractLeafletVectorConnector.this));
99 | }
100 | });
101 |
102 | }
103 |
104 | return o;
105 | }
106 |
107 | @Override
108 | public void setParent(ServerConnector parent) {
109 | super.setParent(parent);
110 | markDirty();
111 | }
112 |
113 | @Override
114 | public T getState() {
115 | return (T) super.getState();
116 | }
117 | }
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/client/LazyUpdator.java:
--------------------------------------------------------------------------------
1 |
2 | package org.vaadin.addon.leaflet.client;
3 |
4 | import com.google.gwt.core.client.Scheduler;
5 | import java.util.HashSet;
6 |
7 | /**
8 | *
9 | * @author mattitahvonenitmill
10 | */
11 | public class LazyUpdator {
12 |
13 | private static final HashSet dirtySet = new HashSet();
14 | private static boolean scheduled;
15 |
16 | public static void defer(AbstractLeafletLayerConnector c) {
17 | dirtySet.add(c);
18 | if(!scheduled) {
19 | Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
20 |
21 | @Override
22 | public void execute() {
23 | scheduled = false;
24 | for (AbstractLeafletLayerConnector c : dirtySet) {
25 | c.updateIfDirty();
26 | }
27 | dirtySet.clear();
28 | }
29 | });
30 | }
31 | }
32 |
33 | public static void clear(AbstractLeafletLayerConnector c) {
34 | dirtySet.remove(c);
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/client/LeafletAttributionConnector.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.client;
2 |
3 | import org.vaadin.addon.leaflet.shared.LeafletAttributionState;
4 | import org.peimari.gleaflet.client.control.Attribution;
5 | import org.vaadin.addon.leaflet.control.LAttribution;
6 |
7 | import com.vaadin.client.communication.StateChangeEvent;
8 | import com.vaadin.shared.ui.Connect;
9 |
10 | @Connect(LAttribution.class)
11 | public class LeafletAttributionConnector extends AbstractDefaultControl {
12 |
13 | @Override
14 | protected Attribution createControl() {
15 | return getMap().getAttributionControl();
16 | }
17 |
18 | @Override
19 | public LeafletAttributionState getState() {
20 | return (LeafletAttributionState) super.getState();
21 | }
22 |
23 | @Override
24 | protected Attribution getControl() {
25 | return (Attribution) super.getControl();
26 | }
27 |
28 | @Override
29 | protected void doStateChange(StateChangeEvent stateChangeEvent) {
30 | super.doStateChange(stateChangeEvent);
31 | getControl().setPrefix(getState().prefix);
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/client/LeafletFeatureGroupConnector.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Vaadin Community.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.vaadin.addon.leaflet.client;
17 |
18 | import org.peimari.gleaflet.client.FeatureGroup;
19 | import org.peimari.gleaflet.client.Layer;
20 | import org.peimari.gleaflet.client.LayerGroup;
21 |
22 | import com.vaadin.client.ServerConnector;
23 | import com.vaadin.shared.ui.Connect;
24 |
25 | /**
26 | *
27 | * @author mattitahvonenitmill
28 | */
29 | @Connect(org.vaadin.addon.leaflet.LFeatureGroup.class)
30 | public class LeafletFeatureGroupConnector extends LeafletLayerGroupConnector {
31 | @Override
32 | protected LayerGroup createLayerGroup() {
33 | return FeatureGroup.create();
34 | }
35 |
36 | public AbstractLeafletLayerConnector> getConnectorFor(Layer iLayer) {
37 | for (ServerConnector c : getChildren()) {
38 | if (c instanceof AbstractLeafletLayerConnector>) {
39 | AbstractLeafletLayerConnector> lc = (AbstractLeafletLayerConnector>) c;
40 | if(lc.getLayer() == iLayer) {
41 | return lc;
42 | }
43 | }
44 | }
45 | return null;
46 | }
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/client/LeafletGridLayerConnector.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.client;
2 |
3 | import org.peimari.gleaflet.client.Event;
4 | import org.peimari.gleaflet.client.GridLayer;
5 | import org.peimari.gleaflet.client.GridLayerOptions;
6 | import org.peimari.gleaflet.client.LatLng;
7 | import org.peimari.gleaflet.client.LatLngBounds;
8 | import org.peimari.gleaflet.client.Layer;
9 | import org.peimari.gleaflet.client.LoadListener;
10 | import org.peimari.gleaflet.client.LoadingListener;
11 | import org.vaadin.addon.leaflet.shared.EventId;
12 | import org.vaadin.addon.leaflet.shared.LeafletGridLayerServerRpc;
13 | import org.vaadin.addon.leaflet.shared.LeafletGridLayerState;
14 |
15 | import com.vaadin.client.communication.RpcProxy;
16 | import com.vaadin.shared.ui.Connect;
17 |
18 | @Connect(org.vaadin.addon.leaflet.LGridLayer.class)
19 | public class LeafletGridLayerConnector extends AbstractLeafletLayerConnector {
20 |
21 | protected Layer layer;
22 | protected LeafletGridLayerServerRpc gridLayerServerRpc = RpcProxy.create(LeafletGridLayerServerRpc.class, this);
23 |
24 | @Override
25 | public LeafletGridLayerState getState() {
26 | return (LeafletGridLayerState) super.getState();
27 | }
28 |
29 | @Override
30 | protected GridLayerOptions createOptions() {
31 | GridLayerOptions o = GridLayerOptions.create();
32 | LeafletGridLayerState s = getState();
33 |
34 | if (s.attributionString != null) {
35 | o.setAttribution(s.attributionString);
36 | }
37 | if (s.minNativeZoom != null) {
38 | o.setMinNativeZoom(s.minNativeZoom);
39 | }
40 | if (s.maxNativeZoom != null) {
41 | o.setMaxNativeZoom(s.maxNativeZoom);
42 | }
43 | if (s.opacity != null) {
44 | o.setOpacity(s.opacity);
45 | }
46 | if (s.zIndex != null) {
47 | o.setZindex(s.zIndex);
48 | }
49 | if (s.noWrap != null) {
50 | o.setNoWrap(s.noWrap);
51 | }
52 | if (s.bounds != null) {
53 | o.setBounds(LatLngBounds.create(LatLng.create(s.bounds.getSouthWestLat(), s.bounds.getSouthWestLon()),
54 | LatLng.create(s.bounds.getNorthEastLat(), s.bounds.getNorthEastLon())));
55 | }
56 | if (s.tileSize != null)
57 | {
58 | o.setTileSize(s.tileSize);
59 | }
60 | return o;
61 | }
62 |
63 | @Override
64 | protected void update() {
65 | if (layer != null) {
66 | removeLayerFromParent();
67 | }
68 | GridLayerOptions o = createOptions();
69 | layer = createGridLayer(o);
70 | GridLayer gridLayer = (GridLayer) layer;
71 | if (hasEventListener(EventId.LOAD)) {
72 | gridLayer.addLoadListener(new LoadListener() {
73 | @Override
74 | public void onLoad(Event event) {
75 | gridLayerServerRpc.onLoad();
76 | }
77 | });
78 | }
79 | if (hasEventListener(EventId.LOADING)) {
80 | gridLayer.addLoadingListener(new LoadingListener() {
81 | @Override
82 | public void onLoading(Event event) {
83 | gridLayerServerRpc.onLoading();
84 | }
85 | });
86 | }
87 | addToParent(layer);
88 | }
89 |
90 | protected GridLayer createGridLayer(GridLayerOptions o) {
91 | return GridLayer.create(o);
92 | }
93 |
94 | @Override
95 | public Layer getLayer() {
96 | return layer;
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/client/LeafletLayersConnector.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.client;
2 |
3 | import org.peimari.gleaflet.client.control.LayersOptions;
4 | import org.vaadin.addon.leaflet.shared.LeafletLayersState;
5 | import org.peimari.gleaflet.client.control.Layers;
6 | import org.vaadin.addon.leaflet.control.LLayers;
7 | import org.vaadin.addon.leaflet.shared.LayerControlInfo;
8 |
9 | import com.vaadin.client.ServerConnector;
10 | import com.vaadin.client.communication.StateChangeEvent;
11 | import com.vaadin.shared.ui.Connect;
12 | import java.util.HashMap;
13 | import java.util.HashSet;
14 | import org.peimari.gleaflet.client.Layer;
15 |
16 | @Connect(LLayers.class)
17 | public class LeafletLayersConnector extends AbstractControlConnector {
18 |
19 | HashMap infoToLayer = new HashMap<>();
20 |
21 | @Override
22 | protected Layers createControl() {
23 | LayersOptions o = createOptions();
24 | Layers l = Layers.create(o);
25 | getParent().setLayersControl(l);
26 | return l;
27 | }
28 |
29 | protected LayersOptions createOptions() {
30 | LayersOptions o = LayersOptions.create();
31 | LeafletLayersState s = getState();
32 |
33 | if (s.collapsed != null) {
34 | o.setCollapsed(s.collapsed);
35 | }
36 | return o;
37 | }
38 |
39 | protected void doStateChange(StateChangeEvent stateChangeEvent) {
40 | if(!infoToLayer.isEmpty()) {
41 | // redrawing list, remove all and then add all
42 | // TODO optimize if somebody uses hundreds of layers
43 | for (LayerControlInfo layerControlInfo : infoToLayer.keySet()) {
44 | getControl().removeLayer(infoToLayer.get(layerControlInfo));
45 | }
46 | infoToLayer.clear();
47 | }
48 | for (ServerConnector connector : getParent().getChildren()) {
49 | if (!(connector instanceof AbstractLeafletLayerConnector>)) {
50 | continue;
51 | }
52 | AbstractLeafletLayerConnector> layerConnector = (AbstractLeafletLayerConnector>) connector;
53 | LayerControlInfo layerControlInfo = getState().layerContolInfo
54 | .get(layerConnector);
55 |
56 | if (layerControlInfo != null && layerControlInfo.name != null) {
57 | if (layerControlInfo.baseLayer) {
58 | getControl().addBaseLayer(layerConnector.getLayer(),
59 | layerControlInfo.name);
60 | } else {
61 | getControl().addOverlay(layerConnector.getLayer(),
62 | layerControlInfo.name);
63 | }
64 | infoToLayer.put(layerControlInfo, layerConnector.getLayer());
65 | }
66 | }
67 | }
68 |
69 | @Override
70 | public LeafletLayersState getState() {
71 | return (LeafletLayersState) super.getState();
72 | }
73 |
74 | }
75 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/client/LeafletPolygonConnector.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.client;
2 |
3 | import com.google.gwt.core.client.JsArray;
4 | import com.google.gwt.json.client.JSONParser;
5 | import com.vaadin.shared.ui.Connect;
6 | import org.peimari.gleaflet.client.Polygon;
7 | import org.peimari.gleaflet.client.PolylineOptions;
8 |
9 | @Connect(org.vaadin.addon.leaflet.LPolygon.class)
10 | public class LeafletPolygonConnector extends LeafletPolylineConnector {
11 |
12 | @Override
13 | protected Polygon createVector(PolylineOptions options) {
14 | return Polygon.createWithHoles(getCoordinatesTwoDimArray(), options);
15 | }
16 |
17 | protected JsArray> getCoordinatesTwoDimArray() {
18 | return JSONParser.parseStrict(getState().geometryjson).isArray().getJavaScriptObject().cast();
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/client/LeafletPolylineConnector.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.client;
2 |
3 | import org.vaadin.addon.leaflet.shared.LeafletPolylineState;
4 | import com.google.gwt.core.client.JsArray;
5 | import com.google.gwt.core.client.Scheduler;
6 | import com.google.gwt.core.client.Scheduler.ScheduledCommand;
7 | import com.google.gwt.json.client.JSONParser;
8 | import com.vaadin.client.MouseEventDetailsBuilder;
9 | import com.vaadin.shared.ui.Connect;
10 | import org.peimari.gleaflet.client.*;
11 | import org.vaadin.addon.leaflet.shared.EventId;
12 |
13 | @Connect(org.vaadin.addon.leaflet.LPolyline.class)
14 | public class LeafletPolylineConnector extends
15 | AbstractLeafletVectorConnector {
16 |
17 | protected AbstractPath marker;
18 |
19 | @Override
20 | protected void update() {
21 | if (marker != null) {
22 | removeLayerFromParent();
23 | marker.removeClickListener();
24 | marker.removeMouseOverListener();
25 | marker.removeMouseOutListener();
26 | marker.removeContextMenuListener();
27 | }
28 | if (getState().geometryjson == null) {
29 | return;
30 | }
31 |
32 | marker = createVector(createOptions());
33 |
34 | marker.addClickListener(new ClickListener() {
35 |
36 | @Override
37 | public void onClick(MouseEvent event) {
38 | rpc.onClick(U.toPoint(event.getLatLng()),
39 | MouseEventDetailsBuilder.buildMouseEventDetails(event.getNativeEvent(), getLeafletMapConnector().getWidget().getElement()));
40 | }
41 | });
42 | if (hasEventListener(EventId.MOUSEOVER)) {
43 | /*
44 | * Add listener lazily to avoid extra event if layer is modified in
45 | * server side listener. This can be removed if "clear and rebuild"
46 | * style component updates are changed into something more
47 | * intelligent at some point.
48 | */
49 | Scheduler.get().scheduleDeferred(new ScheduledCommand() {
50 | @Override
51 | public void execute() {
52 |
53 | marker.addMouseOverListener(new MouseOverListener() {
54 | @Override
55 | public void onMouseOver(MouseEvent event) {
56 | mouseOverRpc.onMouseOver(U.toPoint(event.getLatLng()));
57 | }
58 | });
59 | }
60 | });
61 | }
62 | if (hasEventListener(EventId.MOUSEOUT)) {
63 | marker.addMouseOutListener(new MouseOutListener() {
64 | @Override
65 | public void onMouseOut(MouseEvent event) {
66 | mouseOutRpc.onMouseOut(U.toPoint(event.getLatLng()));
67 | }
68 | });
69 | }
70 |
71 | if (hasEventListener(EventId.CONTEXTMENU)) {
72 | marker.addContextMenuListener(new ContextMenuListener() {
73 | @Override
74 | public void onContextMenu(MouseEvent event) {
75 | contextMenuRpc.onContextMenu(U.toPoint(event.getLatLng()),
76 | MouseEventDetailsBuilder.buildMouseEventDetails(event.getNativeEvent(), getLeafletMapConnector().getWidget().getElement()));
77 | }
78 | });
79 | }
80 |
81 | addToParent(marker);
82 | }
83 |
84 | @Override
85 | public Layer getLayer() {
86 | return marker;
87 | }
88 |
89 | protected AbstractPath createVector(PolylineOptions options) {
90 | return Polyline.createWithArray(getCoordinatesArray(), options);
91 | }
92 |
93 | protected JsArray getCoordinatesArray() {
94 | return JSONParser.parseStrict(getState().geometryjson).isArray().getJavaScriptObject().cast();
95 | }
96 |
97 | }
98 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/client/LeafletRectangleConnector.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.client;
2 |
3 | import org.vaadin.addon.leaflet.shared.LeafletRectangleState;
4 | import com.vaadin.shared.ui.Connect;
5 | import org.peimari.gleaflet.client.*;
6 | import org.vaadin.addon.leaflet.shared.Bounds;
7 |
8 | @Connect(org.vaadin.addon.leaflet.LRectangle.class)
9 | public class LeafletRectangleConnector extends LeafletPolygonConnector {
10 |
11 | @Override
12 | public LeafletRectangleState getState() {
13 | return (LeafletRectangleState) super.getState();
14 | }
15 |
16 | @Override
17 | public Layer getLayer() {
18 | return marker;
19 | }
20 |
21 | @Override
22 | protected Polygon createVector(PolylineOptions options) {
23 | return Rectangle.create(getLatLngBounds(), options);
24 | }
25 |
26 | protected LatLngBounds getLatLngBounds() {
27 | Bounds b = getState().bounds;
28 | LatLngBounds latlngs = LatLngBounds.create(
29 | LatLng.create(b.getSouthWestLat(), b.getSouthWestLon()),
30 | LatLng.create(b.getNorthEastLat(), b.getNorthEastLon()));
31 | return latlngs;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/client/LeafletScaleConnector.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.client;
2 |
3 | import org.vaadin.addon.leaflet.shared.LeafletScaleState;
4 | import org.peimari.gleaflet.client.control.Scale;
5 | import org.peimari.gleaflet.client.control.ScaleOptions;
6 | import org.vaadin.addon.leaflet.control.LScale;
7 |
8 | import com.vaadin.client.communication.StateChangeEvent;
9 | import com.vaadin.shared.ui.Connect;
10 |
11 | @Connect(LScale.class)
12 | public class LeafletScaleConnector extends AbstractControlConnector {
13 |
14 | @Override
15 | protected Scale createControl() {
16 | ScaleOptions o = ScaleOptions.create();
17 | if(getState().imperial != null) {
18 | boolean booleanValue = getState().imperial.booleanValue();
19 | o.setImperial(booleanValue);
20 | }
21 | if(getState().metric != null) {
22 | boolean booleanValue = getState().metric.booleanValue();
23 | o.setMetric(booleanValue);
24 | }
25 | return Scale.create(o);
26 | }
27 |
28 | protected void doStateChange(StateChangeEvent stateChangeEvent) {
29 | super.doStateChange(stateChangeEvent);
30 | }
31 |
32 | @Override
33 | public LeafletScaleState getState() {
34 | return (LeafletScaleState) super.getState();
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/client/LeafletTileLayerConnector.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.client;
2 |
3 | import com.vaadin.shared.ui.Connect;
4 | import org.peimari.gleaflet.client.GridLayer;
5 | import org.peimari.gleaflet.client.GridLayerOptions;
6 | import org.peimari.gleaflet.client.TileLayer;
7 | import org.peimari.gleaflet.client.TileLayerOptions;
8 | import org.vaadin.addon.leaflet.shared.LeafletTileLayerState;
9 |
10 | @Connect(org.vaadin.addon.leaflet.LTileLayer.class)
11 | public class LeafletTileLayerConnector extends LeafletGridLayerConnector {
12 |
13 | @Override
14 | public LeafletTileLayerState getState() {
15 | return (LeafletTileLayerState) super.getState();
16 | }
17 |
18 | @Override
19 | protected TileLayerOptions createOptions() {
20 | TileLayerOptions o = super.createOptions().cast();
21 | LeafletTileLayerState s = getState();
22 |
23 | if (s.detectRetina != null && s.detectRetina) {
24 | o.setDetectRetina(true);
25 | }
26 | if (s.subDomains != null) {
27 | o.setSubDomains(s.subDomains);
28 | }
29 | if (s.minZoom != null) {
30 | o.setMinZoom(s.minZoom);
31 | }
32 | if (s.maxZoom != null) {
33 | o.setMaxZoom(s.maxZoom);
34 | }
35 | if (s.tms != null && s.tms) {
36 | o.setTms(true);
37 | }
38 | if (s.customOptions != null) {
39 | for (String keyName : s.customOptions.keySet()) {
40 | o.setCustomOption(keyName, s.customOptions.get(keyName));
41 | }
42 | }
43 | return o;
44 | }
45 |
46 | @Override
47 | protected GridLayer createGridLayer(GridLayerOptions o) {
48 | return TileLayer.create(getState().url, (TileLayerOptions) o);
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/client/LeafletWmsLayerConnector.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.client;
2 |
3 | import org.peimari.gleaflet.client.Crs;
4 | import org.peimari.gleaflet.client.GridLayerOptions;
5 | import org.peimari.gleaflet.client.WmsLayer;
6 | import org.peimari.gleaflet.client.WmsLayerOptions;
7 | import org.vaadin.addon.leaflet.shared.LeafletWmsLayerState;
8 |
9 | import com.vaadin.shared.ui.Connect;
10 |
11 | @Connect(org.vaadin.addon.leaflet.LWmsLayer.class)
12 | public class LeafletWmsLayerConnector extends LeafletTileLayerConnector {
13 |
14 | @Override
15 | public LeafletWmsLayerState getState() {
16 | return (LeafletWmsLayerState) super.getState();
17 | }
18 |
19 | @Override
20 | protected WmsLayerOptions createOptions() {
21 | WmsLayerOptions o = super.createOptions().cast();
22 | LeafletWmsLayerState s = getState();
23 | if (s.layers != null) {
24 | o.setLayers(s.layers);
25 | }
26 | if (s.layerStyles != null) {
27 | o.setStyles(s.layerStyles);
28 | }
29 | if (s.format != null) {
30 | o.setFormat(s.format);
31 | }
32 | if (s.transparent != null && s.transparent) {
33 | o.setTransparent(true);
34 | }
35 | if (s.version != null) {
36 | o.setVersion(s.version);
37 | }
38 | if (s.crsName != null) {
39 | o.setCrs(Crs.byName(s.crsName));
40 | }
41 | if (s.viewparams != null) {
42 | o.setViewparams(s.viewparams);
43 | }
44 | if (s.cqlFilter != null)
45 | {
46 | o.setCQLFilter(s.cqlFilter);
47 | }
48 | return o;
49 | }
50 |
51 | @Override
52 | protected WmsLayer createGridLayer(GridLayerOptions o) {
53 | return WmsLayer.create(getState().url, (WmsLayerOptions ) o);
54 | }
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/client/LeafletZoomConnector.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.client;
2 |
3 | import org.peimari.gleaflet.client.control.Control;
4 | import org.vaadin.addon.leaflet.control.LZoom;
5 |
6 | import com.vaadin.shared.ui.Connect;
7 |
8 | @Connect(LZoom.class)
9 | public class LeafletZoomConnector extends AbstractDefaultControl {
10 |
11 | @Override
12 | protected Control createControl() {
13 | return getMap().getZoomControl();
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/client/MapWidget.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.client;
2 |
3 | import com.google.gwt.dom.client.DivElement;
4 | import com.google.gwt.dom.client.Document;
5 | import com.google.gwt.dom.client.Style.Position;
6 | import com.google.gwt.dom.client.Style.Unit;
7 | import com.google.gwt.user.client.ui.Widget;
8 |
9 | public class MapWidget extends Widget {
10 |
11 | public MapWidget() {
12 | setElement(Document.get().createDivElement());
13 | getElement().getStyle().setPosition(Position.RELATIVE);
14 | DivElement d = Document.get().createDivElement();
15 | getElement().appendChild(d);
16 | d.getStyle().setHeight(100, Unit.PCT);
17 | setStyleName("v-leaflet");
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/client/StyleUtil.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.client;
2 |
3 | import com.vaadin.shared.AbstractComponentState;
4 | import com.vaadin.shared.ui.ComponentStateUtil;
5 |
6 | final class StyleUtil {
7 | private StyleUtil(){}
8 |
9 | /**
10 | * Retrieves the primaryStyleName and other styles that are set in the componentState and composes them to
11 | * one string where each className is separated by an empty space " ".
12 | * Checks whether values are set or not.
13 | */
14 | static String getStyleNameFromComponentState(AbstractComponentState componentState) {
15 | StringBuilder styleNameBuilder = new StringBuilder();
16 | if (componentState.primaryStyleName != null)
17 | styleNameBuilder.append(componentState.primaryStyleName);
18 |
19 | if(ComponentStateUtil.hasStyles(componentState)) {
20 | for (String s : componentState.styles) {
21 | if (styleNameBuilder.length() > 0)
22 | styleNameBuilder.append(" ");
23 |
24 | styleNameBuilder.append(s);
25 | }
26 | }
27 | return styleNameBuilder.toString();
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/client/U.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.client;
2 |
3 | import com.vaadin.client.VConsole;
4 | import org.peimari.gleaflet.client.LatLng;
5 | import org.peimari.gleaflet.client.LatLngBounds;
6 | import org.vaadin.addon.leaflet.shared.Bounds;
7 | import org.vaadin.addon.leaflet.shared.Point;
8 |
9 | public class U {
10 |
11 | public static Point toPoint(org.peimari.gleaflet.client.Point point) {
12 | VConsole.log("Point " + point.getX() + " " + point.getY());
13 | return new Point(point.getY(), point.getX());
14 | }
15 |
16 | public static Point toPoint(LatLng latLng) {
17 | return new Point(latLng.getLatitude(), latLng.getLongitude());
18 | }
19 |
20 | public static Point[] toPointArray(LatLng[] latLngs) {
21 | Point[] r = new Point[latLngs.length];
22 | for (int i = 0; i < r.length; i++) {
23 | r[i] = toPoint(latLngs[i]);
24 | }
25 | return r;
26 | }
27 |
28 | public static Bounds toBounds(LatLngBounds b) {
29 | return new Bounds(
30 | new Point(b.getSouthWest().getLatitude(), b.getSouthWest().getLongitude()),
31 | new Point(b.getNorthEast().getLatitude(), b.getNorthEast().getLongitude()));
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/control/AbstractControl.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.control;
2 |
3 | import org.vaadin.addon.leaflet.shared.LeafletControlState;
4 | import org.vaadin.addon.leaflet.shared.ControlPosition;
5 |
6 | import com.vaadin.server.AbstractExtension;
7 |
8 | public abstract class AbstractControl extends AbstractExtension {
9 |
10 | public AbstractControl() {
11 | super();
12 | }
13 |
14 | @Override
15 | protected LeafletControlState getState() {
16 | return (LeafletControlState) super.getState();
17 | }
18 |
19 | public void setPosition(ControlPosition position) {
20 | getState().position = position;
21 | }
22 |
23 | public ControlPosition getPosition() {
24 | return getState().position;
25 | }
26 |
27 | }
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/control/AbstractDefaultControl.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.control;
2 |
3 | public abstract class AbstractDefaultControl extends AbstractControl {
4 |
5 | public void setEnabled(boolean enabled) {
6 | getState().enabled = enabled;
7 | }
8 |
9 | public boolean isEnabled() {
10 | return getState(false).enabled;
11 | }
12 |
13 | }
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/control/LAttribution.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.control;
2 |
3 | import org.vaadin.addon.leaflet.shared.LeafletAttributionState;
4 |
5 | public class LAttribution extends AbstractDefaultControl {
6 |
7 | @Override
8 | protected LeafletAttributionState getState() {
9 | return (LeafletAttributionState) super.getState();
10 | }
11 |
12 | public void setPrefix(String prefix) {
13 | getState().prefix = prefix;
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/control/LLayers.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.control;
2 |
3 | import org.vaadin.addon.leaflet.LeafletLayer;
4 | import org.vaadin.addon.leaflet.shared.LeafletLayersState;
5 | import org.vaadin.addon.leaflet.shared.LayerControlInfo;
6 |
7 |
8 | public class LLayers extends AbstractControl {
9 |
10 | public LLayers() {
11 | super();
12 | }
13 | public LLayers(LLayers lLayers) {
14 | super();
15 | LeafletLayersState state = getState();
16 | state.collapsed = lLayers.getState().collapsed;
17 | state.layerContolInfo = lLayers.getState().layerContolInfo;
18 | }
19 |
20 | public void addOverlay(LeafletLayer overlay, String name) {
21 | LayerControlInfo info = new LayerControlInfo();
22 | info.baseLayer = false;
23 | info.name = name;
24 | getState().layerContolInfo.put(overlay, info);
25 | }
26 |
27 | @Override
28 | protected LeafletLayersState getState() {
29 | return (LeafletLayersState) super.getState();
30 | }
31 |
32 | public void addBaseLayer(LeafletLayer baseLayer, String name) {
33 | LayerControlInfo info = new LayerControlInfo();
34 | info.baseLayer = true;
35 | info.name = name;
36 | getState().layerContolInfo.put(baseLayer, info);
37 | }
38 |
39 | public void removeLayer(LeafletLayer c) {
40 | getState().layerContolInfo.remove(c);
41 | }
42 |
43 | public void setCollapsed(Boolean collapsed) {
44 | getState().collapsed = collapsed;
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/control/LScale.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.control;
2 |
3 | import org.vaadin.addon.leaflet.shared.LeafletScaleState;
4 |
5 | public class LScale extends AbstractControl {
6 |
7 | @Override
8 | protected LeafletScaleState getState() {
9 | return (LeafletScaleState) super.getState();
10 | }
11 |
12 | public void setImperial(boolean showImperial) {
13 | getState().imperial = showImperial;
14 | }
15 |
16 | public void setMetric(boolean showMetric) {
17 | getState().metric = showMetric;
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/control/LZoom.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.control;
2 |
3 |
4 | public class LZoom extends AbstractDefaultControl {
5 |
6 | }
7 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/jsonmodels/BasicMap.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.jsonmodels;
2 |
3 | import com.fasterxml.jackson.core.JsonProcessingException;
4 | import java.io.Serializable;
5 | import java.util.HashMap;
6 | import static org.vaadin.addon.leaflet.jsonmodels.VectorStyle.mapper;
7 |
8 | /**
9 | * @author mstahv
10 | */
11 | public class BasicMap extends HashMap {
12 |
13 | public String asJson() {
14 | try {
15 | return mapper.writeValueAsString(this);
16 | } catch (JsonProcessingException ex) {
17 | throw new RuntimeException(ex);
18 | }
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/jsonmodels/PointArray.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.jsonmodels;
2 |
3 | import com.fasterxml.jackson.core.JsonProcessingException;
4 | import org.vaadin.addon.leaflet.shared.Point;
5 |
6 | import java.util.ArrayList;
7 | import java.util.Arrays;
8 | import java.util.Collection;
9 | import java.util.Collections;
10 |
11 | public class PointArray extends ArrayList {
12 | public PointArray() {
13 | }
14 |
15 | public PointArray(Point... points) {
16 | this(Arrays.asList(points));
17 | }
18 |
19 | public PointArray(Collection extends Point> c) {
20 | super(c);
21 | }
22 |
23 | public void sanitize() {
24 | removeAll(Collections.singleton(null));
25 | }
26 |
27 | public String asJson() {
28 | try {
29 | return VectorStyle.mapper.writeValueAsString(this);
30 | } catch (JsonProcessingException ex) {
31 | throw new RuntimeException(ex);
32 | }
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/jsonmodels/PointMultiArray.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.jsonmodels;
2 |
3 | import com.fasterxml.jackson.core.JsonProcessingException;
4 |
5 | import java.util.ArrayList;
6 | import java.util.Collection;
7 |
8 | public class PointMultiArray extends ArrayList {
9 |
10 | public PointMultiArray() {
11 | }
12 |
13 | public PointMultiArray(Collection extends PointArray> c) {
14 | super(c);
15 | }
16 |
17 | public String asJson() {
18 | try {
19 | return VectorStyle.mapper.writeValueAsString(this);
20 | } catch (JsonProcessingException ex) {
21 | throw new RuntimeException(ex);
22 | }
23 | }
24 |
25 | public void sanitize() {
26 | for (PointArray pa : this) {
27 | pa.sanitize();
28 | }
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/jsonmodels/VectorStyle.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.jsonmodels;
2 |
3 | import com.fasterxml.jackson.annotation.JsonInclude;
4 | import com.fasterxml.jackson.core.JsonProcessingException;
5 | import com.fasterxml.jackson.databind.ObjectMapper;
6 | import java.io.Serializable;
7 |
8 | public class VectorStyle implements Serializable {
9 |
10 | static final ObjectMapper mapper = new ObjectMapper();
11 | static {
12 | mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
13 | }
14 |
15 | private Boolean stroke;
16 |
17 | private Boolean fill;
18 |
19 | private String fillColor;
20 |
21 | private Double fillOpacity;
22 |
23 | private Integer weight;
24 |
25 | private Double opacity;
26 |
27 | private String dashArray;
28 |
29 | private String lineCap;
30 |
31 | private String lineJoin;
32 |
33 | private String color;
34 |
35 | public void setFill(Boolean fill) {
36 | this.fill = fill;
37 | }
38 |
39 | public Boolean getFill() {
40 | return fill;
41 | }
42 |
43 | public void setOpacity(Double opacity) {
44 | this.opacity = opacity;
45 | }
46 |
47 | public Double getOpacity() {
48 | return opacity;
49 | }
50 |
51 | public void setFillColor(String fillColor) {
52 | this.fillColor = fillColor;
53 | }
54 |
55 | public String getFillColor() {
56 | return fillColor;
57 | }
58 |
59 | public Double getFillOpacity() {
60 | return fillOpacity;
61 | }
62 |
63 | public void setFillOpacity(Double fillOpacity) {
64 | this.fillOpacity = fillOpacity;
65 | }
66 |
67 | public void setWeight(Integer weight) {
68 | this.weight = weight;
69 | }
70 |
71 | public Integer getWeight() {
72 | return weight;
73 | }
74 |
75 | public void setColor(String color) {
76 | this.color = color;
77 | }
78 |
79 | public String getColor() {
80 | return color;
81 | }
82 |
83 | public Boolean getStroke() {
84 | return stroke;
85 | }
86 |
87 | public void setStroke(Boolean stroke) {
88 | this.stroke = stroke;
89 | }
90 |
91 | public String getDashArray() {
92 | return dashArray;
93 | }
94 |
95 | public void setDashArray(String dashArray) {
96 | this.dashArray = dashArray;
97 | }
98 |
99 | public String getLineCap() {
100 | return lineCap;
101 | }
102 |
103 | public void setLineCap(String lineCap) {
104 | this.lineCap = lineCap;
105 | }
106 |
107 | public String getLineJoin() {
108 | return lineJoin;
109 | }
110 |
111 | public void setLineJoin(String lineJoin) {
112 | this.lineJoin = lineJoin;
113 | }
114 |
115 | public String asJson() {
116 | try {
117 | return mapper.writeValueAsString(this);
118 | } catch (JsonProcessingException ex) {
119 | throw new RuntimeException(ex);
120 | }
121 | }
122 |
123 | }
124 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/shared/AbstractLeafletComponentState.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.shared;
2 |
3 | import com.vaadin.shared.ui.AbstractComponentContainerState;
4 |
5 | public class AbstractLeafletComponentState extends AbstractComponentContainerState {
6 | public Boolean active;
7 | }
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/shared/AbstractLeafletDivOverlayState.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.shared;
2 |
3 | public class AbstractLeafletDivOverlayState extends AbstractLeafletComponentState {
4 |
5 | public Point point;
6 | public String htmlContent;
7 | }
8 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/shared/AbstractLeafletVectorState.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.shared;
2 |
3 | public class AbstractLeafletVectorState extends AbstractLeafletComponentState {
4 |
5 | public String vectorStyleJson;
6 | public Boolean clickable;
7 | public String pointerEvents;
8 | public Boolean bubblingMouseEvents;
9 | public String className;
10 | public String tooltip;
11 | public TooltipState tooltipState;
12 | public String popup;
13 | public PopupState popupState;
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/shared/Bounds.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.shared;
2 |
3 | import java.io.Serializable;
4 |
5 | public class Bounds implements Serializable {
6 |
7 | private double southWestLng;
8 | private double southWestLat;
9 | private double northEastLng;
10 | private double northEastLat;
11 |
12 | public Bounds() {
13 | setSouthWestLat(Double.MAX_VALUE);
14 | setSouthWestLon(Double.MAX_VALUE);
15 | setNorthEastLat(Double.NEGATIVE_INFINITY);
16 | setNorthEastLon(Double.NEGATIVE_INFINITY);
17 | }
18 |
19 | public Bounds(String bounds) {
20 | String[] split = bounds.split(",");
21 | setSouthWestLon(Double.parseDouble(split[0]));
22 | setSouthWestLat(Double.parseDouble(split[1]));
23 | setNorthEastLon(Double.parseDouble(split[2]));
24 | setNorthEastLat(Double.parseDouble(split[3]));
25 | }
26 |
27 | public Bounds(Point... points) {
28 | this();
29 | extend(points);
30 | }
31 |
32 | public double getSouthWestLon() {
33 | return southWestLng;
34 | }
35 |
36 | public void setSouthWestLon(double southWestLng) {
37 | this.southWestLng = southWestLng;
38 | }
39 |
40 | public double getSouthWestLat() {
41 | return southWestLat;
42 | }
43 |
44 | public void setSouthWestLat(double southWestLat) {
45 | this.southWestLat = southWestLat;
46 | }
47 |
48 | public double getNorthEastLon() {
49 | return northEastLng;
50 | }
51 |
52 | public void setNorthEastLon(double northEastLng) {
53 | this.northEastLng = northEastLng;
54 | }
55 |
56 | public double getNorthEastLat() {
57 | return northEastLat;
58 | }
59 |
60 | public void setNorthEastLat(double northEastLat) {
61 | this.northEastLat = northEastLat;
62 | }
63 |
64 | public void extend(Point... points) {
65 | for (Point point : points) {
66 | extend(point.getLat(), point.getLon());
67 | }
68 | }
69 |
70 | public void extend(double latitude, double longitude) {
71 | setNorthEastLat(Math.max(getNorthEastLat(), latitude));
72 | setNorthEastLon(Math.max(getNorthEastLon(), longitude));
73 | setSouthWestLat(Math.min(getSouthWestLat(), latitude));
74 | setSouthWestLon(Math.min(getSouthWestLon(), longitude));
75 | }
76 |
77 | public Point getCenter() {
78 | return new Point((getNorthEastLat() + getSouthWestLat()) / 2,
79 | (getNorthEastLon() + getSouthWestLon()) / 2);
80 | }
81 |
82 | @Override
83 | public String toString() {
84 | return "Bounds{" + "southWestLng=" + southWestLng + ", southWestLat=" + southWestLat + ", northEastLng=" + northEastLng + ", northEastLat=" + northEastLat + '}';
85 | }
86 |
87 | }
88 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/shared/ClickServerRpc.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.shared;
2 |
3 |
4 | import com.vaadin.shared.MouseEventDetails;
5 | import com.vaadin.shared.communication.ServerRpc;
6 |
7 | public interface ClickServerRpc extends ServerRpc {
8 |
9 | void onClick(Point p, MouseEventDetails d);
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/shared/ContextMenuServerRpc.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.shared;
2 |
3 |
4 | import com.vaadin.shared.MouseEventDetails;
5 | import com.vaadin.shared.communication.ServerRpc;
6 |
7 | public interface ContextMenuServerRpc extends ServerRpc {
8 |
9 | void onContextMenu(Point p, MouseEventDetails d);
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/shared/Control.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.shared;
2 |
3 | /**
4 | *
5 | */
6 | @Deprecated
7 | public enum Control {
8 | zoom, attribution, scale
9 | }
10 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/shared/ControlPosition.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.shared;
2 |
3 | public enum ControlPosition {
4 | topleft, topright, bottomleft, bottomright
5 | }
6 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/shared/Crs.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Vaadin Community.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.vaadin.addon.leaflet.shared;
17 |
18 | /**
19 | * Encapsulates a Coordinate Reference System for v-leaflet
20 | *
21 | * @author Warwick Dufour
22 | */
23 | public class Crs {
24 |
25 | /**
26 | * Leaflet specific
27 | */
28 | public static final Crs Simple = new Crs("Simple");
29 | /**
30 | * WGS 84
31 | */
32 | public static final Crs EPSG4326 = new Crs("EPSG4326");
33 | /**
34 | * WGS 84 / World Mercator
35 | */
36 | public static final Crs EPSG3395 = new Crs("EPSG3395");
37 | /**
38 | * WGS 84 / Pseudo-Mercator
39 | */
40 | public static final Crs EPSG3857 = new Crs("EPSG3857");
41 |
42 | private final String name;
43 |
44 | public Crs(String name) {
45 | this.name = name;
46 | }
47 |
48 | public String getName() {
49 | return name;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/shared/DivOverlayState.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.shared;
2 |
3 | import java.io.Serializable;
4 |
5 | public class DivOverlayState implements Serializable {
6 |
7 | public Point offset;
8 | public String pane;
9 | }
10 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/shared/DragEndServerRpc.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.shared;
2 |
3 |
4 | import com.vaadin.shared.communication.ServerRpc;
5 |
6 | public interface DragEndServerRpc extends ServerRpc {
7 |
8 | void dragEnd(Point point);
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/shared/EventId.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.shared;
2 |
3 | /**
4 | * Event identifiers for client-server communication. By convention these can be
5 | * e.g. method names from server side listeners.
6 | *
7 | */
8 | public interface EventId {
9 |
10 | public static final String LOAD = "onLoad";
11 | public static final String LOADING = "onLoading";
12 | public static final String MOUSEOVER = "onMouseOver";
13 | public static final String MOUSEOUT = "onMouseOut";
14 | public static final String CONTEXTMENU = "onContextMenu";
15 | public static final String LOCATE = "onLocate";
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/shared/ILayerClientRpc.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 Vaadin Community.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.vaadin.addon.leaflet.shared;
18 |
19 | import com.vaadin.shared.communication.ClientRpc;
20 |
21 | /**
22 | *
23 | */
24 | public interface ILayerClientRpc extends ClientRpc {
25 |
26 | public void bringToFront();
27 |
28 | public void bringToBack();
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/shared/LayerControlInfo.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.shared;
2 |
3 | import java.io.Serializable;
4 |
5 |
6 | public class LayerControlInfo implements Serializable {
7 | public boolean baseLayer;
8 | public String name;
9 | }
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/shared/LeafletAttributionState.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Vaadin Community.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.vaadin.addon.leaflet.shared;
17 |
18 |
19 | /**
20 | */
21 | public class LeafletAttributionState extends LeafletControlState {
22 | public String prefix;
23 | }
24 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/shared/LeafletCircleState.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.shared;
2 |
3 |
4 | public class LeafletCircleState extends AbstractLeafletVectorState {
5 |
6 | public Double radius;
7 | public Point point;
8 | }
9 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/shared/LeafletControlState.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Vaadin Community.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.vaadin.addon.leaflet.shared;
17 |
18 |
19 | import com.vaadin.shared.communication.SharedState;
20 |
21 | /**
22 | */
23 | public class LeafletControlState extends SharedState {
24 | public ControlPosition position;
25 | }
26 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/shared/LeafletGridLayerServerRpc.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.shared;
2 |
3 | import com.vaadin.shared.communication.ServerRpc;
4 |
5 | public interface LeafletGridLayerServerRpc extends ServerRpc {
6 |
7 | // @Delayed(lastOnly = true)
8 | void onLoad();
9 |
10 | //@Delayed(lastOnly = true)
11 | void onLoading();
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/shared/LeafletGridLayerState.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.shared;
2 |
3 | public class LeafletGridLayerState extends AbstractLeafletComponentState {
4 |
5 | public Double opacity;
6 | public Integer zIndex;
7 | public Bounds bounds;
8 | public Integer maxNativeZoom;
9 | public Integer minNativeZoom;
10 | public Boolean noWrap;
11 | public String attributionString;
12 | public Integer tileSize;
13 | }
14 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/shared/LeafletImageOverlayState.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.shared;
2 |
3 | public class LeafletImageOverlayState extends AbstractLeafletVectorState {
4 |
5 | public Bounds bounds;
6 | public Double opacity;
7 | public String alt;
8 | public Boolean interactive;
9 | public Integer zIndex;
10 | public String attribution;
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/shared/LeafletLayerGroupState.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Vaadin Community.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.vaadin.addon.leaflet.shared;
17 |
18 | public class LeafletLayerGroupState extends AbstractLeafletComponentState {
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/shared/LeafletLayersState.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Vaadin Community.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.vaadin.addon.leaflet.shared;
17 |
18 | import java.util.HashMap;
19 | import java.util.Map;
20 |
21 |
22 | import com.vaadin.shared.Connector;
23 |
24 | /**
25 | *
26 | * @author mattitahvonenitmill
27 | */
28 | public class LeafletLayersState extends LeafletControlState {
29 |
30 | public Map layerContolInfo = new HashMap();
31 | public Boolean collapsed;
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/shared/LeafletMapClientRpc.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.shared;
2 |
3 |
4 | import com.vaadin.shared.communication.ClientRpc;
5 |
6 | public interface LeafletMapClientRpc extends ClientRpc {
7 |
8 | void setCenter(Double lat, Double lon, Double zoom);
9 | void flyTo(Double lat, Double lon, Double zoom);
10 | void zoomToExtent(Bounds bounds);
11 | void setMaxBounds(Bounds bounds);
12 | void setDragging(boolean dragging);
13 | void setTouchZoom(boolean touchZoome);
14 | void setDoubleClickZoom(boolean doubleClickZoom);
15 | void setBoxZoom(boolean boxZoom);
16 | void setScrollWheelZoom(boolean scrollWheelZoom);
17 | void setKeyboard(boolean keyboard);
18 | void locate(boolean watch, boolean highaccuracy, boolean updateView);
19 | void stopLocate();
20 | public void translate(int x, int y);
21 |
22 | void getSize();
23 |
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/shared/LeafletMapServerRpc.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Vaadin Community.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.vaadin.addon.leaflet.shared;
17 |
18 |
19 | import com.vaadin.shared.MouseEventDetails;
20 | import com.vaadin.shared.annotations.Delayed;
21 | import com.vaadin.shared.communication.ServerRpc;
22 |
23 | /**
24 | *
25 | * @author mstahv
26 | */
27 | public interface LeafletMapServerRpc extends ServerRpc {
28 |
29 | void onClick(Point location, MouseEventDetails details);
30 |
31 | @Delayed(lastOnly=true)
32 | void onMoveEnd(Bounds bounds, Point center, double zoomlevel);
33 |
34 | void onContextMenu(Point location, MouseEventDetails details);
35 |
36 | void onBaseLayerChange(String name);
37 |
38 | void onOverlayAdd(String name);
39 |
40 | void onOverlayRemove(String name);
41 |
42 | @Delayed(lastOnly = true)
43 | void onLocate(Point location, Double accuracy, Double altitude, Double speed);
44 |
45 | void onLocateError(String error, int code);
46 |
47 | void onTranslate(Point point);
48 |
49 | void onSize(double x, double y);
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/shared/LeafletMapState.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Vaadin Community.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.vaadin.addon.leaflet.shared;
17 |
18 |
19 | import com.vaadin.shared.Connector;
20 | import com.vaadin.shared.ui.AbstractComponentContainerState;
21 |
22 | /**
23 | *
24 | * @author mattitahvonenitmill
25 | */
26 | public class LeafletMapState extends AbstractComponentContainerState {
27 |
28 | public Point center;
29 | public Double zoomLevel;
30 |
31 | public Bounds zoomToExtent;
32 |
33 | public String attributionPrefix = "Leaflet";
34 | public Bounds maxBounds;
35 | public Integer minZoom;
36 | public Integer maxZoom;
37 |
38 | /* This should be replaced with a more decent api */
39 | public String customMapOptionsJson;
40 |
41 | /**
42 | * Internal String identifier of CRS that is meaningful to v-leaflet
43 | * client.
44 | */
45 | public String crsName;
46 | public String newCrsName;
47 | public String newCrsProjection;
48 | public double newCrsA;
49 | public double newCrsB;
50 | public double newCrsC;
51 | public double newCrsD;
52 | public double newCrsMinX;
53 | public double newCrsMinY;
54 | public double newCrsMaxX;
55 | public double newCrsMaxY;
56 |
57 | public Boolean dragging;
58 | public Boolean touchZoom;
59 | public Boolean doubleClickZoom;
60 | public Boolean boxZoom;
61 | public Boolean scrollWheelZoom;
62 | public Double zoomSnap;
63 | public Double zoomDelta;
64 | public Boolean keyboard;
65 | public Boolean readOnly;
66 | public Connector[] updateLayersOnLocate;
67 |
68 | public int minLocateInterval = 5000;
69 | }
70 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/shared/LeafletMarkerClientRpc.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.shared;
2 |
3 | import com.vaadin.shared.communication.ClientRpc;
4 |
5 | public interface LeafletMarkerClientRpc extends ClientRpc {
6 |
7 | public void openTooltip();
8 | public void closeTooltip();
9 | public void openPopup();
10 | public void closePopup();
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/shared/LeafletMarkerState.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.shared;
2 |
3 | public class LeafletMarkerState extends AbstractLeafletComponentState {
4 |
5 | public Point point;
6 | public Point iconSize;
7 | public Point iconAnchor;
8 | public String iconPathFill;
9 | public String iconPathStroke;
10 | public String iconTextFill;
11 | public Point popupAnchor;
12 | public String divIcon;
13 | public String title;
14 | public String tooltip;
15 | public TooltipState tooltipState;
16 | public String popup;
17 | public PopupState popupState;
18 | public Boolean draggable;
19 | public Integer zIndexOffset;
20 | public String markerChar;
21 | }
22 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/shared/LeafletPolylineState.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.shared;
2 |
3 | public class LeafletPolylineState extends AbstractLeafletVectorState {
4 |
5 | public String geometryjson;
6 | }
7 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/shared/LeafletPopupState.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.shared;
2 |
3 |
4 | public class LeafletPopupState extends AbstractLeafletDivOverlayState {
5 |
6 | {
7 | primaryStyleName = "l-popup";
8 | }
9 |
10 | public PopupState popupState = new PopupState();
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/shared/LeafletRectangleState.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.shared;
2 |
3 | public class LeafletRectangleState extends LeafletPolylineState {
4 |
5 | public Bounds bounds;
6 | }
7 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/shared/LeafletScaleState.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Vaadin Community.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.vaadin.addon.leaflet.shared;
17 |
18 |
19 | /**
20 | */
21 | public class LeafletScaleState extends LeafletControlState {
22 | public Boolean imperial;
23 | public Boolean metric;
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/shared/LeafletTileLayerServerRpc.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.shared;
2 |
3 | import com.vaadin.shared.communication.ServerRpc;
4 |
5 | public interface LeafletTileLayerServerRpc extends ServerRpc
6 | {
7 | // @Delayed(lastOnly = true)
8 | void onLoad();
9 |
10 | //@Delayed(lastOnly = true)
11 | void onLoading();
12 | }
13 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/shared/LeafletTileLayerState.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.shared;
2 |
3 | import java.util.Map;
4 |
5 | public class LeafletTileLayerState extends LeafletGridLayerState {
6 |
7 | public String url;
8 | public Boolean detectRetina;
9 | public Boolean tms;
10 | public Integer minZoom;
11 | public Integer maxZoom;
12 | public String[] subDomains;
13 | public Map customOptions;
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/shared/LeafletTooltipState.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.shared;
2 |
3 | public class LeafletTooltipState extends AbstractLeafletDivOverlayState {
4 |
5 | public TooltipState tooltipState = new TooltipState();
6 | }
7 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/shared/LeafletWmsLayerState.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.shared;
2 |
3 | public class LeafletWmsLayerState extends LeafletTileLayerState {
4 |
5 | public String layers;
6 | public String layerStyles;
7 | public String format;
8 | public Boolean transparent;
9 | public String version;
10 | public String crsName;
11 | public String viewparams;
12 | public String cqlFilter;
13 | }
14 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/shared/MouseOutServerRpc.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.shared;
2 |
3 |
4 | import com.vaadin.shared.communication.ServerRpc;
5 |
6 | public interface MouseOutServerRpc extends ServerRpc {
7 |
8 | void onMouseOut(Point p);
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/shared/MouseOverServerRpc.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.shared;
2 |
3 |
4 | import com.vaadin.shared.communication.ServerRpc;
5 |
6 | public interface MouseOverServerRpc extends ServerRpc {
7 |
8 | void onMouseOver(Point p);
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/shared/Point.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.shared;
2 |
3 | import com.fasterxml.jackson.annotation.JsonValue;
4 |
5 | import java.io.Serializable;
6 | import java.util.Objects;
7 |
8 | public class Point implements Serializable {
9 | private Double lon;
10 | private Double lat;
11 |
12 | public Point() {
13 | }
14 |
15 | public Point(double lat, double lon) {
16 | this.lon = lon;
17 | this.lat = lat;
18 | }
19 | public Double getLon() {
20 | return lon;
21 | }
22 | public void setLon(Double lon) {
23 | this.lon = lon;
24 | }
25 | public Double getLat() {
26 | return lat;
27 | }
28 | public void setLat(Double lat) {
29 | this.lat = lat;
30 | }
31 |
32 | @Override
33 | public String toString() {
34 | return lat + "," + lon;
35 | }
36 |
37 | @JsonValue
38 | public Double[] getLatLonPair() {
39 | return new Double[]{lat,lon};
40 | }
41 |
42 | @Override
43 | public int hashCode() {
44 | int hash = 3;
45 | return hash*(lon == null ? 0 : lon.intValue());
46 | }
47 |
48 | @Override
49 | public boolean equals(Object obj) {
50 | if (this == obj) {
51 | return true;
52 | }
53 | if (obj == null) {
54 | return false;
55 | }
56 | if (getClass() != obj.getClass()) {
57 | return false;
58 | }
59 | final Point other = (Point) obj;
60 | if (!Objects.equals(this.lon, other.lon)) {
61 | return false;
62 | }
63 | if (!Objects.equals(this.lat, other.lat)) {
64 | return false;
65 | }
66 | return true;
67 | }
68 |
69 |
70 |
71 | }
72 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/shared/PopupServerRpc.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.shared;
2 |
3 | import com.vaadin.shared.communication.ServerRpc;
4 |
5 | public interface PopupServerRpc extends ServerRpc {
6 |
7 | void closed();
8 |
9 | }
10 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/shared/PopupState.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.shared;
2 |
3 | public class PopupState extends DivOverlayState {
4 | public int maxWidth = 300;
5 | public int minWidth = 50;
6 | public int maxHeight = 0;
7 | public boolean autoPan;
8 | public boolean closeButton = true;
9 | public boolean closeOnClick = true;
10 | public boolean autoClose = true;
11 | public boolean keepInView;
12 | public Point autoPanPadding;
13 | public boolean zoomAnimation = true;
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/shared/TooltipState.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.shared;
2 |
3 | public class TooltipState extends DivOverlayState {
4 |
5 | public String direction;
6 | public Boolean permanent;
7 | public Boolean sticky;
8 | public Boolean interactive;
9 | public Double opacity;
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/util/CRSTranslator.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.util;
2 |
3 | import org.locationtech.jts.geom.Geometry;
4 |
5 | public interface CRSTranslator {
6 |
7 | /**
8 | * Converts a geometry to a CRS suitable for Leaflet (WGS84 aka
9 | * EPSG:4326)
10 | *
11 | * @param geom the geometry to be translated
12 | * @return geometry transformed to EPSG:4326
13 | */
14 | T toPresentation(T geom);
15 |
16 | /**
17 | * Converts geometry coming from V-Leaflet (in WGS84 aka EPSG:4326) to
18 | * another CRS for model.
19 | *
20 | * @param geom the geometry to be translated
21 | * @return the translated geometry
22 | */
23 | T toModel(T geom);
24 | }
--------------------------------------------------------------------------------
/src/main/java/org/vaadin/addon/leaflet/util/PointField.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.util;
2 |
3 | import com.vaadin.shared.Registration;
4 | import org.locationtech.jts.geom.Point;
5 | import org.vaadin.addon.leaflet.LMarker;
6 | import org.vaadin.addon.leaflet.LMarker.DragEndEvent;
7 | import org.vaadin.addon.leaflet.LMarker.DragEndListener;
8 |
9 | import org.vaadin.addon.leaflet.LeafletClickEvent;
10 | import org.vaadin.addon.leaflet.LeafletClickListener;
11 |
12 | public class PointField extends AbstractJTSField {
13 |
14 | private LMarker marker;
15 | private Registration drawRegistration;
16 | private Registration clickRegistration;
17 | private Registration markerRegisration;
18 |
19 | public PointField() {
20 |
21 | }
22 |
23 | public PointField(String caption) {
24 | this();
25 | setCaption(caption);
26 | }
27 |
28 | @Override
29 | protected void prepareEditing(boolean userOriginatedValueChangeEvent) {
30 | if (marker == null) {
31 | marker = new LMarker(JTSUtil.toLeafletPoint(getCrsTranslator()
32 | .toPresentation(getValue())));
33 | map.addLayer(marker);
34 | } else {
35 | marker.setPoint(JTSUtil.toLeafletPoint(getCrsTranslator()
36 | .toPresentation(getValue())));
37 | }
38 |
39 | drawRegistration = marker.addDragEndListener(editDragEndListener);
40 | clickRegistration = map.addClickListener(editClickListener);
41 |
42 | map.zoomToContent();
43 | }
44 |
45 | @Override
46 | protected void prepareDrawing() {
47 | if (marker != null) {
48 | map.removeComponent(marker);
49 | marker = null;
50 | }
51 | markerRegisration = map.addClickListener(drawListener);
52 | }
53 |
54 | @Override
55 | protected void prepareViewing() {
56 | if (drawRegistration != null) {
57 | drawRegistration.remove();
58 | drawRegistration = null;
59 | }
60 | if (clickRegistration != null) {
61 | clickRegistration.remove();
62 | clickRegistration = null;
63 | }
64 | if (markerRegisration != null) {
65 | markerRegisration.remove();
66 | markerRegisration = null;
67 | }
68 | }
69 |
70 | protected LMarker getMarker() {
71 | return marker;
72 | }
73 |
74 | private final LeafletClickListener drawListener = new LeafletClickListener() {
75 |
76 | @Override
77 | public void onClick(LeafletClickEvent event) {
78 | org.vaadin.addon.leaflet.shared.Point point = event.getPoint();
79 | setValue(getCrsTranslator().toModel(JTSUtil.toPoint(point)));
80 | if (clickRegistration != null) {
81 | clickRegistration.remove();
82 | clickRegistration = null;
83 | }
84 | }
85 | };
86 |
87 | private final LeafletClickListener editClickListener = new LeafletClickListener() {
88 | @Override
89 | public void onClick(LeafletClickEvent event) {
90 | setValue(getCrsTranslator().toModel(
91 | JTSUtil.toPoint(event.getPoint())));
92 | marker.setPoint(event.getPoint());
93 | }
94 | };
95 |
96 | private final DragEndListener editDragEndListener = new DragEndListener() {
97 | @Override
98 | public void dragEnd(DragEndEvent event) {
99 | setValue(getCrsTranslator()
100 | .toModel(JTSUtil.toPoint(marker)));
101 | }
102 | };
103 | }
104 |
--------------------------------------------------------------------------------
/src/test/java/org/vaadin/addon/leaflet/demoandtestapp/AddOverlayBugTest.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.demoandtestapp;
2 |
3 | import com.vaadin.server.ExternalResource;
4 | import org.vaadin.addon.leaflet.LMap;
5 | import org.vaadin.addon.leaflet.LOpenStreetMapLayer;
6 | import org.vaadin.addon.leaflet.LWmsLayer;
7 | import org.vaadin.addonhelpers.AbstractTest;
8 |
9 | import com.vaadin.ui.Button;
10 | import com.vaadin.ui.Button.ClickEvent;
11 | import com.vaadin.ui.Component;
12 | import com.vaadin.ui.VerticalLayout;
13 | import org.vaadin.addon.leaflet.LImageOverlay;
14 | import org.vaadin.addon.leaflet.LTileLayer;
15 | import org.vaadin.addon.leaflet.shared.Bounds;
16 | import org.vaadin.addon.leaflet.shared.Point;
17 |
18 | public class AddOverlayBugTest extends AbstractTest {
19 |
20 | @Override
21 | public String getDescription() {
22 | return "Test Bug with duplicate Layers in overlays";
23 | }
24 |
25 | private LMap lmap;
26 |
27 | @Override
28 | public Component getTestComponent() {
29 |
30 | VerticalLayout lmapContainer = new VerticalLayout();
31 | lmapContainer.setMargin(true);
32 | // create leaflet map
33 | lmap = new LMap();
34 | lmap.setCenter(40.712216, -74.22655);
35 | lmap.setWidth("500px");
36 | lmap.setHeight("400px");
37 |
38 | lmapContainer.addComponent(lmap);
39 |
40 | // base laser 1 & 2 (dummy base layers)
41 | LOpenStreetMapLayer osm1 = new LOpenStreetMapLayer();
42 | osm1.setActive(false);
43 | lmap.addBaseLayer(osm1, "Base Layer 1");
44 | LTileLayer osm2 = new LTileLayer("https://a.tile.thunderforest.com/cycle/{z}/{x}/{y}.png");
45 | osm2.setAttributionString("© OpenStreetMap contributors. Tiles courtesy of Andy Allan");
46 |
47 | osm2.setActive(true);
48 | lmap.addBaseLayer(osm2, "Base Layer 2");
49 |
50 | // BUG: after removing/adding the base layer and also existing wms layers are duplicated
51 | Button wmsLayerRemoveAddButton = new Button("Add");
52 | wmsLayerRemoveAddButton.addClickListener(new Button.ClickListener() {
53 | @Override
54 | public void buttonClick(ClickEvent event) {
55 |
56 | ExternalResource url = new ExternalResource("https://www.lib.utexas.edu/maps/historical/newark_nj_1922.jpg");
57 | LImageOverlay imageOverlay = new LImageOverlay(url, new Bounds(new Point(40.712216, -74.22655), new Point(40.773941, -74.12544)));
58 | imageOverlay.setOpacity(0.5);
59 | imageOverlay.setAttribution("University of Texas");
60 | lmap.addOverlay(imageOverlay, "imagelayer-" + System.currentTimeMillis() );
61 |
62 | // dummy wms layer
63 | LWmsLayer result = new LWmsLayer();
64 | result.setFormat("image/png");
65 | result.setUrl("not/working/url/to/your/geoserver");
66 | result.setLayers("layerselection");
67 |
68 | // add new wms layer
69 | lmap.addOverlay(result, "layer-" + System.currentTimeMillis());
70 | }
71 | });
72 | lmapContainer.addComponent(wmsLayerRemoveAddButton);
73 |
74 | return lmapContainer;
75 | }
76 |
77 | @Override
78 | protected void setup() {
79 | super.setup();
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/src/test/java/org/vaadin/addon/leaflet/demoandtestapp/ComponentsToNewLayerGroupOrdering.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.demoandtestapp;
2 |
3 | import org.vaadin.addon.leaflet.LMap;
4 |
5 | import com.vaadin.ui.Button;
6 | import com.vaadin.ui.Component;
7 | import com.vaadin.ui.VerticalLayout;
8 |
9 | import org.vaadin.addon.leaflet.LCircleMarker;
10 | import org.vaadin.addon.leaflet.LLayerGroup;
11 | import org.vaadin.addonhelpers.AbstractTest;
12 |
13 | public class ComponentsToNewLayerGroupOrdering extends AbstractTest {
14 |
15 | @Override
16 | public String getDescription() {
17 | return "Test layer ordering";
18 | }
19 |
20 | @Override
21 | public Component getTestComponent() {
22 | final MapView view1 = new MapView();
23 | final VerticalLayout layout = new VerticalLayout();
24 | layout.setMargin(true);
25 | Button button1 = new Button("Red");
26 | Button button2 = new Button("Blue");
27 | layout.addComponent(view1);
28 | button1.addClickListener(new Button.ClickListener() {
29 | public void buttonClick(Button.ClickEvent event) {
30 | view1.redUp();
31 | System.out.println("Red Up");
32 | }
33 | });
34 | button2.addClickListener(new Button.ClickListener() {
35 | public void buttonClick(Button.ClickEvent event) {
36 | view1.redDown();
37 | System.out.println("Red Down");
38 |
39 | }
40 | });
41 | layout.addComponent(button1);
42 | layout.addComponent(button2);
43 | layout.addComponent(view1);
44 |
45 | return layout;
46 | }
47 |
48 | public class MapView extends LMap {
49 |
50 | LCircleMarker[] reds = new LCircleMarker[3];
51 | LCircleMarker[] blues = new LCircleMarker[3];
52 |
53 | public MapView() {
54 | setHeight("300px");
55 | setWidth("300px");
56 |
57 | reds[0] = m("red",32.3, 34.8);
58 | reds[1] = m("red",32.2, 34.6);
59 | reds[2] = m("red",32.27, 34.58);
60 |
61 | blues[0] = m("blue",32.34, 34.0);
62 | blues[1] = m("blue",32.25, 34.62);
63 | blues[2] = m("blue",32.29, 34.5);
64 |
65 | redUp();
66 | zoomToContent();
67 | }
68 |
69 | LCircleMarker m(String color, double lat, double lon) {
70 | LCircleMarker marker = new LCircleMarker(lat,lon, 30);
71 | marker.setFillColor(color);
72 | marker.getStyle().setFillOpacity(1.0);
73 | return marker;
74 | }
75 |
76 | public void redUp() {
77 | removeAllComponents();
78 | addComponents(new LLayerGroup(blues),new LLayerGroup(reds));
79 | }
80 |
81 | public void redDown() {
82 | removeAllComponents();
83 | addComponents(new LLayerGroup(reds),new LLayerGroup(blues));
84 | }
85 |
86 | }
87 |
88 | }
89 |
--------------------------------------------------------------------------------
/src/test/java/org/vaadin/addon/leaflet/demoandtestapp/ContextClickOnMap.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.demoandtestapp;
2 |
3 | import com.vaadin.shared.MouseEventDetails;
4 | import org.vaadin.addon.leaflet.LMap;
5 | import org.vaadin.addon.leaflet.shared.Point;
6 |
7 | import com.vaadin.ui.Component;
8 | import com.vaadin.ui.Notification;
9 | import org.vaadin.addon.leaflet.LMarker;
10 | import org.vaadin.addon.leaflet.LOpenStreetMapLayer;
11 | import org.vaadin.addon.leaflet.LPolygon;
12 | import org.vaadin.addon.leaflet.LeafletClickEvent;
13 | import org.vaadin.addon.leaflet.LeafletClickListener;
14 | import org.vaadin.addon.leaflet.LeafletContextMenuEvent;
15 | import org.vaadin.addon.leaflet.LeafletContextMenuListener;
16 | import org.vaadin.addonhelpers.AbstractTest;
17 |
18 | public class ContextClickOnMap extends AbstractTest {
19 |
20 | @Override
21 | public String getDescription() {
22 | return "Testing Context click events";
23 | }
24 |
25 | private LMap leafletMap;
26 |
27 | @Override
28 | public Component getTestComponent() {
29 |
30 | leafletMap = new LMap();
31 | final LOpenStreetMapLayer lOpenStreetMapLayer = new LOpenStreetMapLayer();
32 |
33 | leafletMap.addLayer(lOpenStreetMapLayer);
34 |
35 | leafletMap.setCenter(0, 0);
36 | leafletMap.setZoomLevel(2);
37 |
38 | LPolygon polygon = new LPolygon(new Point(0, 0), new Point(30, 30), new Point(0, 30));
39 |
40 | leafletMap.addLayer(polygon);
41 |
42 | polygon.addContextMenuListener(new LeafletContextMenuListener() {
43 | @Override
44 | public void onContextMenu(LeafletContextMenuEvent event) {
45 |
46 | Notification.show("CxtClick at polygon at " + event.toString());
47 |
48 | }
49 | });
50 |
51 | polygon.addClickListener(new LeafletClickListener() {
52 | @Override
53 | public void onClick(LeafletClickEvent event) {
54 | Notification.show("Std Click at polygon at " + event.toString());
55 | }
56 | });
57 |
58 | // prevent bubbling of events to DOM parents(like the map)
59 | polygon.setBubblingMouseEvents(false);
60 |
61 | leafletMap.addContextMenuListener(new LeafletContextMenuListener() {
62 | @Override
63 | public void onContextMenu(LeafletContextMenuEvent event) {
64 | Point point = event.getPoint();
65 |
66 | LMarker marker = new LMarker(point);
67 | marker.setPopup("Created by ContextClick on lOpenStreetMapLayer");
68 | leafletMap.addComponent(marker);
69 | marker.openPopup();
70 |
71 | }
72 | });
73 |
74 | leafletMap.addClickListener(new LeafletClickListener() {
75 | @Override
76 | public void onClick(LeafletClickEvent event) {
77 | if (event.getMouseEvent().getButton() == MouseEventDetails.MouseButton.LEFT) {
78 | Notification.show("Std Click on map at " + event.toString() + ". Use context click to add marker.");
79 | }
80 | }
81 | });
82 |
83 | return leafletMap;
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/src/test/java/org/vaadin/addon/leaflet/demoandtestapp/ContinuousWorld.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.demoandtestapp;
2 |
3 | import org.vaadin.addon.leaflet.LMap;
4 | import org.vaadin.addon.leaflet.LOpenStreetMapLayer;
5 | import org.vaadin.addon.leaflet.LPolyline;
6 | import org.vaadin.addon.leaflet.shared.Point;
7 |
8 | import com.vaadin.ui.Component;
9 | import org.vaadin.addonhelpers.AbstractTest;
10 |
11 | public class ContinuousWorld extends AbstractTest {
12 |
13 | @Override
14 | public String getDescription() {
15 | return "Test for continuous world and nowrap.";
16 | }
17 |
18 | @Override
19 | public Component getTestComponent() {
20 | LMap leafletMap = new LMap();
21 |
22 | LOpenStreetMapLayer layer = new LOpenStreetMapLayer();
23 | layer.setNoWrap(true); // default false
24 |
25 | leafletMap.addBaseLayer(layer, "OSM");
26 |
27 | leafletMap.setCenter(0, 0);
28 | leafletMap.setZoomLevel(0);
29 |
30 | //Should cross pacific ocean
31 | LPolyline lPolyline = new LPolyline(new Point(0,360),new Point(0,390));
32 |
33 | leafletMap.addComponent(lPolyline);
34 |
35 | return leafletMap;
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/src/test/java/org/vaadin/addon/leaflet/demoandtestapp/ControlTest.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.demoandtestapp;
2 |
3 | import org.vaadin.addon.leaflet.LMap;
4 | import org.vaadin.addon.leaflet.control.LAttribution;
5 | import org.vaadin.addon.leaflet.control.LScale;
6 | import org.vaadin.addon.leaflet.control.LZoom;
7 | import org.vaadin.addon.leaflet.shared.ControlPosition;
8 |
9 | import com.vaadin.ui.Component;
10 | import org.vaadin.addon.leaflet.LOpenStreetMapLayer;
11 | import org.vaadin.addonhelpers.AbstractTest;
12 |
13 | public class ControlTest extends AbstractTest {
14 |
15 | @Override
16 | public String getDescription() {
17 | return "Test controls";
18 | }
19 |
20 | private LMap leafletMap;
21 | private LScale scale = new LScale();
22 |
23 | @Override
24 | public Component getTestComponent() {
25 | leafletMap = new LMap();
26 |
27 | leafletMap.setCenter(60.4525, 22.301);
28 | leafletMap.setZoomLevel(15);
29 |
30 | leafletMap.addBaseLayer(new LOpenStreetMapLayer(), "OSM");
31 | /*
32 | * Using nameless api, doesn't add layers control
33 | */
34 | // leafletMap.addLayer(baselayer);
35 |
36 | /*
37 | * Layers control can also be removed manually
38 | */
39 | // leafletMap.getLayersControl().remove();
40 |
41 | scale.setPosition(ControlPosition.topright);
42 | scale.setImperial(false);
43 | scale.setMetric(true);
44 | leafletMap.addControl(scale);
45 |
46 | /*
47 | * DEFAULT CONTROLS These are on there by default, but can be customized
48 | * and disabled if needed.
49 | */
50 |
51 | LAttribution attribution = new LAttribution();
52 | attribution.setPrefix("Leaflet with Java in JVM");
53 | attribution.setPosition(ControlPosition.bottomleft);
54 | // attribution.setEnabled(false);
55 | leafletMap.addControl(attribution);
56 |
57 | LZoom zoom = new LZoom();
58 | zoom.setPosition(ControlPosition.bottomright);
59 | // zoom.setEnabled(false);
60 | leafletMap.addControl(zoom);
61 |
62 | return leafletMap;
63 | }
64 |
65 | @Override
66 | protected void setup() {
67 | super.setup();
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/src/test/java/org/vaadin/addon/leaflet/demoandtestapp/CustomProjection.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.demoandtestapp;
2 |
3 | import org.vaadin.addon.leaflet.LMap;
4 | import com.vaadin.ui.Component;
5 | import org.vaadin.addon.leaflet.LWmsLayer;
6 | import org.vaadin.addon.leaflet.shared.Crs;
7 | import org.vaadin.addonhelpers.AbstractTest;
8 |
9 | public class CustomProjection extends AbstractTest {
10 |
11 | @Override
12 | public String getDescription() {
13 | return "A test for using custom/explicit projection. Ensure the "
14 | + "WMS layer uses the projection given to map.";
15 | }
16 |
17 | @Override
18 | public Component getTestComponent() {
19 | LMap leafletMap = new LMap();
20 |
21 | LWmsLayer lWmsLayer = new LWmsLayer();
22 | lWmsLayer.setUrl("http://osm.omniscale.net/proxy/service");
23 | lWmsLayer.setLayers("osm");
24 | lWmsLayer.setFormat("image/png");
25 | // Toggle this line to see if WMS layer is requested with differen
26 | // CRS
27 | lWmsLayer.setCrs(Crs.EPSG4326);
28 | leafletMap.addLayer(lWmsLayer);
29 |
30 | leafletMap.setCenter(52.51739, 13.40209);
31 | leafletMap.setZoomLevel(14);
32 | // Toggle this line to see if WMS layer is requested with differen
33 | // CRS
34 | // leafletMap.setCrs(Crs.EPSG4326);
35 |
36 | return leafletMap;
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/src/test/java/org/vaadin/addon/leaflet/demoandtestapp/DragAndDropOnMap.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Vaadin Community.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.vaadin.addon.leaflet.demoandtestapp;
17 |
18 | import com.vaadin.ui.dnd.DropTargetExtension;
19 | import com.vaadin.server.FontAwesome;
20 | import com.vaadin.ui.Button;
21 | import com.vaadin.ui.Component;
22 | import com.vaadin.ui.VerticalLayout;
23 | import com.vaadin.ui.dnd.DragSourceExtension;
24 | import com.vaadin.ui.dnd.event.DropEvent;
25 | import com.vaadin.ui.themes.ValoTheme;
26 | import org.vaadin.addon.leaflet.LMap;
27 | import org.vaadin.addon.leaflet.LMarker;
28 | import org.vaadin.addon.leaflet.LOpenStreetMapLayer;
29 | import org.vaadin.addonhelpers.AbstractTest;
30 | import org.vaadin.addon.leaflet.shared.Point;
31 |
32 | /**
33 | *
34 | * @author mstahv
35 | */
36 | public class DragAndDropOnMap extends AbstractTest {
37 |
38 | @Override
39 | public String getDescription() {
40 | return "Test fractional zoom introduced in 1.0-beta1.";
41 | }
42 |
43 | private LMap leafletMap;
44 |
45 | @Override
46 | public Component getTestComponent() {
47 |
48 | leafletMap = new LMap();
49 | leafletMap.setWidth("300px");
50 | leafletMap.setHeight("300px");
51 | leafletMap.setCenter(0, 0);
52 | leafletMap.setZoomLevel(2.5);
53 | leafletMap.addLayer(new LOpenStreetMapLayer());
54 |
55 | Button button = new Button(FontAwesome.ANCHOR);
56 | button.setStyleName(ValoTheme.BUTTON_BORDERLESS);
57 |
58 | DragSourceExtension dragFrom = new DragSourceExtension(button);
59 | dragFrom.setDragData("foo");
60 |
61 | DropTargetExtension dt = new DropTargetExtension(leafletMap);
62 | dt.addDropListener((DropEvent event) -> {
63 | int relativeX = event.getMouseEventDetails().getRelativeX();
64 | int relativeY = event.getMouseEventDetails().getRelativeY();
65 | leafletMap.translatePixelCoordinates(relativeX, relativeY, (Point p) -> {
66 | final LMarker lMarker = new LMarker(p);
67 | lMarker.setIcon(FontAwesome.ANCHOR);
68 | leafletMap.addLayer(lMarker);
69 | });
70 | Object dragData = event.getDragSourceExtension().get().getDragData();
71 | System.err.println(dragData);
72 | });
73 |
74 | return new VerticalLayout(button, leafletMap);
75 | }
76 | }
--------------------------------------------------------------------------------
/src/test/java/org/vaadin/addon/leaflet/demoandtestapp/FlyToTest.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.demoandtestapp;
2 |
3 | import org.vaadin.addon.leaflet.LMap;
4 | import com.vaadin.ui.Button;
5 | import com.vaadin.ui.Component;
6 | import com.vaadin.ui.VerticalLayout;
7 | import org.vaadin.addon.leaflet.LOpenStreetMapLayer;
8 | import org.vaadin.addon.leaflet.shared.Point;
9 | import org.vaadin.addonhelpers.AbstractTest;
10 |
11 | public class FlyToTest extends AbstractTest {
12 |
13 | @Override
14 | public String getDescription() {
15 | return "Fly to functionality in Leaflet 1.0.";
16 | }
17 |
18 | private LMap leafletMap;
19 |
20 | @Override
21 | public Component getTestComponent() {
22 |
23 | leafletMap = new LMap();
24 | leafletMap.setWidth("600px");
25 | leafletMap.setHeight("300px");
26 | leafletMap.setCenter(0, 0);
27 | leafletMap.setZoomLevel(2);
28 | final LOpenStreetMapLayer osm = new LOpenStreetMapLayer();
29 | leafletMap.addLayer(osm);
30 |
31 | Button flyTo1 = new Button("Fly to Vaadin HQ");
32 | flyTo1.addClickListener(new Button.ClickListener() {
33 |
34 | @Override
35 | public void buttonClick(Button.ClickEvent event) {
36 | leafletMap.flyTo(new Point(60.452236, 22.299839), 14.0);
37 | }
38 | });
39 |
40 | Button flyTo2 = new Button("Fly to Golden Gate");
41 | flyTo2.addClickListener(new Button.ClickListener() {
42 |
43 | @Override
44 | public void buttonClick(Button.ClickEvent event) {
45 | leafletMap.flyTo(new Point(37.816304, -122.478543), 9.0);
46 | }
47 | });
48 |
49 | return new VerticalLayout(leafletMap, flyTo1, flyTo2);
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/test/java/org/vaadin/addon/leaflet/demoandtestapp/FractionalZoom.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.demoandtestapp;
2 |
3 | import com.vaadin.data.HasValue;
4 | import org.vaadin.addon.leaflet.LMap;
5 | import com.vaadin.ui.Component;
6 | import com.vaadin.ui.Notification;
7 | import com.vaadin.ui.Slider;
8 | import com.vaadin.ui.VerticalLayout;
9 | import org.vaadin.addon.leaflet.LOpenStreetMapLayer;
10 | import org.vaadin.addonhelpers.AbstractTest;
11 |
12 | public class FractionalZoom extends AbstractTest {
13 |
14 | @Override
15 | public String getDescription() {
16 | return "Test fractional zoom introduced in 1.0-beta1.";
17 | }
18 |
19 | private LMap leafletMap;
20 |
21 | @Override
22 | public Component getTestComponent() {
23 |
24 | leafletMap = new LMap();
25 | leafletMap.setWidth("300px");
26 | leafletMap.setHeight("300px");
27 | leafletMap.setCenter(0, 0);
28 | leafletMap.setZoomLevel(2.5);
29 | leafletMap.addLayer(new LOpenStreetMapLayer());
30 |
31 | final Slider slider = new Slider("ZoomLevel");
32 | slider.setWidth("200px");
33 | slider.setMin(1);
34 | slider.setMax(16);
35 | slider.setResolution(1);
36 | slider.addValueChangeListener((HasValue.ValueChangeListener) event -> {
37 | leafletMap.setZoomLevel(event.getValue());
38 | Notification.show("Zoom level: " + event.getValue(), Notification.Type.TRAY_NOTIFICATION);
39 | });
40 |
41 | return new VerticalLayout(leafletMap, slider);
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/test/java/org/vaadin/addon/leaflet/demoandtestapp/GeolocationAPIExample.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.demoandtestapp;
2 |
3 | import com.vaadin.annotations.Push;
4 | import com.vaadin.shared.ui.ui.Transport;
5 | import com.vaadin.ui.Button;
6 | import com.vaadin.ui.Component;
7 | import com.vaadin.ui.Label;
8 | import com.vaadin.ui.VerticalLayout;
9 | import org.peimari.gleaflet.client.CircleMarker;
10 | import org.vaadin.addon.leaflet.*;
11 | import org.vaadin.addon.leaflet.shared.Point;
12 | import org.vaadin.addonhelpers.AbstractTest;
13 |
14 | import java.util.Date;
15 |
16 | public class GeolocationAPIExample extends AbstractTest {
17 |
18 | @Override
19 | public String getDescription() {
20 | return "Testing geolocation features.";
21 | }
22 |
23 | private LMap leafletMap;
24 |
25 | @Override
26 | public Component getTestComponent() {
27 | // setPollInterval(1000);
28 |
29 | leafletMap = new LMap();
30 | leafletMap.setWidth("600px");
31 | leafletMap.setHeight("300px");
32 | leafletMap.setCenter(0, 0);
33 | leafletMap.setZoomLevel(2);
34 | final LOpenStreetMapLayer osm = new LOpenStreetMapLayer();
35 | leafletMap.addLayer(osm);
36 |
37 |
38 | final Label pos = new Label();
39 |
40 | final LMarker m = new LMarker();
41 | m.setPopup("That's you");
42 | final LCircleMarker cm = new LCircleMarker();
43 | final LCircle c = new LCircle();
44 |
45 | leafletMap.addLocateListener(new LeafletLocateListener() {
46 | @Override
47 | public void onLocate(LeafletLocateEvent event) {
48 | pos.setValue(new Date().toString() + ": " + event.toString());
49 | if(m.getParent() == null) {
50 | m.setPoint(event.getPoint());
51 | cm.setPoint(event.getPoint());
52 | cm.setColor("red");
53 | cm.setRadius(1);
54 | c.setPoint(event.getPoint());
55 | c.setColor("yellow");
56 | c.setStroke(false);
57 | c.setRadius(event.getAccuracy());
58 | leafletMap.addComponents(m, cm, c);
59 | leafletMap.setLayersToUpdateOnLocate(m, cm, c);
60 | }
61 | }
62 | });
63 |
64 | Button locate = new Button("Locate");
65 | locate.addClickListener(new Button.ClickListener() {
66 |
67 | @Override
68 | public void buttonClick(Button.ClickEvent event) {
69 | leafletMap.locate();
70 | }
71 | });
72 |
73 | Button watch = new Button("Watch location");
74 | watch.addClickListener(new Button.ClickListener() {
75 |
76 | @Override
77 | public void buttonClick(Button.ClickEvent event) {
78 | leafletMap.locate(true, true, true);
79 | }
80 | });
81 |
82 | Button stop = new Button("Stop");
83 | stop.addClickListener(new Button.ClickListener() {
84 |
85 | @Override
86 | public void buttonClick(Button.ClickEvent event) {
87 | leafletMap.stopLocate();
88 | }
89 | });
90 |
91 | return new VerticalLayout(leafletMap, locate, watch, stop, pos);
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/src/test/java/org/vaadin/addon/leaflet/demoandtestapp/ImageLayerOnOSM.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.demoandtestapp;
2 |
3 | import com.vaadin.server.ExternalResource;
4 | import com.vaadin.ui.Notification;
5 | import org.vaadin.addon.leaflet.*;
6 | import org.vaadin.addon.leaflet.shared.Point;
7 |
8 | import com.vaadin.ui.Component;
9 | import org.vaadin.addon.leaflet.shared.Bounds;
10 | import org.vaadin.addonhelpers.AbstractTest;
11 |
12 | public class ImageLayerOnOSM extends AbstractTest {
13 |
14 | @Override
15 | public String getDescription() {
16 | return "Test ImageOverlay on top of OSM.";
17 | }
18 |
19 | private LMap leafletMap = new LMap();
20 |
21 | @Override
22 | public Component getTestComponent() {
23 | leafletMap.addLayer(new LOpenStreetMapLayer());
24 |
25 | // Old map overlayed approximately over OSM map
26 | ExternalResource url = new ExternalResource("https://www.lib.utexas.edu/maps/historical/newark_nj_1922.jpg");
27 | LImageOverlay imageOverlay = new LImageOverlay(url, new Bounds(new Point(40.712216, -74.22655),new Point(40.773941, -74.12544)));
28 | imageOverlay.setOpacity(0.5);
29 | imageOverlay.setInteractive(true); //set true to emit mouse events
30 | imageOverlay.setAttribution("University of Texas");
31 | imageOverlay.addClickListener(new LeafletClickListener() {
32 | @Override
33 | public void onClick(LeafletClickEvent event) {
34 | Notification.show("Image overlay clicked!");
35 | }
36 | });
37 | imageOverlay.addContextMenuListener(new LeafletContextMenuListener() {
38 | @Override
39 | public void onContextMenu(LeafletContextMenuEvent event) {
40 | Notification.show("Image overlay context clicked!");
41 | }
42 | });
43 | imageOverlay.addMouseOverListener(new LeafletMouseOverListener() {
44 | @Override
45 | public void onMouseOver(LeafletMouseOverEvent event) {
46 | Notification.show("Mouse over image overlay!");
47 | }
48 | });
49 | imageOverlay.addMouseOutListener(new LeafletMouseOutListener() {
50 | @Override
51 | public void onMouseOut(LeafletMouseOutEvent event) {
52 | Notification.show("Mouse out of image overlay");
53 | }
54 | });
55 | leafletMap.addLayer(imageOverlay);
56 |
57 | leafletMap.zoomToContent();
58 |
59 | return leafletMap;
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/src/test/java/org/vaadin/addon/leaflet/demoandtestapp/InitialViewPortDetectionWithFixedSize.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.demoandtestapp;
2 |
3 | import com.vaadin.ui.Component;
4 | import com.vaadin.ui.HorizontalLayout;
5 | import com.vaadin.ui.Label;
6 | import com.vaadin.ui.Notification;
7 |
8 | import org.vaadin.addon.leaflet.LMap;
9 | import org.vaadin.addon.leaflet.LOpenStreetMapLayer;
10 | import org.vaadin.addon.leaflet.LeafletMoveEndEvent;
11 | import org.vaadin.addon.leaflet.LeafletMoveEndListener;
12 | import org.vaadin.addonhelpers.AbstractTest;
13 |
14 | @SuppressWarnings("serial")
15 | public class InitialViewPortDetectionWithFixedSize extends AbstractTest {
16 |
17 | private final LMap leafletMap = new LMap();
18 |
19 | private final Label zoomLabel = new Label();
20 |
21 | @Override
22 | public String getDescription() {
23 | return "Test that inial size is reported to server if move end listeners"
24 | + " is set";
25 | }
26 |
27 | @Override
28 | public Component getTestComponent() {
29 | LOpenStreetMapLayer layer = new LOpenStreetMapLayer();
30 | leafletMap.addBaseLayer(layer, "OSM");
31 | leafletMap.setCenter(42.3625, -71.112);
32 | leafletMap.setZoomLevel(15);
33 |
34 | leafletMap.addMoveEndListener(new LeafletMoveEndListener() {
35 | @Override
36 | public void onMoveEnd(LeafletMoveEndEvent event) {
37 | updateZoomLabel();
38 | }
39 | });
40 |
41 | return leafletMap;
42 | }
43 |
44 | @Override
45 | protected void setup() {
46 | super.setup();
47 | HorizontalLayout layout = new HorizontalLayout();
48 | layout.addComponent(zoomLabel);
49 | content.addComponentAsFirst(layout);
50 | updateZoomLabel();
51 | leafletMap.setWidth("300px");
52 | leafletMap.setHeight("300px");
53 | }
54 |
55 | private void updateZoomLabel() {
56 | zoomLabel.setCaption(
57 | "Current zoom: " + leafletMap.getZoomLevel()
58 | + " Viewport: " + leafletMap.getBounds()
59 |
60 |
61 | );
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/src/test/java/org/vaadin/addon/leaflet/demoandtestapp/LayerClickWithCustomCursor.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.demoandtestapp;
2 |
3 | import com.vaadin.server.Page;
4 | import com.vaadin.ui.Component;
5 | import com.vaadin.ui.Notification;
6 | import org.vaadin.addon.leaflet.LCircleMarker;
7 | import org.vaadin.addon.leaflet.LMap;
8 | import org.vaadin.addon.leaflet.LMarker;
9 | import org.vaadin.addon.leaflet.LPolyline;
10 | import org.vaadin.addon.leaflet.LeafletClickEvent;
11 | import org.vaadin.addon.leaflet.LeafletClickListener;
12 | import org.vaadin.addon.leaflet.shared.Point;
13 | import org.vaadin.addonhelpers.AbstractTest;
14 |
15 | public class LayerClickWithCustomCursor extends AbstractTest {
16 |
17 | @Override
18 | public String getDescription() {
19 | return "Example how to use custom cursor directly with CSS.";
20 | }
21 |
22 | private LMap leafletMap;
23 |
24 | @Override
25 | public Component getTestComponent() {
26 |
27 | Page.getCurrent().getStyles().add(".leaflet-grab {cursor: crosshair;}");
28 |
29 | leafletMap = new LMap();
30 | leafletMap.setWidth("300px");
31 | leafletMap.setHeight("300px");
32 | leafletMap.setCenter(0, 0);
33 | leafletMap.setZoomLevel(2);
34 | leafletMap.addClickListener(new LeafletClickListener() {
35 | @Override
36 | public void onClick(LeafletClickEvent event) {
37 | leafletMap.addLayer(new LMarker(event.getPoint()));
38 | }
39 | });
40 |
41 | return leafletMap;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/test/java/org/vaadin/addon/leaflet/demoandtestapp/LayerOrdering.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.demoandtestapp;
2 |
3 | import org.vaadin.addon.leaflet.LMap;
4 | import com.vaadin.ui.Button;
5 | import com.vaadin.ui.Component;
6 | import com.vaadin.ui.HorizontalLayout;
7 | import org.vaadin.addon.leaflet.LCircleMarker;
8 | import org.vaadin.addonhelpers.AbstractTest;
9 |
10 | public class LayerOrdering extends AbstractTest {
11 |
12 | @Override
13 | public String getDescription() {
14 | return "Test layer ordering";
15 | }
16 |
17 | private LMap leafletMap;
18 |
19 | private HorizontalLayout buttons = new HorizontalLayout();
20 |
21 | @Override
22 | public Component getTestComponent() {
23 |
24 | leafletMap = new LMap();
25 | leafletMap.setWidth("300px");
26 | leafletMap.setHeight("300px");
27 | leafletMap.setCenter(0, 0);
28 | leafletMap.setZoomLevel(2);
29 |
30 | leafletMap.addLayer(createMarker("red", -10, -10, 40));
31 | leafletMap.addLayer(createMarker("green",10, -10, 40));
32 | leafletMap.addLayer(createMarker("blue",10, 10, 40));
33 | leafletMap.addLayer(createMarker("cyan",-10, 10, 40));
34 |
35 | return leafletMap;
36 | }
37 |
38 | private LCircleMarker createMarker(String color, int x, int y, int r) {
39 | final LCircleMarker lCircleMarker;
40 | lCircleMarker = new LCircleMarker(x, y, r);
41 | lCircleMarker.setFillOpacity(1.0);
42 | lCircleMarker.setColor(color);
43 | lCircleMarker.setFillColor(color);
44 | buttons.addComponent(new Button(color + " to top", new Button.ClickListener() {
45 |
46 | @Override
47 | public void buttonClick(Button.ClickEvent event) {
48 | lCircleMarker.bringToFront();
49 | }
50 | }));
51 | return lCircleMarker;
52 | }
53 |
54 | @Override
55 | protected void setup() {
56 | super.setup();
57 | content.addComponentAsFirst(buttons);
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/src/test/java/org/vaadin/addon/leaflet/demoandtestapp/MapAntWMTSExample.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.demoandtestapp;
2 |
3 | import org.vaadin.addon.leaflet.LMap;
4 | import com.vaadin.ui.Component;
5 | import org.vaadin.addon.leaflet.LTileLayer;
6 | import org.vaadin.addon.leaflet.shared.Crs;
7 | import org.vaadin.addonhelpers.AbstractTest;
8 |
9 | public class MapAntWMTSExample extends AbstractTest {
10 |
11 | @Override
12 | public String getDescription() {
13 | return "An example fo WMTS layer.";
14 | }
15 |
16 | @Override
17 | public Component getTestComponent() {
18 | LMap leafletMap = new LMap();
19 | leafletMap.setCrs(Crs.EPSG3857);
20 | LTileLayer tileLayer = new LTileLayer("http://wmts.mapant.fi/wmts_EPSG3857.php?z={z}&x={x}&y={y}");
21 | tileLayer.setMaxZoom(19);
22 | tileLayer.setMinZoom(7);
23 | tileLayer.setAttributionString("Laser scanning and topographic data provided by the National Land Survey of Finland under the Creative Commons license.");
24 |
25 | leafletMap.addLayer(tileLayer);
26 |
27 | leafletMap.setCenter(61.0, 26);
28 | leafletMap.setZoomLevel(17);
29 |
30 | return leafletMap;
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/src/test/java/org/vaadin/addon/leaflet/demoandtestapp/MapInGridDetailsRow.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.demoandtestapp;
2 |
3 | import com.vaadin.ui.Component;
4 | import com.vaadin.ui.Grid;
5 | import com.vaadin.ui.VerticalLayout;
6 | import com.vaadin.ui.components.grid.DetailsGenerator;
7 | import com.vaadin.ui.components.grid.ItemClickListener;
8 | import org.vaadin.addon.leaflet.LMap;
9 | import org.vaadin.addon.leaflet.LMarker;
10 | import org.vaadin.addon.leaflet.LTileLayer;
11 | import org.vaadin.addonhelpers.AbstractTest;
12 |
13 | public class MapInGridDetailsRow extends AbstractTest {
14 |
15 | @Override
16 | public String getDescription() {
17 | return "Map should work in Grid details rows.";
18 | }
19 |
20 | @Override
21 | public Component getTestComponent() {
22 | VerticalLayout vl = new VerticalLayout();
23 | vl.setSizeFull();
24 | final Grid grid = new Grid<>();
25 | grid.setSizeFull();
26 |
27 | // Define some columns
28 | grid.addColumn(r -> r).setCaption("Name");
29 | grid.addColumn(r -> "").setCaption("Born");
30 |
31 | // Add some data rows
32 | grid.setItems("Nicolaus Copernicus","Galileo Galilei", "Johannes Kepler");
33 |
34 | grid.setDetailsGenerator((DetailsGenerator) s -> {
35 | final LMap leafletMap = new LMap();
36 | final LTileLayer baselayer = new LTileLayer();
37 | baselayer.setAttributionString("OpenStreetMap");
38 | baselayer.setUrl("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png");
39 | leafletMap.addLayer(baselayer);
40 | leafletMap.setWidth("100%");
41 | leafletMap.setHeight("100px");
42 | leafletMap.setZoomLevel(3);
43 | LMarker leafletMarker = new LMarker(-21.54, 30.76);
44 | leafletMap.addComponent(leafletMarker);
45 | leafletMap.zoomToContent();
46 | return leafletMap;
47 | });
48 |
49 | grid.addItemClickListener((ItemClickListener) event -> grid.setDetailsVisible(event.getItem(), !grid.isDetailsVisible(event.getItem())));
50 | vl.addComponent(grid);
51 |
52 | return vl;
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/src/test/java/org/vaadin/addon/leaflet/demoandtestapp/MapInWindowIssue19.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.demoandtestapp;
2 |
3 | import org.vaadin.addon.leaflet.AbstractLeafletLayer;
4 | import org.vaadin.addon.leaflet.LMap;
5 | import org.vaadin.addon.leaflet.LTileLayer;
6 | import org.vaadin.addon.leaflet.control.LScale;
7 | import org.vaadin.addon.leaflet.control.LZoom;
8 |
9 | import com.vaadin.ui.Button;
10 | import com.vaadin.ui.Button.ClickEvent;
11 | import com.vaadin.ui.Component;
12 | import com.vaadin.ui.Window;
13 | import org.vaadin.addonhelpers.AbstractTest;
14 |
15 | public class MapInWindowIssue19 extends AbstractTest {
16 |
17 | @Override
18 | public String getDescription() {
19 | return "Run this test with ?debug and close subwindow, errors should not be thrown.";
20 | }
21 |
22 | @Override
23 | public Component getTestComponent() {
24 | Button button = new Button("Click Me");
25 | button.addClickListener(new Button.ClickListener() {
26 | public void buttonClick(ClickEvent event) {
27 | Window window = new Window();
28 | LMap map = createMap();
29 | map.setSizeFull();
30 | window.setContent(map);
31 | window.setModal(true);
32 | window.setWidth("90%");
33 | window.setHeight("90%");
34 | addWindow(window);
35 | }
36 | });
37 |
38 | return button;
39 | }
40 |
41 | private LMap createMap() {
42 | final LMap map = new LMap();
43 | map.setCenter(41.920833176630296, 1.853337480434182);
44 | map.setZoomLevel(5);
45 |
46 | map.addControl(new LScale());
47 | map.addControl(new LZoom());
48 |
49 | AbstractLeafletLayer[] layers = new AbstractLeafletLayer[] {
50 | createTileLayer(
51 | "OSM",
52 | "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
53 | "a", "b", "c")
54 | };
55 | addLayers(map, layers);
56 |
57 | return map;
58 | }
59 |
60 | private static void addLayers(LMap map, AbstractLeafletLayer... layers) {
61 | for (int i = 0; i < layers.length; i++) {
62 | if (i == 0) {
63 | layers[i].setActive(true);
64 | } else {
65 | layers[i].setActive(false);
66 | }
67 | map.addBaseLayer(layers[i], layers[i].getCaption());
68 | }
69 | }
70 |
71 | private AbstractLeafletLayer createTileLayer(String name, String url, String... servers) {
72 | return createTileLayer(name, url, false, servers);
73 | }
74 |
75 | private AbstractLeafletLayer createTileLayer(String name, String url, boolean tms,
76 | String... servers) {
77 | LTileLayer layer = new LTileLayer();
78 | layer.setCaption(name);
79 | layer.setUrl(url);
80 | layer.setActive(false);
81 | layer.setTms(tms);
82 | layer.setSubDomains(servers);
83 | return layer;
84 | }
85 |
86 | }
87 |
--------------------------------------------------------------------------------
/src/test/java/org/vaadin/addon/leaflet/demoandtestapp/MapWithCustomOptions.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.demoandtestapp;
2 |
3 | import com.vaadin.ui.Component;
4 | import org.vaadin.addon.leaflet.LMap;
5 | import org.vaadin.addon.leaflet.LOpenStreetMapLayer;
6 | import org.vaadin.addon.leaflet.control.LScale;
7 | import org.vaadin.addonhelpers.AbstractTest;
8 |
9 | public class MapWithCustomOptions extends AbstractTest {
10 |
11 | private LMap leafletMap;
12 |
13 | @Override
14 | public String getDescription() {
15 | return "Map Options Test";
16 | }
17 |
18 | @Override
19 | public Component getTestComponent() {
20 | leafletMap = new LMap();
21 | final LOpenStreetMapLayer lOpenStreetMapLayer = new LOpenStreetMapLayer();
22 | leafletMap.addLayer(lOpenStreetMapLayer);
23 | leafletMap.addControl(new LScale());
24 | leafletMap.setCenter(0, 0);
25 | leafletMap.setZoomLevel(2);
26 |
27 | leafletMap.setZoomSnap(2.0);
28 | leafletMap.setZoomDelta(0.1);
29 |
30 | leafletMap.setCustomInitOption("closePopupOnClick", false);
31 |
32 | leafletMap.setBoxZoomEnabled(false);
33 | leafletMap.setDoubleClickZoomEnabled(false);
34 |
35 | return leafletMap;
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/src/test/java/org/vaadin/addon/leaflet/demoandtestapp/MarkerZIndexOffset.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.demoandtestapp;
2 |
3 | import org.vaadin.addon.leaflet.LMap;
4 | import com.vaadin.ui.Button;
5 | import com.vaadin.ui.Component;
6 | import com.vaadin.ui.VerticalLayout;
7 | import org.vaadin.addon.leaflet.LMarker;
8 | import org.vaadin.addonhelpers.AbstractTest;
9 |
10 | import java.util.concurrent.atomic.AtomicInteger;
11 |
12 | public class MarkerZIndexOffset extends AbstractTest {
13 |
14 | @Override
15 | public String getDescription() {
16 | return "Test removing marker.";
17 | }
18 |
19 | @Override
20 | public Component getTestComponent() {
21 |
22 | LMap leafletMap = new LMap();
23 | leafletMap.setWidth("300px");
24 | leafletMap.setHeight("300px");
25 | leafletMap.setCenter(0, 0);
26 | leafletMap.setZoomLevel(2);
27 |
28 | final AtomicInteger currentBase = new AtomicInteger(1000);
29 |
30 | final LMarker m = new LMarker(5, 5);
31 | m.setId("5 5");
32 | final LMarker m2 = new LMarker(9, 9);
33 | m2.setZIndexOffset(currentBase.get());
34 | m2.setId("9 9");
35 | // m.setZIndexOffset(currentBase.getValue());
36 |
37 | final LMarker m3 = new LMarker(7, 7);
38 |
39 | leafletMap.addComponents(m, m2, m3);
40 |
41 | Button move = new Button("Move top right on top");
42 | move.addClickListener(new Button.ClickListener() {
43 |
44 | @Override
45 | public void buttonClick(Button.ClickEvent event) {
46 | m.setZIndexOffset(currentBase.get());
47 | currentBase.addAndGet(1000);
48 | m2.setZIndexOffset(currentBase.get());
49 | }
50 | });
51 |
52 | Button move2 = new Button("Move low left to top");
53 | move2.addClickListener(new Button.ClickListener() {
54 |
55 | @Override
56 | public void buttonClick(Button.ClickEvent event) {
57 | m2.setZIndexOffset(currentBase.get());
58 | currentBase.addAndGet(1000);
59 | m.setZIndexOffset(currentBase.get());
60 | }
61 | });
62 |
63 | return new VerticalLayout(leafletMap, move, move2);
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/src/test/java/org/vaadin/addon/leaflet/demoandtestapp/MouseListenersTest.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.demoandtestapp;
2 |
3 | import com.vaadin.ui.Component;
4 | import org.vaadin.addon.leaflet.*;
5 | import org.vaadin.addon.leaflet.shared.Point;
6 | import org.vaadin.addonhelpers.AbstractTest;
7 |
8 | public class MouseListenersTest extends AbstractTest {
9 |
10 | @Override
11 | public String getDescription() {
12 | return "Test for mouse{Over|Out} events.
Polygon should be red on hovering.";
13 | }
14 |
15 | @Override
16 | public Component getTestComponent() {
17 | LMap leafletMap = new LMap();
18 |
19 | LOpenStreetMapLayer layer = new LOpenStreetMapLayer();
20 | leafletMap.addBaseLayer(layer, "OSM");
21 | leafletMap.setCenter(0, 0);
22 | leafletMap.setZoomLevel(0);
23 |
24 | final LPolygon lPolygon = new LPolygon(new Point(0, 360), new Point(0, 390), new Point(60, 370));
25 | leafletMap.addComponent(lPolygon);
26 | lPolygon.addMouseOverListener(new LeafletMouseOverListener() {
27 | @Override
28 | public void onMouseOver(LeafletMouseOverEvent event) {
29 | lPolygon.setColor("red");
30 | System.err.println("onMouseOver");
31 | }
32 | });
33 | lPolygon.addMouseOutListener(new LeafletMouseOutListener() {
34 | @Override
35 | public void onMouseOut(LeafletMouseOutEvent event) {
36 | lPolygon.setColor("blue");
37 | System.err.println("onMouseOut");
38 | }
39 | });
40 |
41 | LMarker lMarker = new LMarker(0, 30);
42 | lMarker.addMouseOverListener(new LeafletMouseOverListener() {
43 |
44 | @Override
45 | public void onMouseOver(LeafletMouseOverEvent event) {
46 | System.err.println("marker mouse over");
47 | }
48 | });
49 | lMarker.addMouseOutListener(new LeafletMouseOutListener() {
50 |
51 | @Override
52 | public void onMouseOut(LeafletMouseOutEvent event) {
53 | System.err.println("marker mouse out");
54 | }
55 | });
56 | leafletMap.addLayer(lMarker);
57 |
58 |
59 |
60 | return leafletMap;
61 | }
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/src/test/java/org/vaadin/addon/leaflet/demoandtestapp/PlainImage.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.demoandtestapp;
2 |
3 |
4 |
5 | import com.vaadin.server.ExternalResource;
6 | import org.vaadin.addon.leaflet.LMap;
7 | import org.vaadin.addon.leaflet.shared.Point;
8 |
9 | import com.vaadin.ui.Component;
10 | import org.vaadin.addon.leaflet.LImageOverlay;
11 | import org.vaadin.addon.leaflet.LOpenStreetMapLayer;
12 | import org.vaadin.addon.leaflet.LPolyline;
13 | import org.vaadin.addon.leaflet.shared.Bounds;
14 | import org.vaadin.addon.leaflet.shared.Crs;
15 | import org.vaadin.addonhelpers.AbstractTest;
16 |
17 | public class PlainImage extends AbstractTest {
18 |
19 | @Override
20 | public String getDescription() {
21 | return "Image \"zooming and panning\"";
22 | }
23 |
24 | private LMap leafletMap = new LMap();
25 |
26 | @Override
27 | public Component getTestComponent() {
28 | leafletMap.setCrs(Crs.Simple);
29 |
30 | ExternalResource url = new ExternalResource("https://www.dropbox.com/s/oajfgu8onqxfo0g/photo.jpg?dl=1");
31 |
32 | // The size of this image is 3264 * 2448, scale it here to suite better
33 | // for default zoomlevels
34 | final Bounds bounds = new Bounds(new Point(0, 0), new Point(244.8,326.4));
35 | LImageOverlay imageOverlay = new LImageOverlay(url, bounds);
36 | leafletMap.addLayer(imageOverlay);
37 |
38 | // You can fit it directly or to another extend like here, you could also
39 | // use multiple images on the background
40 | leafletMap.setMaxBounds(new Bounds(new Point(0, 0), new Point(300,500)));
41 |
42 | // draw line from corner to corner
43 | leafletMap.addLayer(new LPolyline(new Point(0, 0), new Point(244.8,326.4)));
44 |
45 | leafletMap.setMaxZoom(5);
46 |
47 | return leafletMap;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/test/java/org/vaadin/addon/leaflet/demoandtestapp/PolygonWithHolesTest.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.demoandtestapp;
2 |
3 | import com.vaadin.ui.Component;
4 | import org.locationtech.jts.geom.Geometry;
5 | import org.locationtech.jts.geom.Polygon;
6 | import org.locationtech.jts.io.ParseException;
7 | import org.locationtech.jts.io.WKTReader;
8 | import org.vaadin.addon.leaflet.LFeatureGroup;
9 | import org.vaadin.addon.leaflet.LMap;
10 | import org.vaadin.addon.leaflet.LPolygon;
11 | import org.vaadin.addon.leaflet.LeafletLayer;
12 | import org.vaadin.addon.leaflet.shared.Point;
13 | import org.vaadin.addon.leaflet.util.JTSUtil;
14 | import org.vaadin.addonhelpers.AbstractTest;
15 |
16 | import java.util.Collection;
17 |
18 | public class PolygonWithHolesTest extends AbstractTest {
19 |
20 | @Override
21 | public String getDescription() {
22 | return "A test for the JTS api";
23 | }
24 |
25 | private LMap leafletMap;
26 | private LFeatureGroup lfg;
27 |
28 | private WKTReader wkt = new WKTReader();
29 |
30 | private Geometry readWKT(String wktString) {
31 | try {
32 | return wkt.read(wktString);
33 | } catch (ParseException e) {
34 | e.printStackTrace();
35 | }
36 | return null;
37 | }
38 |
39 | private Polygon getPolygon() {
40 | return (Polygon) readWKT("POLYGON ((35 10, 45 45, 15 40, 10 20, 35 10)," +
41 | "(20 30, 35 35, 30 20, 20 30))");
42 | }
43 |
44 | public Component getTestComponent() {
45 | leafletMap = new LMap();
46 |
47 | lfg = new LFeatureGroup(); // Not creating a name -> not added to the
48 | // overlay controller
49 |
50 |
51 | LPolygon polygon = new LPolygon();
52 | polygon.setPoints(new Point[]{new Point(0,0),new Point(30,30),new Point(30,0)});
53 | polygon.setHoles(new Point[]{new Point(20, 20), new Point(25, 25), new Point(25, 20)});
54 | // non complete hole
55 | polygon.setHoles(new Point[]{new Point(5, 10), new Point(15, 15), new Point(15, 10)});
56 | polygon.setColor("green");
57 | lfg.addComponent(polygon);
58 | Polygon poly = getPolygon();
59 | Collection lPoly = JTSUtil.toLayers(poly);
60 | lfg.addComponent(lPoly);
61 |
62 | leafletMap.setZoomLevel(5);
63 |
64 | leafletMap.addComponent(lfg);
65 |
66 | leafletMap.zoomToContent();
67 |
68 | return leafletMap;
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/src/test/java/org/vaadin/addon/leaflet/demoandtestapp/ReadOnlyTest.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.demoandtestapp;
2 |
3 | import org.vaadin.addon.leaflet.LMap;
4 | import org.vaadin.addon.leaflet.LOpenStreetMapLayer;
5 | import org.vaadin.addon.leaflet.control.LZoom;
6 | import org.vaadin.addonhelpers.AbstractTest;
7 |
8 | import com.vaadin.ui.Button;
9 | import com.vaadin.ui.Component;
10 | import com.vaadin.ui.HorizontalLayout;
11 | import com.vaadin.ui.Notification;
12 | import com.vaadin.ui.VerticalLayout;
13 | import com.vaadin.ui.Notification.Type;
14 | import com.vaadin.ui.Button.ClickEvent;
15 |
16 | @SuppressWarnings("serial")
17 | public class ReadOnlyTest extends AbstractTest {
18 |
19 | @Override
20 | public String getDescription() {
21 | return "A visual test for the readOnly feature.";
22 | }
23 |
24 | private LMap leafletMap;
25 |
26 | @Override
27 | public Component getTestComponent() {
28 | leafletMap = new LMap();
29 | leafletMap.setCenter(60.4525, 22.301);
30 | leafletMap.setZoomLevel(10);
31 | LOpenStreetMapLayer layer = new LOpenStreetMapLayer();
32 | leafletMap.addBaseLayer(layer, "OSM");
33 | leafletMap.addControl(new LZoom());
34 | leafletMap.setReadOnly(true);
35 |
36 | Button getStates = new Button("getStates", new Button.ClickListener() {
37 | @Override
38 | public void buttonClick(ClickEvent event) {
39 | StringBuilder sb = new StringBuilder("\nisDraggingEnabled() = ").append(leafletMap.isDraggingEnabled())
40 | .append("\nisBooxZoomEnabled() = ").append(leafletMap.isBoxZoomEnabled());
41 | Notification.show("States", sb.toString(), Type.HUMANIZED_MESSAGE);
42 | }
43 | });
44 | Button toggleReadOnly = new Button("toggle readonly", new Button.ClickListener() {
45 | @Override
46 | public void buttonClick(ClickEvent event) {
47 | leafletMap.setReadOnly(!leafletMap.isReadOnly());
48 | }
49 | });
50 | VerticalLayout verticalLayout = new VerticalLayout(leafletMap, new HorizontalLayout(getStates, toggleReadOnly));
51 | verticalLayout.setSizeFull();
52 | verticalLayout.setExpandRatio(leafletMap, 1);
53 | return verticalLayout;
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/test/java/org/vaadin/addon/leaflet/demoandtestapp/RemoveMarker.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.demoandtestapp;
2 |
3 | import org.vaadin.addon.leaflet.LMap;
4 | import com.vaadin.ui.Button;
5 | import com.vaadin.ui.Component;
6 | import com.vaadin.ui.VerticalLayout;
7 | import org.vaadin.addon.leaflet.LMarker;
8 | import org.vaadin.addonhelpers.AbstractTest;
9 |
10 | public class RemoveMarker extends AbstractTest {
11 |
12 | @Override
13 | public String getDescription() {
14 | return "Test removing marker.";
15 | }
16 |
17 | private LMap leafletMap;
18 |
19 | @Override
20 | public Component getTestComponent() {
21 |
22 | leafletMap = new LMap();
23 | leafletMap.setWidth("300px");
24 | leafletMap.setHeight("300px");
25 | leafletMap.setCenter(0, 0);
26 | leafletMap.setZoomLevel(2);
27 |
28 | final LMarker m = new LMarker(5, 5);
29 |
30 | leafletMap.addComponent(m);
31 |
32 | Button remove = new Button("Remove marker");
33 | remove.addClickListener(new Button.ClickListener() {
34 |
35 | @Override
36 | public void buttonClick(Button.ClickEvent event) {
37 | leafletMap.removeComponent(m);
38 | event.getButton().setEnabled(false);
39 | }
40 | });
41 |
42 | return new VerticalLayout(leafletMap, remove);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/test/java/org/vaadin/addon/leaflet/demoandtestapp/RemovePopup.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.demoandtestapp;
2 |
3 | import org.vaadin.addon.leaflet.LMap;
4 | import com.vaadin.ui.Button;
5 | import com.vaadin.ui.Component;
6 | import com.vaadin.ui.VerticalLayout;
7 | import org.vaadin.addon.leaflet.LPopup;
8 | import org.vaadin.addonhelpers.AbstractTest;
9 |
10 | public class RemovePopup extends AbstractTest {
11 |
12 | @Override
13 | public String getDescription() {
14 | return "Test removing popup.";
15 | }
16 |
17 | private LMap leafletMap;
18 |
19 | @Override
20 | public Component getTestComponent() {
21 |
22 | leafletMap = new LMap();
23 | leafletMap.setWidth("300px");
24 | leafletMap.setHeight("300px");
25 | leafletMap.setCenter(0, 0);
26 | leafletMap.setZoomLevel(2);
27 |
28 | final LPopup popup = new LPopup(5.0, 5.0);
29 | popup.setContent("Hello!");
30 | leafletMap.addComponent(popup);
31 |
32 | Button remove = new Button("Remove popup");
33 | remove.addClickListener(new Button.ClickListener() {
34 |
35 | @Override
36 | public void buttonClick(Button.ClickEvent event) {
37 | leafletMap.removeComponent(popup);
38 | event.getButton().setEnabled(false);
39 | }
40 | });
41 |
42 | return new VerticalLayout(leafletMap, remove);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/test/java/org/vaadin/addon/leaflet/demoandtestapp/RestritedExtent.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.demoandtestapp;
2 |
3 | import com.vaadin.ui.Button;
4 | import com.vaadin.ui.Component;
5 | import com.vaadin.ui.VerticalLayout;
6 | import org.vaadin.addon.leaflet.LMap;
7 | import org.vaadin.addon.leaflet.LPolyline;
8 | import org.vaadin.addon.leaflet.shared.Bounds;
9 | import org.vaadin.addon.leaflet.shared.Point;
10 | import org.vaadin.addonhelpers.AbstractTest;
11 |
12 | public class RestritedExtent extends AbstractTest {
13 |
14 | @Override
15 | public String getDescription() {
16 | return "A test for using custom/explicit projection. Ensure the "
17 | + "WMS layer uses the projection given to map.";
18 | }
19 |
20 | @Override
21 | public Component getTestComponent() {
22 | final LMap leafletMap = new LMap();
23 | leafletMap.setHeight("300px");
24 | leafletMap.setWidth("300px");
25 | leafletMap.setZoomLevel(15);
26 |
27 | // leafletMap.addBaseLayer(new LOpenStreetMapLayer(), "OSM");
28 |
29 | Point p = new Point(60, 22);
30 | Point p2 = new Point(61, 23);
31 | final Bounds b = new Bounds(p, p2);
32 | leafletMap.setMaxBounds(b);
33 | leafletMap.zoomToExtent(b);
34 |
35 | leafletMap.addComponent(new LPolyline(p, p2));
36 |
37 | Button button = new Button("Move restricted extent (aka max bounds)");
38 | button.addClickListener(new Button.ClickListener() {
39 |
40 | @Override
41 | public void buttonClick(Button.ClickEvent event) {
42 |
43 | b.setNorthEastLat(b.getNorthEastLat() + 0.5);
44 | b.setNorthEastLon(b.getNorthEastLon() + 0.5);
45 | b.setSouthWestLat(b.getSouthWestLat() + 0.5);
46 | b.setSouthWestLon(b.getSouthWestLon() + 0.5);
47 | leafletMap.setMaxBounds(b);
48 |
49 | leafletMap.addComponent(new LPolyline(new Point(b.getSouthWestLat(), b.getSouthWestLon()), new Point(b.getNorthEastLat(), b.getNorthEastLon())));
50 |
51 | leafletMap.zoomToExtent(b);
52 | }
53 | });
54 | return new VerticalLayout(leafletMap, button);
55 | }
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/src/test/java/org/vaadin/addon/leaflet/demoandtestapp/SimpleMarkerTest.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.demoandtestapp;
2 |
3 | import com.vaadin.server.ExternalResource;
4 | import com.vaadin.ui.Button;
5 | import com.vaadin.ui.Button.ClickListener;
6 | import org.vaadin.addon.leaflet.LMap;
7 | import org.vaadin.addon.leaflet.LMarker;
8 | import org.vaadin.addon.leaflet.LTileLayer;
9 |
10 | import com.vaadin.ui.Component;
11 | import com.vaadin.ui.Notification;
12 | import org.vaadin.addon.leaflet.LeafletClickEvent;
13 | import org.vaadin.addon.leaflet.LeafletClickListener;
14 | import org.vaadin.addon.leaflet.shared.Point;
15 | import org.vaadin.addonhelpers.AbstractTest;
16 |
17 | public class SimpleMarkerTest extends AbstractTest {
18 | private LMarker lMarker;
19 |
20 | @Override
21 | public String getDescription() {
22 | return "Add marker test case";
23 | }
24 |
25 | private LMap leafletMap;
26 |
27 | @Override
28 | public Component getTestComponent() {
29 |
30 |
31 | leafletMap = new LMap();
32 |
33 | LTileLayer pk = new LTileLayer();
34 | pk.setUrl("http://{s}.kartat.kapsi.fi/peruskartta/{z}/{x}/{y}.png");
35 | pk.setAttributionString("Maanmittauslaitos, hosted by kartat.kapsi.fi");
36 | pk.setMaxZoom(18);
37 | pk.setSubDomains("tile2");
38 | pk.setDetectRetina(true);
39 | leafletMap.addBaseLayer(pk, "Peruskartta");
40 |
41 | leafletMap.setCenter(60.4525, 22.301);
42 | leafletMap.setZoomLevel(15);
43 | lMarker = new LMarker(60.4525, 22.301);
44 | lMarker.addStyleName("specialstyle");
45 | lMarker.setIcon(new ExternalResource("http://leafletjs.com/examples/custom-icons/leaf-red.png"));
46 | lMarker.setIconAnchor(new Point(22, 94));
47 | lMarker.setPopup("Popupstring");
48 | leafletMap.addComponent(lMarker);
49 | lMarker.openPopup();
50 |
51 | LMarker another = new LMarker(60.4525, 22.303);
52 | another.addClickListener(new LeafletClickListener() {
53 |
54 | @Override
55 | public void onClick(LeafletClickEvent event) {
56 | Notification.show("Another marker was clicke.");
57 | }
58 | });
59 | leafletMap.addComponent(another);
60 |
61 | return leafletMap;
62 |
63 | }
64 |
65 | @Override
66 | protected void setup() {
67 | super.setup();
68 | content.addComponentAsFirst(new Button("Open popup", new ClickListener(){
69 |
70 | @Override
71 | public void buttonClick(Button.ClickEvent event) {
72 | lMarker.setPopup("dadaa");
73 | lMarker.openPopup();
74 | }
75 | }));
76 |
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/src/test/java/org/vaadin/addon/leaflet/demoandtestapp/SizeChangeInWindow.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.demoandtestapp;
2 |
3 | import java.util.Random;
4 |
5 | import org.vaadin.addon.leaflet.LMap;
6 |
7 | import com.vaadin.ui.Component;
8 | import com.vaadin.ui.Label;
9 | import com.vaadin.ui.Window;
10 | import org.vaadin.addon.leaflet.LOpenStreetMapLayer;
11 | import org.vaadin.addonhelpers.AbstractTest;
12 |
13 | public class SizeChangeInWindow extends AbstractTest {
14 |
15 | @Override
16 | public String getDescription() {
17 | return "Window resize should notify leaflet about size change.";
18 | }
19 |
20 | @Override
21 | public Component getTestComponent() {
22 |
23 | final LMap map = new LMap();
24 | map.setCenter( 50.06465, 19.94498 );
25 |
26 | map.addBaseLayer(new LOpenStreetMapLayer(), "OpenStreetMap");
27 |
28 | map.setSizeFull();
29 |
30 |
31 | Window window = new Window("Map window");
32 | window.setContent(map);
33 | window.setWidth("300px");
34 | window.setHeight("300px");
35 | getUI().addWindow(window);
36 |
37 |
38 | return new Label("Use the window...");
39 | }
40 |
41 | Random r = new Random(1);
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/src/test/java/org/vaadin/addon/leaflet/demoandtestapp/SplitpanelIssue170.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.demoandtestapp;
2 |
3 | import org.vaadin.addon.leaflet.LMap;
4 | import com.vaadin.ui.Component;
5 | import com.vaadin.ui.HorizontalSplitPanel;
6 | import com.vaadin.ui.Label;
7 | import org.vaadin.addon.leaflet.LTileLayer;
8 | import org.vaadin.addon.leaflet.shared.Bounds;
9 | import org.vaadin.addonhelpers.AbstractTest;
10 |
11 | public class SplitpanelIssue170 extends AbstractTest {
12 |
13 | @Override
14 | public String getDescription() {
15 | return "Leaflet map in SplitPanel";
16 | }
17 |
18 | @Override
19 | public Component getTestComponent() {
20 |
21 | LMap leafletMap = new LMap();
22 | leafletMap.setSizeFull();
23 | Bounds bounds = new Bounds();
24 | bounds.setSouthWestLon(15.3308);
25 | bounds.setSouthWestLat(41.1427);
26 | bounds.setNorthEastLat(39.8847);
27 | bounds.setNorthEastLon(16.887);
28 |
29 | leafletMap.zoomToExtent(bounds);
30 |
31 | leafletMap.addLayer(new LTileLayer("http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"));
32 | HorizontalSplitPanel sp = new HorizontalSplitPanel();
33 | sp.setSizeFull();
34 | sp.setFirstComponent(leafletMap);
35 | sp.setSecondComponent(new Label("My Label"));
36 |
37 | return sp;
38 |
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/test/java/org/vaadin/addon/leaflet/demoandtestapp/TextOnMap.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.demoandtestapp;
2 |
3 | import org.vaadin.addon.leaflet.LMap;
4 | import org.vaadin.addon.leaflet.shared.Point;
5 |
6 | import com.vaadin.ui.Component;
7 | import org.vaadin.addon.leaflet.LMarker;
8 | import org.vaadin.addon.leaflet.LOpenStreetMapLayer;
9 | import org.vaadin.addonhelpers.AbstractTest;
10 |
11 | public class TextOnMap extends AbstractTest {
12 |
13 | @Override
14 | public String getDescription() {
15 | return "Draw some text to the center of the world.";
16 | }
17 |
18 | private LMap leafletMap;
19 |
20 | @Override
21 | public Component getTestComponent() {
22 |
23 | leafletMap = new LMap();
24 |
25 | leafletMap.addLayer(new LOpenStreetMapLayer());
26 |
27 | leafletMap.setCenter(0, 0);
28 | leafletMap.setZoomLevel(2);
29 |
30 | LMarker m = new LMarker(0,0);
31 | m.setStyleName("mycustomclassname"); // <- this becomes's to div icon's class names
32 | m.setDivIcon("Hello world!");
33 | // define the size for the html box
34 | m.setIconSize(new Point(80,20));
35 | leafletMap.addLayer(m);
36 |
37 |
38 | return leafletMap;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/test/java/org/vaadin/addon/leaflet/demoandtestapp/TooltipTest.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.demoandtestapp;
2 |
3 | import com.vaadin.annotations.StyleSheet;
4 | import com.vaadin.ui.Component;
5 | import org.vaadin.addon.leaflet.*;
6 | import org.vaadin.addon.leaflet.shared.Point;
7 | import org.vaadin.addon.leaflet.shared.TooltipState;
8 | import org.vaadin.addonhelpers.AbstractTest;
9 |
10 | @StyleSheet({"testStyles.css"})
11 | public class TooltipTest extends AbstractTest {
12 |
13 | @Override
14 | public String getDescription() {
15 | return "Tooltip test case";
16 | }
17 |
18 | private LMap leafletMap;
19 |
20 | @Override
21 | public Component getTestComponent() {
22 |
23 | leafletMap = new LMap();
24 |
25 | leafletMap.addLayer(new LOpenStreetMapLayer());
26 |
27 | leafletMap.setCenter(60.4525, 22.301);
28 | leafletMap.setZoomLevel(15);
29 |
30 | LTooltip tooltip1 = new LTooltip(60.4540, 22.275).setContent("Hi, I'm a standalone tooltip in magenta!");
31 | tooltip1.setPrimaryStyleName("tooltip-custom-style-test");
32 | leafletMap.addComponent(tooltip1);
33 |
34 | LMarker marker1 = new LMarker(60.4720, 22.271);
35 | marker1.setTooltip("Permanent tooltip bound to marker");
36 | TooltipState marker1TooltipState = new TooltipState();
37 | marker1TooltipState.permanent = true;
38 | marker1.setTooltipState(marker1TooltipState);
39 | leafletMap.addComponent(marker1);
40 |
41 | LMarker marker2 = new LMarker(60.4620, 22.281);
42 | marker2.setTooltip("Auto direction tooltip bound to marker with transparency");
43 | TooltipState marker2TooltipState = new TooltipState();
44 | marker2TooltipState.opacity = 0.5;
45 | marker2.setTooltipState(marker2TooltipState);
46 | leafletMap.addComponent(marker2);
47 |
48 | LMarker marker3 = new LMarker(60.4620, 22.276);
49 | marker3.setTooltip("Top direction tooltip bound to marker");
50 | TooltipState marker3TooltipState = new TooltipState();
51 | marker3TooltipState.direction = "top";
52 | marker3.setTooltipState(marker3TooltipState);
53 | leafletMap.addComponent(marker3);
54 |
55 | LPolyline polyline1 = new LPolyline(new Point(60.4527, 22.291), new Point(60.4549, 22.309));
56 | polyline1.setTooltip("Tooltip bound to polyline");
57 | leafletMap.addComponent(polyline1);
58 |
59 | LPolygon polygon1 = new LPolygon(new Point(60.4525, 22.301), new Point(60.4539, 22.309),
60 | new Point(60.4535, 22.321), new Point(60.4525, 22.301));
61 | polygon1.setTooltip("Sticky tooltip bound to polygon");
62 | TooltipState polygon1TooltipState = new TooltipState();
63 | polygon1TooltipState.sticky = true;
64 | polygon1.setTooltipState(polygon1TooltipState);
65 | leafletMap.addComponent(polygon1);
66 |
67 | leafletMap.zoomToContent();
68 |
69 | return leafletMap;
70 |
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/src/test/java/org/vaadin/addon/leaflet/demoandtestapp/TransparentMap.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.demoandtestapp;
2 |
3 | import org.vaadin.addon.leaflet.LMap;
4 | import org.vaadin.addon.leaflet.LPolyline;
5 | import org.vaadin.addon.leaflet.shared.Point;
6 |
7 | import com.vaadin.server.Page;
8 | import com.vaadin.ui.Component;
9 | import org.vaadin.addon.leaflet.LCircleMarker;
10 | import org.vaadin.addonhelpers.AbstractTest;
11 |
12 | public class TransparentMap extends AbstractTest {
13 |
14 | @Override
15 | public String getDescription() {
16 | return "Test custom map background color.";
17 | }
18 |
19 | private LMap leafletMap;
20 |
21 | @Override
22 | public Component getTestComponent() {
23 |
24 | Page.getCurrent().getStyles().add(".v-leaflet .leaflet-container {background: yellow;}");
25 | leafletMap = new LMap();
26 | leafletMap.setWidth("300px");
27 | leafletMap.setHeight("300px");
28 | leafletMap.setCenter(0, 0);
29 | leafletMap.setZoomLevel(2);
30 |
31 | LPolyline lPolyline = new LPolyline(new Point(-30, -30), new Point(0, 30), new Point(30, 0));
32 | lPolyline.setColor("red");
33 | lPolyline.setFill(true);
34 | lPolyline.getStyle().setFillOpacity(1.0);
35 |
36 | leafletMap.addLayer(lPolyline);
37 |
38 | LCircleMarker lCircleMarker = new LCircleMarker(30, 30, 40);
39 | lCircleMarker.getStyle().setFillOpacity(0.05);
40 | leafletMap.addLayer(lCircleMarker);
41 |
42 | return leafletMap;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/test/java/org/vaadin/addon/leaflet/demoandtestapp/VectorPerfotest.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.demoandtestapp;
2 |
3 | import com.vaadin.ui.Button;
4 | import com.vaadin.ui.Component;
5 | import com.vaadin.ui.VerticalLayout;
6 | import java.util.ArrayList;
7 | import java.util.Collections;
8 | import java.util.List;
9 | import java.util.Random;
10 | import org.vaadin.addon.leaflet.LMap;
11 | import org.vaadin.addon.leaflet.LPolyline;
12 | import org.vaadin.addon.leaflet.shared.Point;
13 | import org.vaadin.addonhelpers.AbstractTest;
14 |
15 | public class VectorPerfotest extends AbstractTest {
16 |
17 | @Override
18 | public String getDescription() {
19 | return "Test to render largish set of vectors.";
20 | }
21 |
22 | @Override
23 | public Component getTestComponent() {
24 | final LMap leafletMap = new LMap();
25 | leafletMap.setHeight("300px");
26 | leafletMap.setWidth("300px");
27 | leafletMap.setZoomLevel(15);
28 |
29 | // leafletMap.addBaseLayer(new LOpenStreetMapLayer(), "OSM");
30 | final Random r = new Random();
31 | List pa = new ArrayList();
32 | for (int i = 0; i < 10; i++) {
33 | pa.add(new Point(60 + r.nextDouble() * 10, 20 + r.nextDouble() * 10));
34 | }
35 |
36 | for (int i = 0; i < 1000; i++) {
37 | Collections.shuffle(pa);
38 | LPolyline pl = new LPolyline(pa.toArray(new Point[pa.size()]));
39 | leafletMap.addComponent(pl);
40 | }
41 |
42 | Button button = new Button("Move restricted extent (aka max bounds)");
43 | button.addClickListener(new Button.ClickListener() {
44 |
45 | @Override
46 | public void buttonClick(Button.ClickEvent event) {
47 | }
48 | });
49 |
50 | leafletMap.zoomToContent();
51 | return new VerticalLayout(leafletMap, button);
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/src/test/java/org/vaadin/addon/leaflet/demoandtestapp/VectorsWithNullPoints.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.demoandtestapp;
2 |
3 | import com.vaadin.ui.Component;
4 | import org.vaadin.addon.leaflet.LMap;
5 | import org.vaadin.addon.leaflet.LMarker;
6 | import org.vaadin.addon.leaflet.LPolygon;
7 | import org.vaadin.addonhelpers.AbstractTest;
8 |
9 | import org.vaadin.addon.leaflet.LPolyline;
10 | import org.vaadin.addon.leaflet.shared.Point;
11 |
12 | public class VectorsWithNullPoints extends AbstractTest {
13 |
14 | @Override
15 | public String getDescription() {
16 | return "A test to helper method to sanitize geometries (removing null points)";
17 | }
18 |
19 | private LMap leafletMap;
20 |
21 |
22 | public Component getTestComponent() {
23 | leafletMap = new LMap();
24 |
25 | LPolygon polygon = new LPolygon(new Point(0,0), null,new Point(1,1),new Point(2,3),new Point(0, 0));
26 | polygon.sanitizeGeometry();
27 | LPolyline polyline = new LPolyline();
28 | LPolyline polylineWithNullPoint = new LPolyline(new Point(0,0), null,new Point(1,1),new Point(2,3));
29 | polylineWithNullPoint.sanitizeGeometry();
30 |
31 | LMarker m = new LMarker(0,0);
32 |
33 | leafletMap.setZoomLevel(0);
34 |
35 | leafletMap.addComponents(polygon, polyline,polylineWithNullPoint, m);
36 |
37 | leafletMap.zoomToContent();
38 |
39 | return leafletMap;
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/test/java/org/vaadin/addon/leaflet/demoandtestapp/ViewChangeTest.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.demoandtestapp;
2 |
3 | import org.vaadin.addon.leaflet.LMap;
4 | import org.vaadin.addon.leaflet.LMarker;
5 | import org.vaadin.addon.leaflet.LTileLayer;
6 |
7 | import com.vaadin.navigator.Navigator;
8 | import com.vaadin.navigator.View;
9 | import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
10 | import com.vaadin.navigator.ViewProvider;
11 | import com.vaadin.ui.Component;
12 | import com.vaadin.ui.Label;
13 | import com.vaadin.ui.VerticalLayout;
14 | import org.vaadin.addonhelpers.AbstractTest;
15 |
16 | public class ViewChangeTest extends AbstractTest {
17 |
18 | @Override
19 | public String getDescription() {
20 | return "View change test case";
21 | }
22 |
23 | private Navigator nav;
24 |
25 | private class MapView extends VerticalLayout implements View {
26 |
27 | private LMap lMap;
28 |
29 | public MapView() {
30 | this.setSizeFull();
31 | this.lMap = new LMap();
32 |
33 | this.addComponent(lMap);
34 | lMap.setSizeFull();
35 |
36 | LTileLayer pk = new LTileLayer();
37 | pk.setUrl("https://{s}.kartat.kapsi.fi/peruskartta/{z}/{x}/{y}.png");
38 | pk.setAttributionString("Maanmittauslaitos, hosted by kartat.kapsi.fi");
39 | pk.setMaxZoom(18);
40 | pk.setSubDomains("tile2");
41 | pk.setDetectRetina(true);
42 | lMap.addBaseLayer(pk, "Peruskartta");
43 |
44 | lMap.setCenter(60.4525, 22.301);
45 | lMap.setZoomLevel(15);
46 | lMap.addComponent(new LMarker(60.4525, 22.301));
47 | }
48 |
49 | @Override
50 | public void enter(ViewChangeEvent event) {
51 |
52 | }
53 | }
54 |
55 | private class OtherView extends VerticalLayout implements View {
56 |
57 | public OtherView() {
58 | addComponent(new Label("Otherview"));
59 | }
60 |
61 | @Override
62 | public void enter(ViewChangeEvent event) {
63 |
64 | }
65 |
66 | }
67 |
68 | private class TestViewProvider implements ViewProvider {
69 |
70 | @Override
71 | public String getViewName(String viewAndParameters) {
72 | return viewAndParameters;
73 | }
74 |
75 | @Override
76 | public View getView(String viewName) {
77 |
78 | if (viewName.equals("A")) {
79 | return new MapView();
80 | } else if (viewName.equals("B")) {
81 | return new MapView();
82 | }
83 | return new OtherView();
84 |
85 | }
86 |
87 | }
88 |
89 | @Override
90 | public Component getTestComponent() {
91 | return null;
92 | }
93 |
94 | @Override
95 | protected void setup() {
96 | content.setSizeFull();
97 |
98 | nav = new Navigator(this, content);
99 | nav.addProvider(new TestViewProvider());
100 | nav.navigateTo("A");
101 | nav.navigateTo("B");
102 |
103 |
104 | }
105 | }
106 |
--------------------------------------------------------------------------------
/src/test/java/org/vaadin/addon/leaflet/demoandtestapp/WithoutBeanBindingTest.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.demoandtestapp;
2 |
3 | import org.locationtech.jts.geom.Geometry;
4 | import org.locationtech.jts.geom.Point;
5 | import org.locationtech.jts.io.ParseException;
6 | import org.locationtech.jts.io.WKTReader;
7 | import org.vaadin.addon.leaflet.util.PointField;
8 | import org.vaadin.addonhelpers.AbstractTest;
9 |
10 | import com.vaadin.ui.Button;
11 | import com.vaadin.ui.Button.ClickEvent;
12 | import com.vaadin.ui.Component;
13 | import com.vaadin.ui.HorizontalLayout;
14 | import com.vaadin.ui.Notification;
15 | import com.vaadin.ui.VerticalLayout;
16 |
17 | public class WithoutBeanBindingTest extends AbstractTest {
18 | private WKTReader wkt = new WKTReader();
19 |
20 | @Override
21 | public String getDescription() {
22 | return "A simple test for JTSFields without bean binding";
23 | }
24 |
25 | @Override
26 | public Component getTestComponent() {
27 | final PointField pointFieldEmpty = new PointField("empty PointField");
28 | pointFieldEmpty.setSizeFull();
29 |
30 | final PointField pointFieldInitialized = new PointField("PointField with value");
31 | pointFieldInitialized.setSizeFull();
32 | pointFieldInitialized.getMap().setZoomLevel(8);
33 | pointFieldInitialized.setValue(getPoint());
34 |
35 | Button getValueButton = new Button("Get values");
36 | getValueButton.addClickListener(new Button.ClickListener() {
37 | @Override
38 | public void buttonClick(ClickEvent event) {
39 | Point value1 = pointFieldEmpty.getValue();
40 | Point value2 = pointFieldInitialized.getValue();
41 | Notification.show(value1 + "\n" + value2);
42 | }
43 | });
44 | HorizontalLayout fieldLayout = new HorizontalLayout(pointFieldEmpty, pointFieldInitialized);
45 | fieldLayout.setSizeFull();
46 | fieldLayout.setSpacing(true);
47 | VerticalLayout layout = new VerticalLayout(fieldLayout, getValueButton);
48 | layout.setExpandRatio(fieldLayout, 1f);
49 | layout.setSizeFull();
50 | layout.setSpacing(true);
51 | return layout;
52 | }
53 |
54 | private Geometry readWKT(String wktString) {
55 | try {
56 | return wkt.read(wktString);
57 | } catch (ParseException e) {
58 | e.printStackTrace();
59 | }
60 | return null;
61 | }
62 |
63 | private Point getPoint() {
64 | return (Point) readWKT("POINT (23 64)");
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/src/test/java/org/vaadin/addon/leaflet/demoandtestapp/ZoomLimitTest.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.demoandtestapp;
2 |
3 | import com.vaadin.ui.Component;
4 | import com.vaadin.ui.HorizontalLayout;
5 | import com.vaadin.ui.Label;
6 |
7 | import org.vaadin.addon.leaflet.LMap;
8 | import org.vaadin.addon.leaflet.LOpenStreetMapLayer;
9 | import org.vaadin.addon.leaflet.LeafletMoveEndEvent;
10 | import org.vaadin.addon.leaflet.LeafletMoveEndListener;
11 | import org.vaadin.addonhelpers.AbstractTest;
12 |
13 | @SuppressWarnings("serial")
14 | public class ZoomLimitTest extends AbstractTest {
15 |
16 | private final int MIN_ZOOM_LEVEL = 10;
17 | private final int MAX_ZOOM_LEVEL = 16;
18 |
19 | private final LMap leafletMap = new LMap();
20 |
21 | private final Label zoomLabel = new Label();
22 |
23 | @Override
24 | public String getDescription() {
25 | return "Test for min/max zoom";
26 | }
27 |
28 | @Override
29 | public Component getTestComponent() {
30 | LOpenStreetMapLayer layer = new LOpenStreetMapLayer();
31 | leafletMap.addBaseLayer(layer, "OSM");
32 | leafletMap.setCenter(42.3625, -71.112);
33 | leafletMap.setZoomLevel(15);
34 |
35 | leafletMap.setMinZoom(MIN_ZOOM_LEVEL);
36 | leafletMap.setMaxZoom(MAX_ZOOM_LEVEL);
37 |
38 | leafletMap.addMoveEndListener(new LeafletMoveEndListener() {
39 | @Override
40 | public void onMoveEnd(LeafletMoveEndEvent event) {
41 | updateZoomLabel();
42 | }
43 | });
44 |
45 | return leafletMap;
46 | }
47 |
48 | @Override
49 | protected void setup() {
50 | super.setup();
51 | HorizontalLayout layout = new HorizontalLayout();
52 | layout.addComponent(zoomLabel);
53 | content.addComponentAsFirst(layout);
54 | updateZoomLabel();
55 | }
56 |
57 | private void updateZoomLabel() {
58 | zoomLabel.setCaption("Min zoom: " + MIN_ZOOM_LEVEL + " - " +
59 | "Max zoom: " + MAX_ZOOM_LEVEL + " - " +
60 | "Current zoom: " + leafletMap.getZoomLevel());
61 | }
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/src/test/java/org/vaadin/addon/leaflet/demoandtestapp/ZoomToExtendOnInitilaRender.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.demoandtestapp;
2 |
3 | import java.util.ArrayList;
4 | import java.util.Arrays;
5 |
6 | import org.vaadin.addon.leaflet.LMap;
7 | import org.vaadin.addon.leaflet.LMarker;
8 | import org.vaadin.addon.leaflet.shared.Bounds;
9 | import org.vaadin.addon.leaflet.shared.Control;
10 | import org.vaadin.addon.leaflet.shared.Point;
11 |
12 | import com.vaadin.ui.Component;
13 | import com.vaadin.ui.VerticalLayout;
14 | import org.vaadin.addon.leaflet.LOpenStreetMapLayer;
15 | import org.vaadin.addonhelpers.AbstractTest;
16 |
17 | public class ZoomToExtendOnInitilaRender extends AbstractTest {
18 |
19 | @Override
20 | public String getDescription() {
21 | return "A simple test for zoom to extend on initial render";
22 | }
23 |
24 |
25 | @Override
26 | public Component getTestComponent() {
27 | final double[] latitude = {44.03664d, 43.961669d, 43.859999d};
28 | final double[] longitude = {11.161893d, 11.129769d, 11.061234d};
29 |
30 | final VerticalLayout layout = new VerticalLayout();
31 | layout.setMargin(true);
32 | layout.setSizeFull();
33 |
34 | // Getting my map.
35 | LMap map = new LMap();
36 | map.setControls(new ArrayList(Arrays.asList(Control.values())));
37 | map.setSizeFull();
38 |
39 | // Setting backgroud layer.
40 | map.addBaseLayer(new LOpenStreetMapLayer(), "OSM");
41 |
42 | // I am here.
43 | LMarker myPositon = new LMarker(43.894367,11.078185);
44 | myPositon.setVisible(true);
45 | map.addComponent(myPositon);
46 |
47 | // Get random other point.
48 | int idxOther = Math.min((int)(Math.random() * 3.d), 2);
49 |
50 | // Put other point on map.
51 | LMarker leafletMarker = new LMarker(latitude[idxOther], longitude[idxOther]);
52 | map.addComponent(leafletMarker);
53 |
54 | // Build map bounds.
55 | Point[] mapPoints = {new Point(43.894367,11.078185), new Point(latitude[idxOther], longitude[idxOther])};
56 | Bounds mapBounds = new Bounds(mapPoints);
57 |
58 | // I'm expecting to see my map with two points.
59 | map.setCenter(mapBounds);
60 | map.zoomToExtent(mapBounds);
61 |
62 | layout.addComponent(map);
63 | return layout;
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/src/test/java/org/vaadin/addon/leaflet/demoandtestapp/ZoomToExtendPointOnly.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.demoandtestapp;
2 |
3 |
4 | import org.vaadin.addon.leaflet.LMap;
5 | import org.vaadin.addon.leaflet.LMarker;
6 |
7 | import com.vaadin.ui.Component;
8 | import com.vaadin.ui.VerticalLayout;
9 | import org.vaadin.addon.leaflet.LOpenStreetMapLayer;
10 | import org.vaadin.addonhelpers.AbstractTest;
11 |
12 | public class ZoomToExtendPointOnly extends AbstractTest {
13 |
14 | @Override
15 | public String getDescription() {
16 | return "A should not show empty map";
17 | }
18 |
19 |
20 | @Override
21 | public Component getTestComponent() {
22 |
23 | final VerticalLayout layout = new VerticalLayout();
24 | layout.setMargin(true);
25 | layout.setSizeFull();
26 |
27 | // Getting my map.
28 | LMap map = new LMap();
29 | map.addComponent(new LOpenStreetMapLayer());
30 | LMarker lMarker = new LMarker(61, 22);
31 | map.addComponent(lMarker);
32 |
33 | map.zoomToContent();
34 |
35 | layout.addComponent(map);
36 | return layout;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/test/java/org/vaadin/addon/leaflet/demoandtestapp/util/UiRunner.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.demoandtestapp.util;
2 |
3 | import com.vaadin.annotations.Widgetset;
4 | import org.vaadin.addonhelpers.TServer;
5 |
6 | @Widgetset("org.vaadin.addon.leaflet.Widgetset")
7 | public class UiRunner extends TServer {
8 |
9 | /**
10 | * Starts and embedded server for the tests
11 | */
12 | public static void main(String[] args) throws Exception {
13 | new UiRunner().startServer();
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/test/java/org/vaadin/addon/leaflet/junit/BoundsTest.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.junit;
2 |
3 | import java.util.Random;
4 | import org.junit.Assert;
5 | import org.junit.Test;
6 | import org.vaadin.addon.leaflet.shared.Bounds;
7 |
8 | /**
9 | *
10 | * @author Matti Tahvonen
11 | */
12 | public class BoundsTest {
13 |
14 | @Test
15 | public void testNortWest() {
16 |
17 | Bounds bounds = new Bounds();
18 |
19 | final double latBase = 42.3791618;
20 | final double lonBase = -71.1138139;
21 |
22 | final String[] names = new String[]{"Gabrielle Patel", "Brian Robinson", "Eduardo Haugen", "Koen Johansen", "Alejandro Macdonald", "Angel Karlsson", "Yahir Gustavsson", "Haiden Svensson", "Emily Stewart", "Corinne Davis", "Ryann Davis", "Yurem Jackson", "Kelly Gustavsson", "Eileen Walker", "Katelyn Martin", "Israel Carlsson", "Quinn Hansson", "Makena Smith", "Danielle Watson", "Leland Harris", "Gunner Karlsen", "Jamar Olsson", "Lara Martin", "Ann Andersson", "Remington Andersson", "Rene Carlsson", "Elvis Olsen", "Solomon Olsen", "Jaydan Jackson", "Bernard Nilsen"};
23 | Random r = new Random(0);
24 | for (String name : names) {
25 | double lat = latBase + 0.02 * r.nextDouble() - 0.02 * r.
26 | nextDouble();
27 | double lon = lonBase + 0.02 * r.nextDouble() - 0.02 * r.
28 | nextDouble();
29 | bounds.extend(lat, lon);
30 | }
31 |
32 | Assert.assertTrue(bounds.getNorthEastLat() > latBase);
33 | Assert.assertTrue(bounds.getNorthEastLon() > lonBase);
34 | Assert.assertTrue(bounds.getSouthWestLat() < latBase);
35 | Assert.assertTrue(bounds.getSouthWestLon() < lonBase);
36 |
37 | Assert.assertTrue(bounds.getNorthEastLat() > 42);
38 | Assert.assertTrue(bounds.getNorthEastLat() < 43);
39 |
40 | Assert.assertTrue(bounds.getSouthWestLat() > 42);
41 | Assert.assertTrue(bounds.getSouthWestLat() < 43);
42 |
43 | Assert.assertTrue(bounds.getSouthWestLon() < -71);
44 | Assert.assertTrue(bounds.getSouthWestLon() > -72);
45 |
46 | Assert.assertTrue(bounds.getNorthEastLon()< -71);
47 | Assert.assertTrue(bounds.getNorthEastLon() > -72);
48 |
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/src/test/java/org/vaadin/addon/leaflet/junit/OnePointLineAndZoomToContent.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.junit;
2 |
3 | import org.junit.Test;
4 | import org.vaadin.addon.leaflet.LMap;
5 | import org.vaadin.addon.leaflet.LPolyline;
6 | import org.vaadin.addon.leaflet.shared.Point;
7 |
8 | public class OnePointLineAndZoomToContent {
9 |
10 | @Test
11 | public void test() {
12 | LMap lMap = new LMap();
13 | lMap.addComponent(new LPolyline(new Point(0,0)));
14 | lMap.zoomToContent();
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/src/test/java/org/vaadin/addon/leaflet/testbenchtests/SimpleTest.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addon.leaflet.testbenchtests;
2 |
3 | import java.io.IOException;
4 | import java.util.concurrent.TimeUnit;
5 |
6 | import org.junit.Assert;
7 | import org.junit.Test;
8 | import org.openqa.selenium.By;
9 | import org.openqa.selenium.NoSuchElementException;
10 | import org.openqa.selenium.WebElement;
11 | import org.vaadin.addonhelpers.TListUi;
12 | import org.vaadin.addonhelpers.automated.AbstractWebDriverCase;
13 |
14 | import java.util.List;
15 | import org.openqa.selenium.firefox.FirefoxDriver;
16 |
17 | public class SimpleTest extends AbstractWebDriverCase {
18 |
19 | @Test
20 | public void checkAllTestsOpenWithoutErrors() throws IOException, AssertionError {
21 | startBrowser();
22 |
23 | driver.manage().timeouts().implicitlyWait(2000, TimeUnit.MILLISECONDS);
24 |
25 | List listTestClasses = TListUi.listTestClasses();
26 | for (TListUi.TestDetails td : listTestClasses) {
27 | Class clazz = td.getClazz();
28 |
29 | driver.get(BASEURL + clazz.getName() + "?debug");
30 | waitForLoading();
31 | try {
32 | WebElement error = driver.findElement(By.className("v-Notification-error"));
33 | Assert.fail("Test " + clazz.getName() + " has client side exception");
34 | } catch (NoSuchElementException e) {
35 | continue;
36 | }
37 |
38 | }
39 |
40 | }
41 |
42 | @Override
43 | protected void startBrowser() {
44 | startBrowser(new FirefoxDriver());
45 | }
46 | }
--------------------------------------------------------------------------------
/src/test/java/org/vaadin/addonhelpers/Config.java:
--------------------------------------------------------------------------------
1 | package org.vaadin.addonhelpers;
2 |
3 | import com.vaadin.annotations.Widgetset;
4 |
5 | @Widgetset("org.vaadin.addon.leaflet.Widgetset")
6 | public class Config {
7 |
8 | }
9 |
--------------------------------------------------------------------------------
/src/test/resources/org/vaadin/addon/leaflet/demoandtestapp/testStyles.css:
--------------------------------------------------------------------------------
1 | .leaflet-pane .tooltip-custom-style-test {
2 | color : #ffffff;
3 | background-color: #ff00ff;
4 | }
5 | .popup-custom-style-test .leaflet-popup-tip,
6 | .popup-custom-style-test .leaflet-popup-content-wrapper {
7 | color : #ffffff;
8 | background-color: #ff00ff;
9 | }
--------------------------------------------------------------------------------
/src/test/resources/org/vaadin/addon/leaflet/demoandtestapp/testicon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mstahv/v-leaflet/72ca53935b94a980fc23e030b8a00c142821f1a9/src/test/resources/org/vaadin/addon/leaflet/demoandtestapp/testicon.png
--------------------------------------------------------------------------------