1

I added two features for a map. first handles drawing on map and second one which will show the features in a table. when i am drawing the map the second click event is working. so i stopped the event of getfeatures using unByKey(key) in drawing. But how to start the event back after drawing . Please help me`

        function draw() {
        map.unByKey(k1);
        var wkt = new ol.format.GeoJSON();
        var drawInteraction = new ol.interaction.Draw({
            source : floodAlertLayer.getSource(),
            type : 'Polygon'
        });
        map.addInteraction(drawInteraction);
        drawInteraction.on('drawend', function(e) {
            alert("feature");
            var feature = e.feature;
            feature.set("REGION", "AnglianRegion");
            feature.set("AREA", "Central");
            feature.set("FWD_TACODE", "052FAGBURY");
            feature.set("FWIS_CODE", "052FAGBURY");
            feature.set("FWA_NAME", "GroundwaterFloodinginBuryStEdmunds");
            feature.set("RIVER_SEA", "");
            feature.set("COUNTY", "Suffolk");
            feature.set("DESCRIP", "Areas");
            zoom = map.getView().getZoom();
            center = map.getView().getCenter();
            console.log(center);
            map.removeInteraction(drawInteraction);
            map.setView(new ol.View({
                center : center,
                zoom : zoom
            }));
            var selectInteraction = new ol.interaction.Select();
            map.addInteraction(selectInteraction);
            selectInteraction.getFeatures().push(feature);
            var featureClone = feature.clone();
            featureClone.getGeometry().transform('EPSG:3857', 'EPSG:4326');

            var modifyInteraction = new ol.interaction.Modify({
                features : selectInteraction.getFeatures()
            });
            map.addInteraction(modifyInteraction);
            feature.on('change', function() {
                var featureClone = feature.clone(); 
                featureClone.getGeometry().transform('EPSG:3857',
                        'EPSG:4326');
                modifiedWKT = wkt.writeFeature(featureClone);

            });
            map.removeInteraction(modifyInteraction);
        });


    }
    var myTable = "";
    var displayFeatureInfo = function(pixel) {

        var features = [];
        map.forEachFeatureAtPixel(pixel, function(feature, layer) {
            features.push(feature);
        });
        if (features.length > 0) {
            var info = [];
            var i, ii;
            for (i = 0, ii = features.length; i < ii; ++i) {

                myTable += '<tr><td>' + features[i].get('REGION') + '</td>';
                myTable += '<td>' + features[i].get('AREA') + '</td>';
                myTable += '<td>' + features[i].get('FWD_TACODE') + '</td>';
                myTable += '<td>' + features[i].get('FWIS_CODE') + '</td>';
                myTable += '<td>' + features[i].get('FWA_NAME') + '</td>';
                myTable += '<td>' + features[i].get('DESCRIP') + '</td>';
                myTable += '<td>' + features[i].get('COUNTY') + '</td>';
                myTable += '<td>' + features[i].get('RIVER_SEA')
                        + '</td></tr>';

            }

            document.getElementById('info').innerHTML = myTable;

        } else {
            document.getElementById('info').innerHTML = '&nbsp;';

        }

    }
    var key=function(evt){
        myTable = "";
        myTable += '<table  cellspacing= "0"><thead><tr><th>Feature ID</th><th>REGION</th><th>AREA</th><th>FWD_TACODE</th><th>FWIS_CODE</th><th>FWA_NAME</th><th>DESCRIP</th><th>COUNTY</th><th>RIVER_SEA</tr></thead>';
        mywarningTable = "";
        mywarningTable += '<table  cellspacing= "0"><thead><tr><th>Feature ID</th><th>REGION</th></tr></thead>';
        displayFeatureInfo(evt.pixel);
    }
    var k1=map.on('click',key); 
    function enable() {
        map.un('click',key);
    }`
  • register it a second time in 'drawend' (add k1=map.on('click',key); as the last line). – ca0v Jul 4 '15 at 13:19
  • @ca0v Thank You. Its Working but when i complete drawing its displaying undefined in table. can you help me – pinky Jul 6 '15 at 5:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.