如何在openlayers3中创建缓冲区样式

时间:2016-08-05 12:58:43

标签: openlayers-3

我在openlayers3中创建缓冲区样式。但是没有得到styles.can任何人的帮助? 这段代码有什么问题。我没有收到任何错误。但是样式没有添加到功能中。我在这段代码中没有收到错误。当我第二次点击时,我收到的错误就像NS_ERROR_FAILURE:in(ol.js)..

  function getbuffer(code, bufferdistance) {
    var bufferdistance = ($("#DropDownList1").val()) * 1000;

    $.ajax({
        type: "POST",
        url: "--.asmx/buffer",
        data: "{'code':'" + code + "','bufferdistance':'" + bufferdistance + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: OnSuccess

    });

    function OnSuccess(data, status) {

        var myObject = JSON.parse(data.d);

        var value = $('#ddlvalue option:selected').val();
        $.ajax({
            type: "POST",
            url: "--.asmx/Getxy",
            data: "{'-code':'" + value + "'}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (data, status) {
                var ObjectIDs = [];
                var obj = JSON.parse(data.d);
                for (var i = 0; i < obj.length; i++) {

                    ObjectIDs.push(myObject[i].x);
                    ObjectIDs.push(myObject[i].y);
                }

                var x = ObjectIDs[0].toString();
                var y = ObjectIDs[1].toString();
                pointgeom = new ol.geom.Point(ol.proj.transform([parseFloat(x), parseFloat(y)], "EPSG:4326", "EPSG:3857"));

                var bufferfeature = new ol.Feature(pointgeom);
                var bufferstyle = new ol.style.Style({
                    image: new ol.style.Circle({
                        stroke: new ol.style.Stroke({
                            width: 5,
                            color: 'blue'
                        }),

                        radius: bufferdistance

                    }),
                    text: new ol.style.Text({
                        font: '12px helvetica,sans-serif',


                        fill: new ol.style.Fill({
                            color: '#000'
                        }),
                        stroke: new ol.style.Stroke({
                            color: '#fff',
                            width: 2
                        })
                    })
                });


                bufferfeature.setStyle(bufferstyle);


                vectorSource.addFeature(bufferfeature);
            }

        });

    }
}

0 个答案:

没有答案