diff --git a/src/main/java/net/bootsfaces/component/openStreetMap/OpenStreetMap.java b/src/main/java/net/bootsfaces/component/openStreetMap/OpenStreetMap.java index c39341b3..b84e0ce3 100644 --- a/src/main/java/net/bootsfaces/component/openStreetMap/OpenStreetMap.java +++ b/src/main/java/net/bootsfaces/component/openStreetMap/OpenStreetMap.java @@ -49,23 +49,17 @@ public class OpenStreetMap extends OpenStreetMapCore implements ClientBehaviorHo public static final String DEFAULT_RENDERER = "net.bootsfaces.component.openStreetMap.OpenStreetMap"; - public static final String LEAFLET_VERSION = "1.3.4"; - -// private static final Collection EVENT_NAMES = Collections.unmodifiableCollection(Arrays.asList("click", -// "dblclick", "dragstart", "dragover", "drop", "mousedown", "mousemove", "mouseout", "mouseover", "mouseup")); + public static final String LEAFLET_VERSION = "1.9.4"; public OpenStreetMap() { setRendererType(DEFAULT_RENDERER); Tooltip.addResourceFiles(); -// AddResourcesListener.addThemedCSSResource("core.css"); - AddResourcesListener - .addResourceIfNecessary("https://cdnjs.cloudflare.com/ajax/libs/leaflet/"+LEAFLET_VERSION+"/leaflet-src.js"); - AddResourcesListener - .addResourceIfNecessary("https://cdnjs.cloudflare.com/ajax/libs/leaflet/"+LEAFLET_VERSION+"/leaflet-src.js.map"); - AddResourcesListener.addResourceIfNecessary("https://cdnjs.cloudflare.com/ajax/libs/leaflet/"+LEAFLET_VERSION+"/leaflet.css"); - AddResourcesListener.addResourceIfNecessary("https://cdnjs.cloudflare.com/ajax/libs/leaflet/"+LEAFLET_VERSION+"/leaflet.js"); - AddResourcesListener - .addResourceIfNecessary("https://cdnjs.cloudflare.com/ajax/libs/leaflet/"+LEAFLET_VERSION+"/leaflet.js.map"); + String url = "https://cdnjs.cloudflare.com/ajax/libs/leaflet/"+LEAFLET_VERSION; + AddResourcesListener.addResourceIfNecessary(url+"/leaflet.css"); + AddResourcesListener.addResourceIfNecessary(url+"/leaflet.js"); + AddResourcesListener.addResourceIfNecessary(url+"/leaflet.js.map"); + // activate this for debugging (and deactive the two imports above): + // AddResourcesListener.addResourceIfNecessary(url+"/leaflet-src.js"); } public void setValueExpression(String name, ValueExpression binding) { @@ -78,21 +72,7 @@ public boolean getRendersChildren() { return true; } -// public Collection getEventNames() { -// return EVENT_NAMES; -// } - -// public String getDefaultEventName() { -// return "click"; -// } - public void processEvent(ComponentSystemEvent event) throws AbortProcessingException { -// if (isAutoUpdate()) { -// if (FacesContext.getCurrentInstance().isPostback()) { -// FacesContext.getCurrentInstance().getPartialViewContext().getRenderIds().add(getClientId()); -// } -// super.processEvent(event); -// } } public String getFamily() { @@ -132,4 +112,13 @@ public void queueEvent(FacesEvent event) { } } + @Override + public void setMiniMap(boolean _miniMap) { + super.setMiniMap(_miniMap); + if (isMiniMap()) { + String minimapUrl = "https://cdnjs.cloudflare.com/ajax/libs/leaflet-minimap/3.4.0"; + AddResourcesListener.addResourceIfNecessary(minimapUrl + "/Control.MiniMap.min.js"); + AddResourcesListener.addResourceIfNecessary(minimapUrl + "/Control.MiniMap.min.css"); + } + } } diff --git a/src/main/java/net/bootsfaces/component/openStreetMap/OpenStreetMapCore.java b/src/main/java/net/bootsfaces/component/openStreetMap/OpenStreetMapCore.java index 855bcc25..8f12699e 100644 --- a/src/main/java/net/bootsfaces/component/openStreetMap/OpenStreetMapCore.java +++ b/src/main/java/net/bootsfaces/component/openStreetMap/OpenStreetMapCore.java @@ -297,7 +297,7 @@ public void setZoomControl(boolean _zoomControl) { } /** - * zoomGlobal

+ * Deactivates the zoom function of the map in favor of the general browser zoom * @return Returns the value of the attribute, or , false, if it hasn't been set by the JSF file. */ public boolean isZoomGlobal() { diff --git a/src/main/java/net/bootsfaces/component/openStreetMap/OpenStreetMapRenderer.java b/src/main/java/net/bootsfaces/component/openStreetMap/OpenStreetMapRenderer.java index de961751..79e7f4b9 100644 --- a/src/main/java/net/bootsfaces/component/openStreetMap/OpenStreetMapRenderer.java +++ b/src/main/java/net/bootsfaces/component/openStreetMap/OpenStreetMapRenderer.java @@ -105,32 +105,32 @@ public void encodeEnd(FacesContext context, UIComponent component) throws IOExce + "', {id: 'osm', attribution: '" + openStreetMap.getAttribution() + "', maxZoom: " + openStreetMap.getMaxZoom() + ", minZoom: " + openStreetMap.getMinZoom() + "}), dragging:" + openStreetMap.isDragging() + ", zoomControl:" + openStreetMap.isZoomControl() + " });", null); - rw.writeText("if('" + openStreetMap.getMarker() + "')", null); - rw.writeText("{", null); - rw.writeText("var " + clientId + "_marker = L.marker([" + openStreetMap.getMarker() - + "],{icon: new L.Icon({iconSize: [25, 41], iconAnchor: [25, 41], popupAnchor: [-12, -45], iconUrl: 'https://cdnjs.cloudflare.com/ajax/libs/leaflet/"+openStreetMap.LEAFLET_VERSION+"/images/marker-icon.png', shadowUrl: 'https://cdnjs.cloudflare.com/ajax/libs/leaflet/"+openStreetMap.LEAFLET_VERSION+"/images/marker-shadow.png'})}).addTo(" - + clientId + "_map);", null); - rw.writeText("if('" + openStreetMap.getPopupMsg() + "')", null); - rw.writeText(clientId + "_marker.bindPopup('" + openStreetMap.getPopupMsg() + "');", null); - rw.writeText("}", null); - rw.writeText("if(!" + openStreetMap.isZoomGlobal() + ")", null); - rw.writeText("{", null); - rw.writeText(clientId + "_map.touchZoom.disable();", null); - rw.writeText(clientId + "_map.doubleClickZoom.disable();", null); - rw.writeText(clientId + "_map.scrollWheelZoom.disable();", null); - rw.writeText(clientId + "_map.boxZoom.disable();", null); - rw.writeText(clientId + "_map.keyboard.disable();", null); - rw.writeText("}", null); - rw.writeText("if(" + openStreetMap.isMiniMap() + ")", null); - rw.writeText("{", null); - rw.writeText("new L.Control.MiniMap(L.tileLayer('" + openStreetMap.getUrlTemplate() + "', {}), {", null); - rw.writeText("toggleDisplay: true,", null); - rw.writeText("zoomAnimation: true,", null); - rw.writeText("position: '" + openStreetMap.getMiniMapPosition() + "',", null); - rw.writeText("width: " + openStreetMap.getMiniMapWidth() + ",", null); - rw.writeText("height: " + openStreetMap.getMiniMapWidth(), null); - rw.writeText("}).addTo(" + clientId + "_map);", null); - rw.writeText("}", null); + if (openStreetMap.getMarker() != null && openStreetMap.getMarker().length() > 0) { + rw.writeText("var " + clientId + "_marker = L.marker([" + openStreetMap.getMarker() + "]).addTo(" + + clientId + "_map);", null); + rw.writeText("var " + clientId + "_marker = L.marker([" + openStreetMap.getMarker() + + "],{icon: new L.Icon({iconSize: [25, 41], iconAnchor: [25, 41], popupAnchor: [-12, -45], iconUrl: 'https://cdnjs.cloudflare.com/ajax/libs/leaflet/" + openStreetMap.LEAFLET_VERSION + "/images/marker-icon.png', shadowUrl: 'https://cdnjs.cloudflare.com/ajax/libs/leaflet/" + openStreetMap.LEAFLET_VERSION + "/images/marker-shadow.png'})}).addTo(" + + clientId + "_map);", null); + if (openStreetMap.getPopupMsg() != null && openStreetMap.getPopupMsg().length()>0) { + rw.writeText(clientId + "_marker.bindPopup('" + openStreetMap.getPopupMsg() + "');", null); + } + } + if (openStreetMap.isZoomGlobal()) { + rw.writeText(clientId + "_map.touchZoom.disable();", null); + rw.writeText(clientId + "_map.doubleClickZoom.disable();", null); + rw.writeText(clientId + "_map.scrollWheelZoom.disable();", null); + rw.writeText(clientId + "_map.boxZoom.disable();", null); + rw.writeText(clientId + "_map.keyboard.disable();", null); + } + if (openStreetMap.isMiniMap()) { + rw.writeText("new L.Control.MiniMap(L.tileLayer('" + openStreetMap.getUrlTemplate() + "', {}), {", null); + rw.writeText("toggleDisplay: true,", null); + rw.writeText("zoomAnimation: true,", null); + rw.writeText("position: '" + openStreetMap.getMiniMapPosition() + "',", null); + rw.writeText("width: " + openStreetMap.getMiniMapWidth() + ",", null); + rw.writeText("height: " + openStreetMap.getMiniMapWidth(), null); + rw.writeText("}).addTo(" + clientId + "_map);", null); + } rw.endElement("script"); } diff --git a/xtext/BootsFaces.jsfdsl b/xtext/BootsFaces.jsfdsl index 8767b2ec..12a0b4b9 100644 --- a/xtext/BootsFaces.jsfdsl +++ b/xtext/BootsFaces.jsfdsl @@ -1661,7 +1661,7 @@ widget openStreetMap maxZoom Integer default "20" "Maximal zoom level the user can configure." dragging Boolean "dragging" zoomControl Boolean "Setting this to false hides the zoom control widget." - zoomGlobal Boolean "zoomGlobal" + zoomGlobal Boolean "Deactivates the zoom function of the map in favor of the general browser zoom" attribution String "Copyright notice, indicating the template provider (aka tile server)." miniMap Boolean "Setting this to true activates a miniature map." miniMapWidth Integer "Width of the miniature map (in pixels)."