到目前为止,我已尝试使用此代码
feature.getGeometry().getCoordinates()
Run Code Online (Sandbox Code Playgroud)
但它不起作用.我得到的错误是"类型几何上不存在属性getCoordinates".可能与我使用TypeScript的事实有关吗?
我的OpenLayer3地图有问题。当我在地图上添加一些标记时,我想调整地图大小并更改缩放比例,以便在屏幕上设置所有标记。
我的代码如下:
/** CREATE MARKERS **/
for (var i=0;i<1;i++){
var iconFeature = new ol.Feature({
geometry: new
ol.geom.Point(ol.proj.transform([Math.random()*360-180, Math.random()*180-90], 'EPSG:4326', 'EPSG:3857'))
});
vectorSource.addFeature(iconFeature);
var newBound = ol.Bounds();
newBound.extend([Math.random()*360-180, Math.random()*180-90]);
map.zoomToExtent(newBound);
}
/** MARKER STYLE **/
var iconStyle = [
new ol.style.Style({
image: new ol.style.Icon(/** @type {olx.style.IconOptions} */ ({
anchor: [0.5, 46],
anchorXUnits: 'fraction',
anchorYUnits: 'pixels',
opacity: 1,
scale: 0.07,
src: 'marker.png'
}))
})
];
/** ADD LAYER VECTOR **/
var vectorLayer = new ol.layer.Vector({
source: vectorSource,
style: iconStyle
});
/** INIT …Run Code Online (Sandbox Code Playgroud) 所以我使用一个矢量图层来放置我的所有内容:
这是我的代码:
var source = new ol.source.Vector({ wrapX: false });
var vector = new ol.layer.Vector({
source: source,
style: // styleFunction or style or [style] don't know...
});
Run Code Online (Sandbox Code Playgroud)
我想根据他们的类型来设计功能。我在文档中找到了这个,但不知道如何使用它:
...单独的编辑样式具有以下默认值:
styles[ol.geom.GeometryType.POLYGON] = [
new ol.style.Style({
fill: new ol.style.Fill({
color: [255, 255, 255, 0.5]
})
})
];
styles[ol.geom.GeometryType.LINE_STRING] = [
...
];
styles[ol.geom.GeometryType.POINT] = [
...
];
Run Code Online (Sandbox Code Playgroud)
有任何想法吗 ?
在OpenLayers中,我们曾经为我们添加到图层的每个单独的要素独立设置样式:
let feat = new ol.Feature(geometry);
feat.setStyle(myStyle);
Run Code Online (Sandbox Code Playgroud)
较新版本的OpenLayers非常关注"styleFunction"功能,您只需要定义1个样式函数,而不是单独为每个功能设置样式:
let layer = new ol.layer.Vector({
source: mySource,
style: myStyleFunction
});
function myStyleFunction(feature) {
console.log('calling style function');
let props = feature.getProperties();
if (props.drawBlue) {
return new ol.style.Style(...);
} else {
return new ol.style.Style(...);
}
}
Run Code Online (Sandbox Code Playgroud)
我注意到的主要问题是:"调用样式函数"记录在地图的每个平移上,以及地图的每个缩放,用于图层上的所有要素.看起来myStyleFunction正在为图层上的所有功能执行,对地图的每个用户输入都是如此.
问题是:在DOM上使用styleFunction功能比为每个功能使用独立样式更重要吗?我们将使用数以千计的功能,并想知道什么会产生最佳性能.使用旧方法,我无法确定何时在背景中重新绘制要素的方法,但我们只设置了一次样式,之后没有修改.那么这是否意味着旧方法对性能更好?
当然,OpenLayers 3的内部工作非常复杂并且依赖于很多东西,我希望你们中的一个人可以对这个功能有所了解.谢谢.
我正在做一个maplayer切换功能,但是当我切换图层时,所选的功能不会被取消选择。我可以知道如何取消选择 openlayer 3 中的某个功能吗?
$("#show-field-map").click(function(event) {
map.removeLayer(subbasinJsonp);
map.addLayer(fieldJsonp);
$('#show-subbasin-map').attr("disabled", false);
$('#show-field-map').attr("disabled", true);
});
$("#show-subbasin-map").click(function(event) {
map.removeLayer(fieldJsonp);
map.addLayer(subbasinJsonp);
$('#show-field-map').attr("disabled", false);
$('#show-subbasin-map').attr("disabled", true);
});
Run Code Online (Sandbox Code Playgroud) 我似乎无法弄清楚如何杀死这个过程.
我已经知道,我可以,并且一直只是在不同的端口上运行服务器,但这让我感到烦恼,我无法弄清楚这一点.
下面你将首先看到我尝试运行rails时遇到的错误然后我尝试找到PID并杀死所有的错误.
// ? rails s
=> Booting Puma
=> Rails 5.0.0.1 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.6.2 (ruby 2.2.3-p173), codename: Sleepy Sunday Serenity
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://localhost:3000
Exiting
/Users/jrogers2/.rvm/gems/ruby-2.2.3/gems/puma-3.6.2/lib/puma/binder.rb:266:in `initialize': Address already in use - bind(2) for "::1" port 3000 (Errno::EADDRINUSE)
from /Users/jrogers2/.rvm/gems/ruby-2.2.3/gems/puma-3.6.2/lib/puma/binder.rb:266:in `new'
from /Users/jrogers2/.rvm/gems/ruby-2.2.3/gems/puma-3.6.2/lib/puma/binder.rb:266:in `add_tcp_listener'
from /Users/jrogers2/.rvm/gems/ruby-2.2.3/gems/puma-3.6.2/lib/puma/binder.rb:260:in `block in …Run Code Online (Sandbox Code Playgroud)