简体   繁体   English

OpenLayers 3功能已连接

[英]OpenLayers 3 Features Connected

I am attempting to draw some circles on a map. 我正在尝试在地图上绘制一些圆圈。 I am creating the circles as features, then placing them in a layer. 我将圆创建为要素,然后将其放置在图层中。 The issue I am having is that there is a line connecting each of the different features. 我遇到的问题是,有一条线连接着每个不同的功能。 What is causing the features to be connected? 是什么导致功能被连接?

// Generate some rings
var radius = [1000, 2000];
var features = [];
for(var i = 0; i < radius.length; i++)
{
    features[i] = new ol.Feature( new ol.geom.Circle(center, radius[i] / ol.proj.METERS_PER_UNIT.m ) );
}

// Add features to new layer.
var layer = new ol.layer.Vector({
    source: new ol.source.Vector({
        features: features
    }),
    style: new ol.style.Style({
        stroke: new ol.style.Stroke({
            width: 1,
            color: [0, 0, 255, 1]
        })
    })
});
map.addLayer(layer);

Edit: Here is a screenshot of what I am getting http://i.imgur.com/jV19gTJ.png 编辑:这是我得到的截图http://i.imgur.com/jV19gTJ.png

Your code worked fine for me, though I did have to define an initial centre,which I put at [0,0] to match the view I defined for the map. 您的代码对我来说很好用,尽管我必须定义一个初始中心,我将其置于[0,0]以匹配为地图定义的视图。 I also added some ol.Map code (you have not supplied this bit in your Q, so maybe the problem is there?) 我还添加了一些ol.Map代码(您尚未在Q中提供此位,所以也许问题出在那儿?)

I used this HTML: 我使用了以下HTML:

<div id="map" style="width: 100%; height: 500px"></div>

and this JavaScript: 和这个JavaScript:

var center = [0, 0];
var radius = [1000, 2000, 3000, 4000];
var features = [];
for(var i = 0; i < radius.length; i++)
{
    features[i] = new ol.Feature( new ol.geom.Circle(center, radius[i] / ol.proj.METERS_PER_UNIT.m ) );
}

// Add features to new layer.
var layer = new ol.layer.Vector({
    source: new ol.source.Vector({
        features: features
    }),
    style: new ol.style.Style({
        stroke: new ol.style.Stroke({
            width: 1,
            color: [0, 0, 255, 1]
        })
    })
});

var map = new ol.Map({
    layers: [
        new ol.layer.Tile({
            source: new ol.source.OSM()
        }),
        layer
    ],
    target: 'map',
    view: new ol.View({
        center: [0, 0],
        zoom: 10
    })
});

The reason for the connected circles is a bug within openlayers. 圈子相连的原因是openlayers中的错误。 Updating to the newest version corrected the issue. 更新到最新版本可解决此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM