Ken February 2016

Multiselect features in OpenLayers 3 not working

I am new to OpenLayers and have made a simple example where I try to enable drawing of polygons on a map. After drawing I want to be able to multiselect the polygons pressing shift click for further processing. I can not make this work even though some examples on the OpenLayers example page are pretty close... Here is my code (press Draw button and draw two polygons, press Stop button to exit drawing mode and try to multiselect holding shift key):

 <body>
        <div>
        <img src="stop.png" class="fmsv_map_btn" id="fmsv_stop_elm" title="Stop drawing" alt="Stop drawing">
        <img src="draw.png" class="fmsv_map_btn" id="fmsv_contour_elm" title="Contour" alt="Contour">    
        </div>
        <div width="600" height="600" id="map" class="map"></div>
        <script>
        var engine = this;
        var draw = null;
        var map = new ol.Map({
            target: "map",
            layers: [
              new ol.layer.Tile({
                  source: new ol.source.MapQuest({ layer: 'osm' })
              })
            ],
            view: new ol.View({
                center: [0,0],
                zoom: 2
            })
        });
        var features = new ol.Collection();
        var source = new ol.source.Vector({ features: features });
        var featureOverlay = new ol.layer.Vector({
            source: source,
            style: new ol.style.Style({
                fill: new ol.style.Fill({
                    color: 'rgba(255, 255, 255, 0.2)'
                }),
                stroke: new ol.style.Stroke({
                    color: '#000000',
                    width: 1
                }),
                image: new ol.style.Circle({
                    radius: 7,
                    fill: new ol.style.Fill({
                        color: '#000000'
                    })
                })
            })
        });
        featureOverlay.setMap(map);
        $("#fmsv_c        

Answers


oterral February 2016

Use map.addLayer(featureOverlay); instead of featureOverlay.setMap(map)

Post Status

Asked in February 2016
Viewed 1,659 times
Voted 14
Answered 1 times

Search




Leave an answer