簡體   English   中英

OpenLayers點幾何永遠不會調整大小

[英]OpenLayers Point Geometry never resizes

我的網站包含一個OpenStreetMaps。 我使用OpenLayers將Geometry.Point放置在城市頂部。

一個按鈕允許用戶調整此點的大小,但是它從未調整大小,我不明白為什么。

這是我的代碼:

var button = document.myform.btClear,
    map = new OpenLayers.Map("map_element", {}),
    osm = new OpenLayers.Layer.OSM(),
    vectors = new OpenLayers.Layer.Vector(),
    fromProjection = new OpenLayers.Projection("EPSG:4326"),
    toProjection = new OpenLayers.Projection("EPSG:900913"),
    position = new OpenLayers.LonLat(6.9673223,50.9572449).transform(fromProjection, toProjection),
    point =  new OpenLayers.Geometry.Point(6.9673223,50.9572449).transform(fromProjection, toProjection);

map.addLayer(osm);
map.addLayer(vectors);
map.setCenter(position, 5);

pointFeature = new OpenLayers.Feature.Vector(point);
vectors.addFeatures([pointFeature]);

button.onclick = function() {
    vectors.features[0].geometry.resize(1.5, point);
    vectors.redraw();
};

你能幫我弄清楚嗎?

謝謝

http://jsfiddle.net/39KE5/1/

我與OpenLayers的合作不多,所以在這里花點鹽吃。 我正在看這個示例( http://dev.openlayers.org/releases/OpenLayers-2.12/examples/resize-features.html ),我認為調整幾何尺寸的功能與您的預期有所不同。 我認為您真正想要改變的是風格。 我已經在http://jsfiddle.net/MLundin617/39KE5/2/上修改了您的小提琴作為示例。 這還不完整,因為單擊也可以改變該點的顏色,但我相信它離您要尋找的更近。

這是主要的更改:

radius = 2
button.onclick = function() {
    radius = radius * 1.5
    vectors.features[0].style = {pointRadius: radius}
    vectors.redraw();
};

(此外,在您的jsFiddle中,您引用的表單元素不正確,因此無法定義onclick。)

讓我知道是否有幫助。 很好奇也看到其他答案。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM