标签: openlayers

OpenLayers中的最小/最大缩放级别

我正在使用OpenLayers在网页中显示地图.我正在使用来自CloudMade的磁贴,但OpenStreetMap中的Mapnik磁贴也会出现同样的问题.

我正在尝试限制地图,以便用户无法一直缩放到世界视图 - 我希望它们保持在大致城市级别的缩放至少.

我尝试过使用minZoomLevel/ maxZoomLevel/ numZoomLevels属性; 只有maxZoomLevelnumZoomLevels属性似乎有效,而minZoomLevel属性似乎完全被忽略了.

还有另一种方法来实现这一目标吗?

javascript zoom openlayers openstreetmap cloudmade

20
推荐指数
3
解决办法
3万
查看次数

openlayers简单鼠标悬停在标记上

这听起来很简单,但我找不到任何新手教程:有人能给我一个简单的例子我如何在OpenLayers中创建(vektor)标记,在mouseover上打开infowindow甚至在mouseout上关闭它?

我发现了部分解释但不是全部......

mouseover openlayers infowindow marker

19
推荐指数
3
解决办法
4万
查看次数

OpenLayers 3矢量图层上所有要素的范围?

我有一个OpenLayers 3地图,带有基础层和矢量图层.

this.topoLayer = new ol.layer.Vector({
  source: new ol.source.Vector(),
  style: style
});

var baseLayer = new ol.layer.Tile({
    source: new ol.source.XYZ({
        url: 'http://[…]/{z}/{x}/{y}.png',
        crossOrigin: 'null'
    })
});

this.map = new ol.Map({
    target: 'map',
    layers: [baseLayer, this.topoLayer],
    view: new ol.View2D({
        center: ol.proj.transform([11.38,  48.54], this.options.markerEPSG, this.options.mapEPSG),
        zoom: 5,
    }),
});
Run Code Online (Sandbox Code Playgroud)

在用户交互时,我向向量层添加和删除了几个要素.以下是添加新功能的功能:

  var feature = new ol.Feature({
        topo: topo,
        selected: false,
        geometry: new ol.geom.Point(ol.proj.transform(location, this.options.markerEPSG, this.options.mapEPSG)),
  });

  this.topoLayer.getSource().addFeatures([feature]);
Run Code Online (Sandbox Code Playgroud)

添加/删除新功能后,我想自动缩放和平移地图以适应我的功能.在旧的OpenLayers API中getDataExtent,矢量图层上有一个函数可以检索显示的所有特征周围的"边界框".但我想知道如何使用新的API做到这一点.

javascript openlayers openlayers-3

19
推荐指数
3
解决办法
3万
查看次数

在OpenLayers中保存和恢复几何

背景:我是OpenLayers的一个只有几个小时的新手,请保持温柔.

从根本上说,我有一个地图上有一些绘制的对象.如果我理解正确,我有一些OpenLayer.Feature.Vector(layers?),上面有许多OpenLayer.Geometry"thing"(如LinearRing).

目前,我似乎能够使用.toString()获得几何体的良好表示.是的,我怀疑我做错了 - 随意指出我正确的方向.

这产生了一个非常人性化的,可存储数据库的字符串,例如:

  • 要点(-104.74560546875 44.2841796875)

  • POLYGON(( - 96.52783203125 44.6796875,-96.52783203125 45.734375,-92.22119140625 45.734375,-92.22119140625 44.6796875,-96.52783203125 44.6796875))

  • LINESTRING(-105.71240234375 44.6796875,-106.06396484375 42.658203125,-103.55908203125 42.7021484375,-103.47119140625 45.55859375,-104.65771484375 45.20703125)

有没有一种相反的方法可以将它们从那里带回到对象格式中?

我喜欢使用JSON,但似乎无法让GeoJSON接受我的OpenLayer.Feature.Vector对象(这是CLASS_NAME属性在我进入内部时所说的).

非常感谢.

persistence json geospatial openlayers geojson

17
推荐指数
2
解决办法
2万
查看次数

如何在openlayers中隐藏矢量要素

我已经编写了一些代码来根据地图本身之外的复选框隐藏地图中的特定标记.但是,这些标记也有矢量特征(实际上在不同的图层上),但我想隐藏特征而不是破坏它们.我尝试使用display(false)但得到错误.是否有隐藏矢量的功能?

vector openlayers

17
推荐指数
3
解决办法
2万
查看次数

CDN中提供OpenLayers脚本?

OpenLayers Js脚本是否在某个CDN中可用 - 在缩小版本中?

我不想从他们的网站加载它,这将是缓慢而不好.

cdn openlayers

16
推荐指数
2
解决办法
6458
查看次数

如何从openlayers读取外部GeoJSON文件?

我必须通过OpenLayers绘制一些代码.线要素编码为GeoJSON格式.我的代码适用于硬编码的GeoJSON功能.但是,如果我将此功能放在单独的文件中并尝试加载它.它只是不起作用.我不知道加载外部GeoJSON文件有什么问题.我已经给了这两个代码.

代码1:

// This code is ok with hard coded GeoJSON features
map.addControl(new OpenLayers.Control.LayerSwitcher());

            vectorLayer = new OpenLayers.Layer.Vector("Lines");

            var myGeoJSON = { "type": "FeatureCollection",
                "features": 
                [

                    { "type": "Feature", "properties": { "LENGTH": 756.304000}, "geometry": { "type": "LineString", "coordinates": [ [ 18.105018, 59.231027 ], [ 18.104176, 59.230737 ], [ 18.103928, 59.230415 ], [ 18.103650, 59.230336 ], [ 18.103028, 59.230463 ], [ 18.102491, 59.230418 ], [ 18.101976, 59.230237 ], [ 18.100893, 59.230110 ], [ 18.100117, 59.230016 ], [ 18.097715, 59.230262 ], [ …
Run Code Online (Sandbox Code Playgroud)

map geo openlayers geojson

16
推荐指数
1
解决办法
2万
查看次数

为什么示例不起作用?(与进口斗争)

在页面https://openlayers.org/en/latest/examples/image-vector-layer.html我将HTML代码从地图下复制到/tmp/a.html并运行firefox /tmp/a.html.

最初有两个问题很容易解决:

  1. SyntaxError:import声明只能出现在模块的顶层
  2. 未声明HTML文档的字符编码.文件......

要解决这个问题:

  1. 替换<script><script type="module">
  2. 添加<meta charset="UTF-8"><head></head>

但是第三个错误怎么办?

TypeError: Error resolving module specifier: ol/Map.js

我有Firefox 60.0.1.

那么,示例中的HTML代码是否可以像我一样使用,或者我误解了什么?

我的代码需要import Map from ol/Map.js什么?

(我试图重新提出问题,但如果我仍然应该得到负面排名,请解释原因.谢谢)

openlayers

16
推荐指数
2
解决办法
9809
查看次数

在OpenLayers 3中添加事件处理程序到功能?

我使用以下代码将功能添加到OpenLayers 3(OL3)中的矢量图层:

marker = new ol.Feature({
    geometry: new ol.geom.Point([longitude, latitude]),
    name: "Location Marker"
});
markerStyle = new ol.style.Style({
  image: new ol.style.Icon({
    anchor: [0.5, 1.0],
    anchorXUnits: "fraction",
    anchorYUnits: "fraction",
    src: "Content/Images/OpenLayers/marker_trans.png"
  }),
  zIndex: 100000
});
marker.setStyle(markerStyle);
marker.on("click", function(e) {
  // do something
}, marker);
map.getSource().addFeature(marker);
Run Code Online (Sandbox Code Playgroud)

标记按预期显示,但click事件永远不会触发.我究竟做错了什么?

我应该注意到,在地图级别已经存在与"click"关联的处理程序,即

map.on("click", function(e) {
  // do something
}, marker);
Run Code Online (Sandbox Code Playgroud)

javascript openlayers openlayers-3

15
推荐指数
1
解决办法
4万
查看次数

Bounds如何在OpenLayers 3中运行?

难道概念OpenLayers.Bounds从2.X的OpenLayers仍处于3的OpenLayers存在?它是如何改变的,它的新名称是什么?

openlayers openlayers-3

14
推荐指数
3
解决办法
2万
查看次数