Search in sources :

Example 1 with LatLng

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

the class CirclesView method init.

@PostConstruct
public void init() {
    circleModel = new DefaultMapModel();
    // Shared coordinates
    LatLng coord1 = new LatLng(36.879466, 30.667648);
    LatLng coord4 = new LatLng(36.885233, 30.702323);
    // Circle
    Circle circle1 = new Circle(coord1, 500);
    circle1.setStrokeColor("#d93c3c");
    circle1.setFillColor("#d93c3c");
    circle1.setFillOpacity(0.5);
    Circle circle2 = new Circle(coord4, 300);
    circle2.setStrokeColor("#00ff00");
    circle2.setFillColor("#00ff00");
    circle2.setStrokeOpacity(0.7);
    circle2.setFillOpacity(0.7);
    circleModel.addOverlay(circle1);
    circleModel.addOverlay(circle2);
}
Also used : Circle(org.primefaces.model.map.Circle) DefaultMapModel(org.primefaces.model.map.DefaultMapModel) LatLng(org.primefaces.model.map.LatLng) PostConstruct(javax.annotation.PostConstruct)

Example 2 with LatLng

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

the class EventView method onPointSelect.

public void onPointSelect(PointSelectEvent event) {
    LatLng latlng = event.getLatLng();
    FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Point Selected", "Lat:" + latlng.getLat() + ", Lng:" + latlng.getLng()));
}
Also used : LatLng(org.primefaces.model.map.LatLng) FacesMessage(javax.faces.application.FacesMessage)

Example 3 with LatLng

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

the class MarkerSelectionView method init.

@PostConstruct
public void init() {
    simpleModel = new DefaultMapModel();
    // Shared coordinates
    LatLng coord1 = new LatLng(36.879466, 30.667648);
    LatLng coord2 = new LatLng(36.883707, 30.689216);
    LatLng coord3 = new LatLng(36.879703, 30.706707);
    LatLng coord4 = new LatLng(36.885233, 30.702323);
    // Basic marker
    simpleModel.addOverlay(new Marker(coord1, "Konyaalti"));
    simpleModel.addOverlay(new Marker(coord2, "Ataturk Parki"));
    simpleModel.addOverlay(new Marker(coord3, "Karaalioglu Parki"));
    simpleModel.addOverlay(new Marker(coord4, "Kaleici"));
}
Also used : DefaultMapModel(org.primefaces.model.map.DefaultMapModel) LatLng(org.primefaces.model.map.LatLng) Marker(org.primefaces.model.map.Marker) PostConstruct(javax.annotation.PostConstruct)

Example 4 with LatLng

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

the class MarkersView method init.

@PostConstruct
public void init() {
    simpleModel = new DefaultMapModel();
    // Shared coordinates
    LatLng coord1 = new LatLng(36.879466, 30.667648);
    LatLng coord2 = new LatLng(36.883707, 30.689216);
    LatLng coord3 = new LatLng(36.879703, 30.706707);
    LatLng coord4 = new LatLng(36.885233, 30.702323);
    // Basic marker
    simpleModel.addOverlay(new Marker(coord1, "Konyaalti"));
    simpleModel.addOverlay(new Marker(coord2, "Ataturk Parki"));
    simpleModel.addOverlay(new Marker(coord3, "Karaalioglu Parki"));
    simpleModel.addOverlay(new Marker(coord4, "Kaleici"));
}
Also used : DefaultMapModel(org.primefaces.model.map.DefaultMapModel) LatLng(org.primefaces.model.map.LatLng) Marker(org.primefaces.model.map.Marker) PostConstruct(javax.annotation.PostConstruct)

Example 5 with LatLng

use of org.primefaces.model.map.LatLng 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

LatLng (org.primefaces.model.map.LatLng)10 PostConstruct (javax.annotation.PostConstruct)7 DefaultMapModel (org.primefaces.model.map.DefaultMapModel)7 Marker (org.primefaces.model.map.Marker)6 FacesMessage (javax.faces.application.FacesMessage)2 FacesException (javax.faces.FacesException)1 FacesContext (javax.faces.context.FacesContext)1 AjaxBehaviorEvent (javax.faces.event.AjaxBehaviorEvent)1 FacesEvent (javax.faces.event.FacesEvent)1 Circle (org.primefaces.model.map.Circle)1 GeocodeResult (org.primefaces.model.map.GeocodeResult)1 LatLngBounds (org.primefaces.model.map.LatLngBounds)1 Polygon (org.primefaces.model.map.Polygon)1 Polyline (org.primefaces.model.map.Polyline)1