Skip to content

Commit

Permalink
#1201 fixed <b:openStreetMap>
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanrauh committed Aug 13, 2024
1 parent 4aa019f commit c941e9e
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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) {
Expand All @@ -78,21 +72,7 @@ public boolean getRendersChildren() {
return true;
}

// public Collection<String> 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() {
Expand Down Expand Up @@ -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");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public void setZoomControl(boolean _zoomControl) {
}

/**
* zoomGlobal <P>
* 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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand Down
2 changes: 1 addition & 1 deletion xtext/BootsFaces.jsfdsl
Original file line number Diff line number Diff line change
Expand Up @@ -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)."
Expand Down

0 comments on commit c941e9e

Please sign in to comment.