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 am setting a form (for multiple addresses) where users can click on map by creating a marker for each address they want to input. Users can only create one marker per address and once the marker has been created I need to get nearest address and update the address field (form input) with that address.

I am able to activate the marker drawing control but how can I make sure that user only creates one marker (not more) per address and then take that calculated address and update original text field (which fired the event) with new information.

This is what I have so far:

<form name="xxxx">

POI 1: <input type="text">
<a href="#" onClick="edrawMarker(event)"> click here to select address on map</a>
POI 2: <input type="text">
<a href="#" onClick="edrawMarker(event)"> click here to select address on map</a>


</form>
<a href="#"> Add more poi's </a>

Here's the javascript code

poi_markers = new OpenLayers.Layer.Vector('markers',{styleMap:markerStyleMap});
poi_marker_control = new openLayers.Control.DrawFeature(poi_markers,OpenLayers.Handler.Point);  


function e_drawPOIMarker(evt){

        route_markers.events.register('featureadded',poi_markers,function(evt){
         {
         //get JSON response
                     var place_name = getGeoName(evt.feature.geometry)  
                     poi_marker_control.deactivate();
                            //Somehow find the id of the text field which fired original event and update its contents with data returned in place name.
        }
    });
        poi_marker_control.activate();  
    }

Basically I have to capture co-ods of locations clicked by users. Each field (in form) should only allow 1 marker. Suppose if I have unknown numbers of poi address fields (which users can add dynamically) whats the best way of capturing coods and then updating original fields with that information.

At the moment I can activate and deactivate controls and allow users to create marker(s). but how can I know which marker belongs to which text field ?

Thanks.

share|improve this question

1 Answer 1

I would probably add a token to the *e_drawPOIMarker()* function. When called, just test if a marker having the passed token already exists or not.

share|improve this answer

Your Answer

 
discard

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