Search in sources :

Example 1 with GeocodeResult

use of org.primefaces.model.map.GeocodeResult in project primefaces by primefaces.

the class GMap method queueEvent.

@Override
public void queueEvent(FacesEvent event) {
    FacesContext context = getFacesContext();
    Map<String, String> params = context.getExternalContext().getRequestParameterMap();
    String eventName = params.get(Constants.RequestParams.PARTIAL_BEHAVIOR_EVENT_PARAM);
    String clientId = getClientId(context);
    if (ComponentUtils.isRequestSource(this, context)) {
        AjaxBehaviorEvent behaviorEvent = (AjaxBehaviorEvent) event;
        FacesEvent wrapperEvent = null;
        if ("overlaySelect".equals(eventName) || "overlayDblSelect".equals(eventName)) {
            wrapperEvent = new OverlaySelectEvent(this, behaviorEvent.getBehavior(), getModel().findOverlay(params.get(clientId + "_overlayId")));
            // if there is info window, update and show it
            GMapInfoWindow infoWindow = getInfoWindow();
            if (infoWindow != null) {
                PrimeFaces.current().ajax().update(infoWindow.getClientId(context));
            }
        } else if ("stateChange".equals(eventName)) {
            String[] centerLoc = params.get(clientId + "_center").split(",");
            String[] northeastLoc = params.get(clientId + "_northeast").split(",");
            String[] southwestLoc = params.get(clientId + "_southwest").split(",");
            int zoomLevel = Integer.parseInt(params.get(clientId + "_zoom"));
            LatLng center = new LatLng(Double.valueOf(centerLoc[0]), Double.valueOf(centerLoc[1]));
            LatLng northeast = new LatLng(Double.valueOf(northeastLoc[0]), Double.valueOf(northeastLoc[1]));
            LatLng southwest = new LatLng(Double.valueOf(southwestLoc[0]), Double.valueOf(southwestLoc[1]));
            wrapperEvent = new StateChangeEvent(this, behaviorEvent.getBehavior(), new LatLngBounds(northeast, southwest), zoomLevel, center);
        } else if ("pointSelect".equals(eventName) || "pointDblSelect".equals(eventName)) {
            String[] latlng = params.get(clientId + "_pointLatLng").split(",");
            LatLng position = new LatLng(Double.valueOf(latlng[0]), Double.valueOf(latlng[1]));
            wrapperEvent = new PointSelectEvent(this, behaviorEvent.getBehavior(), position);
        } else if ("markerDrag".equals(eventName)) {
            Marker marker = (Marker) getModel().findOverlay(params.get(clientId + "_markerId"));
            double lat = Double.parseDouble(params.get(clientId + "_lat"));
            double lng = Double.parseDouble(params.get(clientId + "_lng"));
            marker.setLatlng(new LatLng(lat, lng));
            wrapperEvent = new MarkerDragEvent(this, behaviorEvent.getBehavior(), marker);
        } else if ("geocode".equals(eventName)) {
            List<GeocodeResult> results = new ArrayList<>();
            String query = params.get(clientId + "_query");
            String[] addresses = params.get(clientId + "_addresses").split("_primefaces_");
            String[] lats = params.get(clientId + "_lat").split(",");
            String[] lngs = params.get(clientId + "_lng").split(",");
            for (int i = 0; i < addresses.length; i++) {
                results.add(new GeocodeResult(addresses[i], new LatLng(Double.valueOf(lats[i]), Double.valueOf(lngs[i]))));
            }
            wrapperEvent = new GeocodeEvent(this, behaviorEvent.getBehavior(), query, results);
        } else if ("reverseGeocode".equals(eventName)) {
            String[] results = params.get(clientId + "_address").split("_primefaces_");
            List<String> addresses = Arrays.asList(results);
            double lat = Double.parseDouble(params.get(clientId + "_lat"));
            double lng = Double.parseDouble(params.get(clientId + "_lng"));
            LatLng coord = new LatLng(lat, lng);
            wrapperEvent = new ReverseGeocodeEvent(this, behaviorEvent.getBehavior(), coord, addresses);
        }
        if (wrapperEvent == null) {
            throw new FacesException("Component " + getClass().getName() + " does not support event " + eventName + "!");
        }
        wrapperEvent.setPhaseId(behaviorEvent.getPhaseId());
        super.queueEvent(wrapperEvent);
    } else {
        super.queueEvent(event);
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) LatLngBounds(org.primefaces.model.map.LatLngBounds) AjaxBehaviorEvent(javax.faces.event.AjaxBehaviorEvent) FacesEvent(javax.faces.event.FacesEvent) Marker(org.primefaces.model.map.Marker) FacesException(javax.faces.FacesException) LatLng(org.primefaces.model.map.LatLng) GeocodeResult(org.primefaces.model.map.GeocodeResult)

Aggregations

FacesException (javax.faces.FacesException)1 FacesContext (javax.faces.context.FacesContext)1 AjaxBehaviorEvent (javax.faces.event.AjaxBehaviorEvent)1 FacesEvent (javax.faces.event.FacesEvent)1 GeocodeResult (org.primefaces.model.map.GeocodeResult)1 LatLng (org.primefaces.model.map.LatLng)1 LatLngBounds (org.primefaces.model.map.LatLngBounds)1 Marker (org.primefaces.model.map.Marker)1