Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I've set up a simple web application where users can draw vectors (points, lines and polygons) using OpenLayers.

Actually digitizing is handled controls (OpenLayers.Control.DrawFeature) and I'm using featureadded, afterfeaturemodified, featureselected and featureunselected listeners to save edits in the database.

I want to be able to manually add features, and insertXY() method of OpenLayers.Control.DrawFeature (full reference: http://dev.openlayers.org/docs/files/OpenLayers/Control/DrawFeature-js.html#OpenLayers.Control.DrawFeature.insertXY) to add x and y values, manually or using browser geolocation. This is working fine on PATH and POLYGON controls, but it's not working as expected on POINT control. In fact it's not working at all.

When I fire insertXY method no point is added on the map and no callback function is called. Am I missing something? I tried also to call the finishSketch() method after insertXY(), but I get the following error: TypeError: this.handler.finishGeometry is not a function

Maybe insertXY does not work with points?

share|improve this question

1 Answer 1

up vote 0 down vote accepted

@bradypus, you dont need to use OpenLayers.Handler.Point with drawing point feature to the map. doesnt vector.addFeatures func. work for you? beside this you can check out editing methods here. you can see info about insertXY there.

The control.insertXY method inserts a point at the given map coordinates (x, y) immediately prior to the most recent point (under the mouse). The control.insertDeltaXY method inserts a point at the given offset values (dx, dy) from the previously added point.

The control.finishSketch method completes the current sketch without adding the point under the user's mouse. This allows a sketch to be finished without a double-click. The control.cancel method discards the current sketch and leaves the control active. The control.insertXY method may be called before any points are digitized manually. The other methods have no effect until at least one point has been added to the sketch.

full code for adding point to vector layer:

var point = new OpenLayers.Geometry.Point(x,y);
var point_ft = new OpenLayers.Feature.Vector(point, null, null);
vectorLayer.addFeatures(point_ft);

i hope it helps you...

share|improve this answer
    
Thank you @Aragon for your helpful answer. vector.addFeatures() works fine for points. I used handler for a faster digitizing and for switching easily throw different features (point, lines, polygons). The example you quoted above also uses Controls and Handles. I changed my code to use vector.addFeatures() if the draw points control is selected, and manual (or browser location) input is chosen for coordinates. Otherwise Controls and handles do the job. Do you think there is a better way to manage this? –  bradypus Apr 11 '13 at 5:57
    
that is the best method come to my mind. good luck :) –  Aragon Apr 11 '13 at 7:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.