|
| 1 | +/*- |
| 2 | + * #%L |
| 3 | + * Google Maps Addon |
| 4 | + * %% |
| 5 | + * Copyright (C) 2020 - 2024 Flowing Code |
| 6 | + * %% |
| 7 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | + * you may not use this file except in compliance with the License. |
| 9 | + * You may obtain a copy of the License at |
| 10 | + * |
| 11 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | + * |
| 13 | + * Unless required by applicable law or agreed to in writing, software |
| 14 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | + * See the License for the specific language governing permissions and |
| 17 | + * limitations under the License. |
| 18 | + * #L% |
| 19 | + */ |
| 20 | + |
| 21 | +package com.flowingcode.vaadin.addons.googlemaps; |
| 22 | + |
| 23 | +import com.flowingcode.vaadin.addons.demo.DemoSource; |
| 24 | +import com.flowingcode.vaadin.addons.googlemaps.GoogleMap.MapType; |
| 25 | +import com.vaadin.flow.component.button.Button; |
| 26 | +import com.vaadin.flow.component.dependency.CssImport; |
| 27 | +import com.vaadin.flow.component.orderedlayout.HorizontalLayout; |
| 28 | +import com.vaadin.flow.router.PageTitle; |
| 29 | +import com.vaadin.flow.router.Route; |
| 30 | + |
| 31 | +@PageTitle("Custom Controls Demo") |
| 32 | +@DemoSource |
| 33 | +@DemoSource( |
| 34 | + value = "/src/test/resources/META-INF/resources/frontend/styles/google-maps/custom-controls-demo-styles.css", |
| 35 | + caption = "custom-controls-demo-styles.css") |
| 36 | +@Route(value = "googlemaps/custom-controls", layout = GooglemapsDemoView.class) |
| 37 | +@CssImport("./styles/google-maps/custom-controls-demo-styles.css") |
| 38 | +@SuppressWarnings("serial") |
| 39 | +public class CustomControlsDemo extends AbstractGoogleMapsDemo { |
| 40 | + |
| 41 | + @Override |
| 42 | + protected void createGoogleMapsDemo(String apiKey) { |
| 43 | + GoogleMap gmaps = new GoogleMap(apiKey, null, null); |
| 44 | + gmaps.setMapType(MapType.ROADMAP); |
| 45 | + gmaps.setSizeFull(); |
| 46 | + add(gmaps); |
| 47 | + |
| 48 | + Button customControlButton1 = new Button("Custom Control 1"); |
| 49 | + customControlButton1.setClassName("custom-control-button"); |
| 50 | + CustomControl customControl1 = |
| 51 | + new CustomControl(customControlButton1, ControlPosition.TOP_CENTER); |
| 52 | + Button customControlButton2 = new Button("Custom Control 2"); |
| 53 | + customControlButton2.setClassName("custom-control-button"); |
| 54 | + CustomControl customControl2 = |
| 55 | + new CustomControl(customControlButton2, ControlPosition.LEFT_CENTER); |
| 56 | + gmaps.setCustomControls(customControl1, customControl2); |
| 57 | + |
| 58 | + Button customControlButton3 = new Button("Custom Control 3"); |
| 59 | + customControlButton3.setClassName("custom-control-button"); |
| 60 | + CustomControl customControl3 = |
| 61 | + new CustomControl(customControlButton3, ControlPosition.BOTTOM_CENTER); |
| 62 | + |
| 63 | + Button addCustomControl3Button = createDemoButton("Add Custom Control 3"); |
| 64 | + Button removeCustomControl3Button = createDemoButton("Remove Custom Control 3"); |
| 65 | + Button removeAllCustomControlsButton = createDemoButton("Remove all controls"); |
| 66 | + Button resetButton = createDemoButton("Reset"); |
| 67 | + |
| 68 | + addCustomControl3Button.addClickListener(e -> { |
| 69 | + gmaps.addCustomControl(customControl3); |
| 70 | + removeCustomControl3Button.setEnabled(true); // hide-source |
| 71 | + removeAllCustomControlsButton.setEnabled(true); // hide-source |
| 72 | + }); |
| 73 | + |
| 74 | + removeCustomControl3Button.addClickListener(e -> { |
| 75 | + gmaps.removeCustomControl(customControl3); |
| 76 | + addCustomControl3Button.setEnabled(true); // hide-source |
| 77 | + }); |
| 78 | + removeCustomControl3Button.setEnabled(false); |
| 79 | + |
| 80 | + removeAllCustomControlsButton.addClickListener(e -> { |
| 81 | + gmaps.removeCustomControls(); |
| 82 | + addCustomControl3Button.setEnabled(true); // hide-source |
| 83 | + removeCustomControl3Button.setEnabled(false); // hide-source |
| 84 | + resetButton.setEnabled(true); // hide-source |
| 85 | + }); |
| 86 | + |
| 87 | + resetButton.addClickListener(e -> { |
| 88 | + gmaps.setCustomControls(customControl1, customControl2); |
| 89 | + removeAllCustomControlsButton.setEnabled(true); // hide-source |
| 90 | + addCustomControl3Button.setEnabled(true); // hide-source |
| 91 | + removeCustomControl3Button.setEnabled(false); // hide-source |
| 92 | + }); |
| 93 | + |
| 94 | + add(new HorizontalLayout(addCustomControl3Button, removeCustomControl3Button, |
| 95 | + removeAllCustomControlsButton, resetButton)); |
| 96 | + } |
| 97 | + |
| 98 | + private Button createDemoButton(String caption) { |
| 99 | + Button button = new Button(caption); |
| 100 | + button.setDisableOnClick(true); |
| 101 | + return button; |
| 102 | + } |
| 103 | +} |
0 commit comments