GeoJSONLayer使回调状态加载javascript API arcgis

我想在加载GeoJSONLayer(dataLayer)状态回调成功/错误时显示响应。我尝试了很多次,但仍然没有显示。任何人都可以在加载GeoJSONLayer成功/失败后给我示例回调,因为单击按钮时我想禁用启用按钮状态。

var geojsonLayer = new GeoJSONLayer({
    url             : "<?php echo $url_data_service;?>",copyright       : "PEMKAB BOGOR",popupTemplate   : {
        title       : "No Register : {no_register}",content     : '<table class="table table-bordered table-striped"><tr><td>Nama Pemohon</td><td style="width:5px;">:</td><td>{nama_pemohon}</td></tr><tr><td>Organisasi Pemohon</td><td style="width:5px;">:</td><td>{nama_organisasi}</td></tr><tr><td>Foto</td><td style="width:5px;">:</td><td><img class="img-responsive" src="{image_source}"></td></tr><tr><td>Kecamatan</td><td style="width:5px;">:</td><td>{kecamatan}</td></tr><tr><td>Kelurahan</td><td style="width:5px;">:</td><td>{kelurahan}</td></tr></table><a style="color:white; font-weight:bold;" class="btn btn-block btn-primary" href="{permalink}">Lihat Detail</a>'
    },renderer        : {
        type    : "simple",field   : "no_register",symbol  : {
            type        : "simple-line",color       : [4,90,141],width       : 1,cap         : "round",join        : "round"
        }
    }
});

var map = new Map({
    basemap : "gray",layers  : [geojsonLayer]
});

var view = new MapView({
    container   : "ArcGIS",center      : [ 106.824651,-6.479687 ],zoom        : 12,map         : map
});

view.ui.add(
    new Expand({
        view        : view,content     : new BasemapGallery({view : view,container : document.createElement("div")
    })
}),"top-left");


$('.btnload').click(function(){
    var page = $(this).attr('data-href');
    $(this).prop('disabled','disabled');
    let dataLayer = new GeoJSONLayer({
        url             : "<?php echo $url_data_service;?>/" + page,loadStatus      : false,popupTemplate   : {
            title       : "No Register : {no_register}",content     : '<table class="table table-bordered table-striped"><tr><td>Nama Pemohon</td><td style="width:5px;">:</td><td>{nama_pemohon}</td></tr><tr><td>Organisasi Pemohon</td><td style="width:5px;">:</td><td>{nama_organisasi}</td></tr><tr><td>Foto</td><td style="width:5px;">:</td><td><img class="img-responsive" src="{image_source}"></td></tr><tr><td>Kecamatan</td><td style="width:5px;">:</td><td>{kecamatan}</td></tr><tr><td>Kelurahan</td><td style="width:5px;">:</td><td>{kelurahan}</td></tr></table><a style="color:white; font-weight:bold;" class="btn btn-block btn-primary" href="{permalink}">Lihat Detail</a>'
        },renderer        : {
            type    : "simple",symbol  : {
                type        : "simple-line",width       : 2,join        : "round"
            }
        }
    });
    view.map.add(dataLayer);
});
ldsfh 回答:GeoJSONLayer使回调状态加载javascript API arcgis

您可以使用when()方法

$('.btnload').click(function(){
    var page = $(this).attr('data-href');
    $(this).prop('disabled','disabled');
    let dataLayer = new GeoJSONLayer({
        url             : "<?php echo $url_data_service;?>/" + page,loadStatus      : false,copyright       : "PEMKAB BOGOR",popupTemplate   : {
            title       : "No Register : {no_register}",content     : '<table class="table table-bordered table-striped"><tr><td>Nama Pemohon</td><td style="width:5px;">:</td><td>{nama_pemohon}</td></tr><tr><td>Organisasi Pemohon</td><td style="width:5px;">:</td><td>{nama_organisasi}</td></tr><tr><td>Foto</td><td style="width:5px;">:</td><td><img class="img-responsive" src="{image_source}"></td></tr><tr><td>Kecamatan</td><td style="width:5px;">:</td><td>{kecamatan}</td></tr><tr><td>Kelurahan</td><td style="width:5px;">:</td><td>{kelurahan}</td></tr></table><a style="color:white; font-weight:bold;" class="btn btn-block btn-primary" href="{permalink}">Lihat Detail</a>'
        },renderer        : {
            type    : "simple",field   : "no_register",symbol  : {
                type        : "simple-line",color       : [4,90,141],width       : 2,cap         : "round",join        : "round"
            }
        }
    });

    dataLayer.when(function() {
        //success
        $('.btnload').prop('disabled','');
    },function() {
        //error
        $('.btnload').prop('disabled','');
    });

    view.map.add(dataLayer);
});
本文链接:https://www.f2er.com/3081836.html

大家都在问