2

我被困住了。我的复选框无法正常工作。我想用一个复选框切换两个图层。这两个图层在加载时应该打开(选中复选框),然后在取消选中时关闭。很简单,我知道,但是尽管查看了许多工作示例并检查了所有帖子,但我无法使其正常工作。我发现的大部分内容都是它如何与 KML 和融合表一起工作。我有一些适用于按钮的工作,但这不适用于复选框。

这是带有复选框的下拉框的代码。

tileNEX = new google.maps.ImageMapType({
            getTileUrl: function(tile, zoom) {
                return "http://mesonet.agron.iastate.edu/cache/tile.py/1.0.0/nexrad-n0q-900913/" + zoom + "/" + tile.x + "/" + tile.y +".png?"+ (new Date()).getTime();
            },
            tileSize: new google.maps.Size(256, 256),
            opacity:0.50,
            name : 'NEXRAD',
            isPng: true
        });


       goes = new google.maps.ImageMapType({
            getTileUrl: function(tile, zoom) {
                return "http://mesonet.agron.iastate.edu/cache/tile.py/1.0.0/goes-ir-4km-900913/" + zoom + "/" + tile.x + "/" + tile.y +".png?"+ (new Date()).getTime();
            },
            tileSize: new google.maps.Size(256, 256),
            opacity:0.50,
            name : 'GOES NA Vis',
            isPng: true
        });

        //create the check box items
        var radarOptions = {
                gmap: map,
                title: "This allows for selection/toggling on/off Radar layer",
                id: "radarCheck",
                label: "Radar",
                action: function(){
                if (map.overlayMapTypes.length==0) {
                  map.overlayMapTypes.push(null); // create empty overlay entry
                  map.overlayMapTypes.setAt("1",tileNEX);
                }
                else {
                    map.overlayMapTypes.clear();
                }

            }
}

        var check1 = new checkBox(radarOptions);

        var radarAnimate = {
                gmap: map,
                title: "This allows for selection/toggling on/off Animated Radar",
                id: "radarAnimate",
                label: "Animate Radar",
                action: function(){
                    alert('Function is coming soon');
                }
        }
        var check2 = new checkBox(radarAnimate);

        var satOptions = {
                gmap: map,
                title: "This allows for selection/toggling on/off Satelite layer",
                id: "satCheck",
                label: "Satellite",
                action: function(){
                if (map.overlayMapTypes.length==0) {
                  map.overlayMapTypes.push(null); // create empty overlay entry
                  map.overlayMapTypes.setAt("1",goes);
                }
                else {
                    map.overlayMapTypes.clear();
                }

            }
}
        var check3 = new checkBox(satOptions);

        //create the input box items

        //possibly add a separator between controls
        var sep = new separator();

        //put them all together to create the drop down
        var ddDivOptions = {
            items: [sep, check1, check2, check3],
            id: "myddOptsDiv"
        }
        //alert(ddDivOptions.items[1]);
        var dropDownDiv = new dropDownOptionsDiv(ddDivOptions);

        var dropDownOptions = {
                gmap: map,
                name: 'Options',
                id: 'ddControl',
                title: 'A custom drop down select with mixed elements',
                position: google.maps.ControlPosition.TOP_RIGHT,
                dropDown: dropDownDiv
        }

        var dropDown1 = new dropDownControl(dropDownOptions);

完整代码

链接到地图

4

0 回答 0