简体   繁体   中英

OpenLayers Point Geometry never resizes

My website contains an OpenStreetMaps. I use OpenLayers to place a Geometry.Point on top of a city.

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/

I haven't worked with OpenLayers much, so take everything here with a grain of salt. 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. 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/ . 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.)

Let me know if that helps. Curious to see any other answers as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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