Search in sources :

Example 1 with SelectFeature

use of org.gwtopenmaps.openlayers.client.control.SelectFeature in project kapua by eclipse.

the class DevicesMap method placeMarkers.

private void placeMarkers(List<GwtDevice> devices) {
    LonLat lonLat = null;
    final List<GwtDevice> theDevices = devices;
    for (int i = 0; i < devices.size(); i++) {
        final GwtDevice theDevice = devices.get(i);
        if (theDevice.getGpsLatitude() != null && theDevice.getGpsLongitude() != null) {
            StringBuilder sbDeviceTitle = new StringBuilder();
            if (theDevice.getDisplayName() != null) {
                sbDeviceTitle.append(theDevice.getDisplayName()).append(" (").append(theDevice.getClientId()).append(")");
            } else {
                sbDeviceTitle.append(theDevice.getClientId());
            }
            lonLat = new LonLat(theDevice.getGpsLongitude(), theDevice.getGpsLatitude());
            lonLat.transform(DEFAULT_PROJECTION.getProjectionCode(), m_map.getProjection());
            // lets create a vector point on the location
            Style pointStyle = new Style();
            pointStyle.setFillOpacity(0.9);
            pointStyle.setExternalGraphic("eclipse/org/eclipse/kapua/app/console/icon/device_map.png");
            pointStyle.setGraphicSize(37, 34);
            pointStyle.setGraphicOffset(-10, -34);
            pointStyle.setGraphicName(theDevice.getDisplayName());
            Point point = new Point(theDevice.getGpsLongitude(), theDevice.getGpsLatitude());
            // transform point to OSM coordinate system
            point.transform(DEFAULT_PROJECTION, new Projection(m_map.getProjection()));
            VectorFeature pointFeature = new VectorFeature(point, pointStyle);
            Attributes attributes = new Attributes();
            attributes.setAttribute("deviceIdx", i);
            pointFeature.setAttributes(attributes);
            m_markerLayer.addFeature(pointFeature);
        }
    }
    // Click SelectFeature and its Options
    SelectFeatureOptions clickFeatureOptions = new SelectFeatureOptions();
    clickFeatureOptions.onSelect(new SelectFeatureListener() {

        @Override
        public void onFeatureSelected(VectorFeature theVectorFeature) {
            int deviceIdx = theVectorFeature.getAttributes().getAttributeAsInt("deviceIdx");
            GwtDevice device = theDevices.get(deviceIdx);
            if (device != null) {
                m_devicesView.setDevice(device);
            }
        }
    });
    SelectFeature clickFeature = new SelectFeature(m_markerLayer, clickFeatureOptions);
    clickFeature.setClickOut(true);
    clickFeature.setMultiple(false);
    // Hover SelectFeature and its Options
    SelectFeatureOptions hoverFeatureOptions = new SelectFeatureOptions();
    hoverFeatureOptions.setHover();
    hoverFeatureOptions.setHighlightOnly(true);
    hoverFeatureOptions.setRenderIntent(RenderIntent.DEFAULT);
    final SelectFeature hoverFeature = new SelectFeature(m_markerLayer, hoverFeatureOptions);
    hoverFeature.setClickOut(true);
    hoverFeature.setMultiple(false);
    hoverFeature.addFeatureHighlightedListener(new FeatureHighlightedListener() {

        @Override
        public void onFeatureHighlighted(VectorFeature theVectorFeature) {
            int deviceIdx = theVectorFeature.getAttributes().getAttributeAsInt("deviceIdx");
            GwtDevice device = theDevices.get(deviceIdx);
            if (device != null) {
                if (m_popup != null) {
                    m_map.removePopup(m_popup);
                }
                LonLat lonLat = theVectorFeature.getCenterLonLat();
                m_popup = new AnchoredBubble("marker-info", lonLat, new Size(185, 20), "<p>" + device.getDisplayName() + " (" + device.getClientId() + ")</p>", null, false);
                m_map.addPopup(m_popup);
            }
        }
    });
    hoverFeature.addFeatureUnhighlightedListener(new FeatureUnhighlightedListener() {

        @Override
        public void onFeatureUnhighlighted(VectorFeature eventObject) {
            if (m_popup != null) {
                m_map.removePopup(m_popup);
                m_popup = null;
            }
            hoverFeature.unselectAll(null);
        }
    });
    m_map.addControl(clickFeature);
    m_map.addControl(hoverFeature);
    hoverFeature.activate();
    clickFeature.activate();
    // auto-adjust the zoom to show all points
    if (m_markerLayer.getDataExtent() != null) {
        m_map.zoomToExtent(m_markerLayer.getDataExtent());
    } else {
        m_map.zoomTo(1);
    }
}
Also used : FeatureHighlightedListener(org.gwtopenmaps.openlayers.client.event.FeatureHighlightedListener) Size(org.gwtopenmaps.openlayers.client.Size) Attributes(org.gwtopenmaps.openlayers.client.util.Attributes) Projection(org.gwtopenmaps.openlayers.client.Projection) LonLat(org.gwtopenmaps.openlayers.client.LonLat) Point(org.gwtopenmaps.openlayers.client.geometry.Point) Point(org.gwtopenmaps.openlayers.client.geometry.Point) AnchoredBubble(org.gwtopenmaps.openlayers.client.popup.AnchoredBubble) SelectFeatureListener(org.gwtopenmaps.openlayers.client.control.SelectFeature.SelectFeatureListener) GwtDevice(org.eclipse.kapua.app.console.shared.model.GwtDevice) VectorFeature(org.gwtopenmaps.openlayers.client.feature.VectorFeature) Style(org.gwtopenmaps.openlayers.client.Style) SelectFeatureOptions(org.gwtopenmaps.openlayers.client.control.SelectFeatureOptions) SelectFeature(org.gwtopenmaps.openlayers.client.control.SelectFeature) FeatureUnhighlightedListener(org.gwtopenmaps.openlayers.client.event.FeatureUnhighlightedListener)

Example 2 with SelectFeature

use of org.gwtopenmaps.openlayers.client.control.SelectFeature in project geo-platform by geosdi.

the class GenericFeatureOperation method createControl.

/**
 * (non-Javadoc)
 *
 * @see
 * org.geosdi.geoplatform.gui.impl.map.control.GeoPlatformMapControl#createControl()
 */
@Override
public void createControl() {
    if (!initialized) {
        SelectFeatureOptions selectFeatureOptions = new SelectFeatureOptions();
        selectFeatureOptions.clickFeature(new ClickFeatureListener() {

            @Override
            public void onFeatureClicked(final VectorFeature vectorFeature) {
                GeoPlatformMessage.confirmMessage(MapModuleConstants.INSTANCE.GenericFeatureOperation_confirmDeletionTitleText(), MapModuleConstants.INSTANCE.GenericFeatureOperation_confirmDeletionBodyText(), new Listener<MessageBoxEvent>() {

                    @Override
                    public void handleEvent(MessageBoxEvent be) {
                        if (Dialog.YES.equals(be.getButtonClicked().getItemId())) {
                            Dispatcher.forwardEvent(MapWidgetEvents.DELETE_FEATURE, vectorFeature);
                        }
                    }
                });
            }
        });
        control = new SelectFeature(vector, selectFeatureOptions);
        this.initialized = true;
    }
}
Also used : MessageBoxEvent(com.extjs.gxt.ui.client.event.MessageBoxEvent) VectorFeature(org.gwtopenmaps.openlayers.client.feature.VectorFeature) Listener(com.extjs.gxt.ui.client.event.Listener) ClickFeatureListener(org.gwtopenmaps.openlayers.client.control.SelectFeature.ClickFeatureListener) SelectFeatureOptions(org.gwtopenmaps.openlayers.client.control.SelectFeatureOptions) SelectFeature(org.gwtopenmaps.openlayers.client.control.SelectFeature) ClickFeatureListener(org.gwtopenmaps.openlayers.client.control.SelectFeature.ClickFeatureListener)

Example 3 with SelectFeature

use of org.gwtopenmaps.openlayers.client.control.SelectFeature in project geo-platform by geosdi.

the class DeleteEditorFeature method createControl.

@Override
public void createControl() {
    if (!initialized) {
        SelectFeatureOptions selectFeatureOptions = new SelectFeatureOptions();
        selectFeatureOptions.clickFeature(new SelectFeature.ClickFeatureListener() {

            @Override
            public void onFeatureClicked(VectorFeature vectorFeature) {
                deleteFeature(vectorFeature);
            }
        });
        this.deleteFeatureControl = new SelectFeature(vector, selectFeatureOptions);
        this.initialized = true;
    }
}
Also used : VectorFeature(org.gwtopenmaps.openlayers.client.feature.VectorFeature) SelectFeatureOptions(org.gwtopenmaps.openlayers.client.control.SelectFeatureOptions) SelectFeature(org.gwtopenmaps.openlayers.client.control.SelectFeature)

Example 4 with SelectFeature

use of org.gwtopenmaps.openlayers.client.control.SelectFeature in project kapua by eclipse.

the class DevicesMap method onRender.

protected void onRender(final Element parent, int index) {
    super.onRender(parent, index);
    setLayout(new FitLayout());
    setBorders(false);
    // create some MapOptions
    MapOptions defaultMapOptions = new MapOptions();
    defaultMapOptions.setNumZoomLevels(16);
    defaultMapOptions.removeDefaultControls();
    // Create a MapWidget
    m_mapWidget = new MapWidget("500px", "500px", defaultMapOptions);
    // create the mapquest base layer
    OSMOptions osmOptions = new OSMOptions();
    osmOptions.setAttribution("<p>Tiles Courtesy of <a href=\"http://www.mapquest.com/\" target=\"_blank\">MapQuest</a> <img src=\"http://developer.mapquest.com/content/osm/mq_logo.png\"></p> - &copy; <a href=\"http://www.openstreetmap.org/copyright\" target=\"_blank\">OpenStreetMap</a> contributors");
    OSM mapQuest = new OSM("Map", "http://otile1.mqcdn.com/tiles/1.0.0/map/${z}/${x}/${y}.png", osmOptions);
    mapQuest.setIsBaseLayer(true);
    // Create a marker layer to the current location marker
    m_markerLayer = new Vector(MSGS.devices());
    // add selection
    SelectFeature selectFeature = new SelectFeature(m_markerLayer);
    // And add them to the map
    m_map = m_mapWidget.getMap();
    m_map.addLayer(mapQuest);
    m_map.addLayer(m_markerLayer);
    m_map.addControl(selectFeature);
    // Lets add some default controls to the map
    // Display the scaleline
    m_map.addControl(new Attribution());
    // Display the scaleline
    m_map.addControl(new Navigation());
    // Display the scaleline
    m_map.addControl(new DragPan());
    // Display the scaleline
    m_map.addControl(new PanZoom());
    // Display the scaleline
    m_map.addControl(new ScaleLine());
    // Center and zoom to a location
    // transform lonlat to OSM coordinate system
    // Open a map centered in Amaro, Italy. Required
    LonLat lonLat = new LonLat(13.097, 46.375);
    lonLat.transform(DEFAULT_PROJECTION.getProjectionCode(), m_map.getProjection());
    m_map.setCenter(lonLat, 12);
    add(m_mapWidget);
    // force the map to fall behind popups
    m_mapWidget.getElement().getFirstChildElement().getStyle().setZIndex(0);
}
Also used : PanZoom(org.gwtopenmaps.openlayers.client.control.PanZoom) ScaleLine(org.gwtopenmaps.openlayers.client.control.ScaleLine) Navigation(org.gwtopenmaps.openlayers.client.control.Navigation) MapOptions(org.gwtopenmaps.openlayers.client.MapOptions) OSMOptions(org.gwtopenmaps.openlayers.client.layer.OSMOptions) OSM(org.gwtopenmaps.openlayers.client.layer.OSM) LonLat(org.gwtopenmaps.openlayers.client.LonLat) MapWidget(org.gwtopenmaps.openlayers.client.MapWidget) Attribution(org.gwtopenmaps.openlayers.client.control.Attribution) SelectFeature(org.gwtopenmaps.openlayers.client.control.SelectFeature) Vector(org.gwtopenmaps.openlayers.client.layer.Vector) DragPan(org.gwtopenmaps.openlayers.client.control.DragPan) FitLayout(com.extjs.gxt.ui.client.widget.layout.FitLayout)

Aggregations

SelectFeature (org.gwtopenmaps.openlayers.client.control.SelectFeature)4 SelectFeatureOptions (org.gwtopenmaps.openlayers.client.control.SelectFeatureOptions)3 VectorFeature (org.gwtopenmaps.openlayers.client.feature.VectorFeature)3 LonLat (org.gwtopenmaps.openlayers.client.LonLat)2 Listener (com.extjs.gxt.ui.client.event.Listener)1 MessageBoxEvent (com.extjs.gxt.ui.client.event.MessageBoxEvent)1 FitLayout (com.extjs.gxt.ui.client.widget.layout.FitLayout)1 GwtDevice (org.eclipse.kapua.app.console.shared.model.GwtDevice)1 MapOptions (org.gwtopenmaps.openlayers.client.MapOptions)1 MapWidget (org.gwtopenmaps.openlayers.client.MapWidget)1 Projection (org.gwtopenmaps.openlayers.client.Projection)1 Size (org.gwtopenmaps.openlayers.client.Size)1 Style (org.gwtopenmaps.openlayers.client.Style)1 Attribution (org.gwtopenmaps.openlayers.client.control.Attribution)1 DragPan (org.gwtopenmaps.openlayers.client.control.DragPan)1 Navigation (org.gwtopenmaps.openlayers.client.control.Navigation)1 PanZoom (org.gwtopenmaps.openlayers.client.control.PanZoom)1 ScaleLine (org.gwtopenmaps.openlayers.client.control.ScaleLine)1 ClickFeatureListener (org.gwtopenmaps.openlayers.client.control.SelectFeature.ClickFeatureListener)1 SelectFeatureListener (org.gwtopenmaps.openlayers.client.control.SelectFeature.SelectFeatureListener)1