[英]OpenLayers: Can't select feature after clickout
我正在嘗試一個簡單的測試,其中我有一個基本圖像,頂部有可拖動的功能。 這些點特征具有相關的外部圖形(我更喜歡使用具有相關圖形的多邊形,但這是另一個問題)。
我有一個完美的懸停控件。 我也有一個幾乎可以工作的選擇控件。 但是,一旦點擊一下,我就無法重新選擇一個功能。 同樣,如果我在嘗試選擇一個功能之前單擊功能外的任何位置,我就無法選擇功能。
我希望這很清楚 - 但如果不是那么這個例子應該是(你也可以看到整個代碼) http://sigfrid.co.uk/oltest/simple.html
我會把我認為是下面代碼的關鍵部分......
創建一個地圖
var map = new OpenLayers.Map({
div:'map',
});
添加基礎層
var base = new OpenLayers.Layer.Image(
'Base level',
'img/base.png',
new OpenLayers.Bounds(-1000, -1000, 1000, 1000),
new OpenLayers.Size(864,864),
options
);
map.addLayer(base);
添加樣式
var markerStyleMap = new OpenLayers.StyleMap
({
"default": new OpenLayers.Style(template, {context: context}),
"hover": new OpenLayers.Style ({graphicOpacity:0.5}),
"select": new OpenLayers.Style ({graphicOpacity:0.1})});
添加積分
pt1 = new OpenLayers.Geometry.Point(0,0);
pt1Feature = new OpenLayers.Feature.Vector(pt1);
...
markerLayer.addFeatures([pt1Feature,pt2Feature,pt3Feature]);
為不同的標記圖像添加唯一查找
var lookup = {
"f1": {externalGraphic:"img/f1.png"},
"f2": {externalGraphic:"img/f2.png"},
"f3": {externalGraphic:"img/f3.png"},
}
markerStyleMap.addUniqueValueRules("default", "type", lookup);
markerLayer.styleMap = markerStyleMap;
markerLayer.features[0].attributes.type = "f1";
...
添加控件
var dragControl = new OpenLayers.Control.DragFeature(markerLayer)
map.addControl(dragControl);
dragControl.activate();
var highlightCtrl = new OpenLayers.Control.SelectFeature(markerLayer, {
hover: true,
highlightOnly: true,
renderIntent: "hover",
});
map.addControl(highlightCtrl);
highlightCtrl.activate();
var selectCtrl = new OpenLayers.Control.SelectFeature(markerLayer, {
clickout: true,
renderIntent: "select",
});
map.addControl(selectCtrl);
selectCtrl.activate();
謝謝你的幫助,
缺口
結果拖動和選擇不兼容。 但是,有一些工作,如
http://fastr.wordpress.com/2012/04/17/openlayers-selectfeature-where-did-i-clicked-2/
雖然這確實增加了一些事件問題......
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.