OpenLayers 3调整功能的大小

时间:2016-08-08 08:55:32

标签: openlayers-3

我正在为我的应用程序使用OpenLayers 3和OpenStreetMap。 我设法在地图上绘制圆形矢量来绘制标记,我的问题是圆形在放大和缩小时总是具有相同的大小。 如何根据分辨率更改矢量的大小?

这是我的矢量定义:

exports.config = {

directConnect: true, 
capabilities: {
    'browserName': 'chrome'
},
baseUrl: 'http://juliemr.github.io/protractor-demo/', 
framework: 'jasmine2', 
specs: ['*spec.js '], 
allScriptsTimeout: 180000, 
getPageTimeout: 180000, 
jasmineNodeOpts: {
    defaultTimeoutInterval: 180000
},
 resultJsonOutputFile: './Report.json', // It would create report.json file in your current folder
 onPrepare: function () {

    browser.driver.manage().window().maximize();
    browser.ignoreSynchronization = true;
}
};

1 个答案:

答案 0 :(得分:0)

您可以根据缩放级别更改圆圈的大小(如果这是您想要的)

var dealerSource = new ol.source.Vector();
function dealerStyle(feature) {
    var style = new ol.style.Style({
        image: new ol.style.Circle({
            radius: map.getView().getZoom(),
            stroke: new ol.style.Stroke({
                color: 'white',
                width: 2
            }),
            anchor: [1.5, 1.5],
            fill: new ol.style.Fill({
                color: 'green'
            })
        })
    });
    return [style];
}

getZoom()将地图的缩放级别作为数字返回,您可以使用它或对其进行转换以适合您所需的圆圈大小。

请注意,上方越大,缩放级别越大,您的圆圈将被绘制得更大,为了做反向,您可以将值替换为:

yourMaxZoomLevel - map.getView().getZoom()

你也可以使用getResolution()它也返回一个数字