- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在使用 Openlayers 创建一个包含大约 1000 多个点的 map 。目前,当我点击一个点的图标时,该点的描述会出现在弹出窗口中,要退出弹出窗口,我需要再次点击同一个点的图标。有没有办法为此修改代码,以便我可以按下关闭按钮,或者我可以单击 map 上的任意位置,以便再次关闭此弹出窗口?我知道如果我只是使用常规弹出窗口但我使用的是 Openlayers.layer.text 层,则有一种方法。
var pois = new OpenLayers.Layer.Text( "Frequencies",
{ location:"./frequencyrange.txt",
projection: map.displayProjection
});
map.addLayer(pois);
我使用这段代码来添加文本层。在文本文件中将包含以下列:lon lat title description icon iconSize iconOffset。我应该为弹出窗口添加另一列吗?我尝试了一个应该修改弹出窗口大小的列,但它对我不起作用。所以,到目前为止,我无法修改弹出窗口,除了其中的内容。
最佳答案
如果您要刷新具有控件的 map ,请注意不要有多个控件和事件处理程序(请参阅本文末尾的最后注释)。
两个不同的事件可以关闭您的弹出窗口:弹出窗口内的关闭 ('X') 框和当弹出窗口失去焦点时关闭弹出窗口的自动程序。
此伪代码取自带有弹出窗口的功能图,当用户点击任何 MARKER 时会出现弹出窗口。
我在 map 上创建了一个图层(在本例中来自动态 KML 文件,由 php 解析):
var urlKML = 'parseKMLTrack07d.php';
var layerKML = new OpenLayers.Layer.Vector("KML1", {
strategies: [new OpenLayers.Strategy.Fixed()],
protocol: new OpenLayers.Protocol.HTTP({
url: urlKML,
format: new OpenLayers.Format.KML({
extractStyles: true,
extractAttributes: true,
maxDepth: 2
})
})
});
然后我创建一个选择控件,我称之为“selectStop”,并将 2 个函数关联到事件(当标记被选中和未被选中时):
var selectStop = new OpenLayers.Control.SelectFeature(layerKML,{onSelect: onFeatureSelect, onUnselect: onFeatureUnselect});
layerKML.events.on({
"featureselected": onFeatureSelect,
"featureunselected": onFeatureUnselect
});
map.addControl(selectStop);
selectStop.activate();
这两个函数用于当 MARKER 被选中或未被选中时
function onFeatureSelect(event) {
var feature = event.feature;
var content = feature.attributes.name + '<br/>'+feature.attributes.description;
popup = new OpenLayers.Popup.FramedCloud("chicken",
feature.geometry.getBounds().getCenterLonLat(),
new OpenLayers.Size(100,100),
content,
null, true, onFeatureUnselect);
feature.popup = popup;
map.addPopup(popup);
// GLOBAL variable, in case popup is destroyed by clicking CLOSE box
lastfeature = feature;
}
function onFeatureUnselect(event) {
var feature = lastfeature;
if(feature.popup) {
map.removePopup(feature.popup);
feature.popup.destroy();
delete feature.popup;
}
}
请注意,在 onFeatureSelect 函数中,我创建了一个名为“lastfeature”的全局变量。我这样做的原因是,我的 onFeatureUnselect 将用于销毁弹出窗口,以防它未被选择或单击了关闭框。
如果我没有将该功能保存为全局变量,我将不得不分别处理取消选择和关闭框单击,因为导致每个事件的事件是不同的。
为了在弹出窗口中创建关闭框,我将倒数第二个参数(在 onFeatureSelect 函数的弹出声明中)设置为 TRUE,并将 onFeatureUnselect 命名为关闭框的回调函数:
popup = new OpenLayers.Popup.FramedCloud("chicken",
feature.geometry.getBounds().getCenterLonLat(),
new OpenLayers.Size(100,100),
content,
null, true, onFeatureUnselect);
最后注意:如果您在图层上使用刷新,请注意不要复制您的处理程序。在这种情况下,当您的 javascript 启动时,创建一个变量“id1”来保存您的 selectStop 控件 ID。在创建新的控件和处理程序之前检查它是否存在。像这样:
if (id1 == '') {
var selectStop = new OpenLayers.Control.SelectFeature(layerKML,{onSelect: onFeatureSelect, onUnselect: onFeatureUnselect});
layerKML.events.on({
"featureselected": onFeatureSelect,
"featureunselected": onFeatureUnselect
});
map.addControl(selectStop);
selectStop.activate();
id1 = selectStop.id;
} else {
selectStop = OpenLayers.Control.SelectFeature(layerKML,{onSelect: onFeatureSelect, onUnselect: onFeatureUnselect});
}
您可以通过在您的 onFeatureSelect 中放置一个警报来检查您是否正在复制您的事件处理程序。如果您单击一个标记并获得多个警报窗口,则说明您有重复的处理程序。你得到的印象是你无法破坏弹出窗口,这是不正确的。你销毁了一个弹出窗口,但你有 N 个相同的弹出窗口(顺便说一句,具有相同的 ID)。
关于javascript - 如何使用 Openlayers 文本层编辑弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9339274/
popup 和 Frame 和 FrameColud 有什么区别? 而且,似乎弹出窗口的方向取决于标记相对于 map 的位置。流行音乐可能在标记上方或下方。 例如: 上图: 下面: 现在,我想知道如何
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引起辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the he
我一直在使用 OpenLayers,我做了一个层树(所有层都是矢量图层),所有这些层都有特征,我想要的是通过选择控件选择这些特征。 我制作了选择功能控件,但问题是当我关闭其中一个图层时(我正在从 ma
关于即将发布的 OpenLayers 6 的快速问题。有谁知道 OpenLayers 5 和 OpenLayers 6 之间的主要区别是什么。我读了一些 here但出现了其他问题: OpenLayer
所以我使用了一个单个矢量图层,我把我所有的: 积分 折线 多边形 这是我的代码: var source = new ol.source.Vector({ wrapX: false }); var ve
我是用 wkt 添加矢量图层的使用以下代码映射的源: var SelectVector = null; for (var i = 0; i < wktarray.length; i++) {
我正在尝试简化我的应用程序,并想知道 OpenLayers 何时物理调用 WMS 服务器?此外,层可见性是否也在调用中起作用? 实例化一个层时会发生吗 var layer = new OpenLaye
对于群集功能,我想在OL3中制作以下样式: 一个正方形,在其顶部,在右上角还有另一个较小的正方形。较大的正方形将保留符号,而较小的正方形将保留聚类要素的数量。 类似于this 有可能实现这一目标吗?在
我正在尝试在 OpenLayers map 上绘制一个代表实体的图标,其中包括一条“速度领导者”,这是一条从图标开始并沿实体移动方向向外绘制的小线段。线的长度表示实体的速度。 我遇到的问题是我希望线的
我正在使用 openlayers,当我从服务器查询 pois 列表时,我想为每个添加到 map 中。 所以我为它们中的每一个都创建了标记,并且我希望在单击标记时打开一个 FrameCloud。 我用这
OpenLayers 2具有非常有用的map.zoomToExtent(extent)功能。 OpenLayers 3中有类似的东西吗?我可以使用source.getExtent()获得感兴趣的范围,
ol5最近发布了,但我仍在使用ol4。他们网站上的所有链接都指向最新的文档,但我需要 4.6.5 的文档。有谁知道它在哪里吗? 最佳答案 https://openlayers.org/en/v4.6.
我想让用户在 map 上添加自定义标记以及每个标记的描述。任何提示、任何教程的链接都会非常有用。 最佳答案 您可以注册一个函数来在 map 上“点击”事件。当用户点击它时,标记会自动添加。 尝试这样的
我对这个 openlayers map 完全感到困惑。即使有很多示例和 wiki,我也找不到如何重用它。我的意思是我想显示我的城市 map ,管理员可以管理,管理员可以添加点和位置,它应该显示在前端。
我对网络制图非常非常陌生。我有一个由 PostGis 数据库的形状文件制作的 OpenLayers map ,有一个矢量图层,它有默认样式(GeoServer SLD),但我想在用户单击刷新按钮时更改
我是 OpenLayers 的新手,我必须开发一个使用它的离线应用程序。我已经下载了 OL 3.7.0 并设置了一个测试 html 文件,该文件通过以下方式加载 OL javascript 文件:
我将我的 openlayer map 集成到一个带有圆角的 div 中。我怎样才能让 map 有圆角?我曾尝试将 border-radius 应用于开发人员工具中的许多 div,但 map 拒绝圆角。
在我们的应用程序中,我们希望从“CanvasMap”上的标记/功能到外部世界(任何接受该类型拖放操作的 HTML 目标)启动 native (HTML) 拖放操作。 想象一下,我们在 CanvasMa
在 Openlayers v2 中,我可以添加如下符号: OpenLayers.Renderer.symbol.pointToIcon = [100, 70, 20, 50, 42, 70, 20,
我在 map 上有一些功能,在我移动它们之后,使用 var point = new OpenLayers.LonLat(newlon, newlat); point.transform(epsg432
我是一名优秀的程序员,十分优秀!