0

我正在使用 Cordova 开发一个 android 应用程序,我首先在 Web 浏览器中尝试了我的代码,它工作正常,但是在 Cordova 中运行时,它会抛出一个错误:

未捕获的类型错误:未定义不是函数

经过检查这里是代码行:

addTo: function (map) {
    map.addLayer(this);
    return this;
},

这是我在 Cordova 中的代码,与我的 Web 应用程序代码非常相似:

document.addEventListener("deviceready", init, false);

function init(){  
    var map = L.map('map').setView([9.0173,7.0382], 14);
    L.tileLayer(
            './tile/cbrRE_TMS/{z}/{x}/{y}.png',{
            minZoom: 13,
            maxZoom: 19,
            tms:true,
            attribution: '©<a href="http://csulidar1.info">CSU Phil-LiDAR 1</a>'
        }).addTo(map);

        //Initialise the FeatureGroup to store editable layers
        var drawnItems = L.featureGroup().addTo(map);
        map.addLayer(drawnItems);

        //Initialise the draw control and pass it the FeatureGroup of editable layers
        var drawControl = new L.Control.Draw({
            edit: {
                featureGroup: drawnItems
            },
            draw:{
                polyline: false,
                circle: false,
                marker: false
            }   
        });
        map.addControl(drawControl);

        map.on('draw:created', function(e) {
            var data = drawnItems.addLayer(e.layer);
            var json = data.toGeoJSON();
            check_intersect(json);
        });

        map.on('draw:drawstart', function() {
            drawnItems.clearLayers();       
        });
}

function check_intersect(drawn){
    var dataset1  = {"type":"FeatureCollection","features":[{"type":"Feature","properties":{"name":"low"},"geometry":{"type":"Polygon","coordinates":[[[6.980266571044922,9.031238813242956],[6.994171142578125,9.034459931058423],...}

    f1 = dataset1.features;
    f2 = drawn.features;

    var conflictlist;

    for (var i = 0; i < f1.length; i++) {
        var parcel1 = f1[i];
        for (var j = 0; j <f2.length; j++) {
            var parcel2 = f2[j];
            //console.log("Processing",i,j);
                var conflict = turf.intersect(parcel1, parcel2);
                if (conflict != null) {
                    conflictlist = conflict;
                }
        }
    }
    var intersect_style = {
        fillColor: "#ff0000",
        color: "#000",
        opacity: 1,
        weight:0.5,
        fillOpacity: 0.8
    };
    L.geoJson(conflictlist,{
        style: intersect_style
    }).addTo(map);
    //console.log(conflictlist);
}

可能是什么问题呢?

4

0 回答 0