简体   繁体   English

OpenLayers点几何永远不会调整大小

[英]OpenLayers Point Geometry never resizes

My website contains an OpenStreetMaps. 我的网站包含一个OpenStreetMaps。 I use OpenLayers to place a Geometry.Point on top of a city. 我使用OpenLayers将Geometry.Point放置在城市顶部。

A button allows the user to resize this point, but it is never resized and I can't understand why. 一个按钮允许用户调整此点的大小,但是它从未调整大小,我不明白为什么。

Here is my code : 这是我的代码:

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();
};

Can you help me to figure it out ? 你能帮我弄清楚吗?

Thanks 谢谢

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

I haven't worked with OpenLayers much, so take everything here with a grain of salt. 我与OpenLayers的合作不多,所以在这里花点盐吃。 I was looking at this example ( http://dev.openlayers.org/releases/OpenLayers-2.12/examples/resize-features.html ), and I think the geometry resize does something different than what you're intending. 我正在看这个示例( http://dev.openlayers.org/releases/OpenLayers-2.12/examples/resize-features.html ),我认为调整几何尺寸的功能与您的预期有所不同。 I think what you really want to change is the style of the point. 我认为您真正想要改变的是风格。 I've modified your fiddle as an example, at http://jsfiddle.net/MLundin617/39KE5/2/ . 我已经在http://jsfiddle.net/MLundin617/39KE5/2/上修改了您的小提琴作为示例。 It's not complete, as the click also manages to change the color of the point, but I believe it's closer to what you're looking for. 这还不完整,因为单击也可以改变该点的颜色,但我相信它离您要寻找的更近。

This is the major change: 这是主要的更改:

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

(Also, in your jsFiddle, you were referencing the incorrect form element, so the onclick couldn't be defined.) (此外,在您的jsFiddle中,您引用的表单元素不正确,因此无法定义onclick。)

Let me know if that helps. 让我知道是否有帮助。 Curious to see any other answers as well. 很好奇也看到其他答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM