[OpenLayers-Trac] Strategy.Refresh + Control.SelectFeature

Dr Magnum davidson at freemail.hu
Tue Jun 12 02:01:00 PDT 2012


Hi,

I have a problem for a long long time.
If I use Strategy.Refresh + Control.SelectFeature the unselect
(clickout) event disabled
every second (odd) refresh.

Here is the code:

<script type="text/javascript" src="/scripts/js/jquery-1.7.1.min.js"></script>
<script type="text/javascript"
src="/scripts/js/openlayers/lib/OpenLayers.js" ></script>
<script type="text/javascript"
src="http://maps.google.com/maps/api/js?sensor=false&v=3.2"></script>
<script type="text/javascript">
    var map;
    var devid = 25;
    var fromdate = '';
    var todate = '';
    var bnds = new OpenLayers.Bounds(19.0281150, 47.4155120,
19.2480020, 47.5638030);
    var mercator = new OpenLayers.Projection("EPSG:900913");
    var geographic = new OpenLayers.Projection("EPSG:4326");
    var geocoder = new google.maps.Geocoder();
    var url = 'http://localhost:81/';
    var fullurl = 'http://localhost:81/hu';
    var follow = 1;
    var selfeature = '';
    var selectFeat,selectCtrl;

    $(document).ready(function() {
        init();
    });

    function init() {
        map = new OpenLayers.Map('map', {
            allOverlays: true,
            projection: geographic,
            controls: [new OpenLayers.Control.Navigation()]
        });
        var gmap = new OpenLayers.Layer.Google("Google Streets",
{numZoomLevels: 20});
        var vlay = new OpenLayers.Layer.Vector("Points", {
            strategies: [
                new OpenLayers.Strategy.Fixed(),
                new OpenLayers.Strategy.Refresh({
                    active: false,
                    force: true,
                    interval: 3000
                })
            ],
            protocol: new OpenLayers.Protocol.HTTP({
                projection: geographic,
                url: "http://localhost:81/hu/tracker/index/nfkml",
                params: {dev: devid, from: fromdate, to: todate,
follow: follow},
                format: new OpenLayers.Format.KML({
                    extractStyles: true,
                    extractAttributes: true,
                    maxDepth: 2
                })
            }),
            eventListeners:{
                'loadend': alap
            }
        });
        map.addLayers([gmap, vlay]);

        selectCtrl = new OpenLayers.Control.SelectFeature(vlay,
        {
            id: 'sf2',
            clickout: true,
            onSelect: onFS,
            onUnselect: onFuS
        });

        map.addControl(selectCtrl);
        selectCtrl.activate();
    }

    function alap(eventmap){
        if (selfeature != ''){
            var mach = map.layers[1].getFeaturesByAttribute('symler',
selfeature);
            var control = map.getControlsBy('id', 'sf2');
            control[0].clickFeature(mach[0]);
            map.layers[1].redraw();
        }
    }

    function onFS(feature){
        if (map.layers[1].selectedFeatures.length > 0 ){
            selfeature = map.layers[1].selectedFeatures[0].attributes.symler;
        }
    }

    function onFuS(feature){
        selfeature = '';
    }

</script>

<div id="map" class="smallmap"></div>

Thanks for the help

davidson


More information about the Trac mailing list