Hi Folks,

I'm a little bit lost inside all the different js functions, drupal.behaviours, js-helper-functions and so on of the OpenLayers-Module (6.x-2.0-alpha10 on Drupal 6). I have the module running, users can set points to the map with their mouse, Drupal is saving the stuff and that part works quite well (take a look at www.geomnesia.de).

Now I want to add the possibility, that users can set the point by typing/pasting in the langitude longitude by themselves. So I added (that's running on a local test-system it's not online now) two fields to the form via jquery for the input and now want to add the point at that coordinates via js. But how can I do that, the docu says nothing about that.

For instance:

Drupal.openlayers.addFeatures("GEOMETRYCOLLECTION(POINT(" + lonIn.toFixed(12) + " " + latIn.toFixed(12) + "))" );

or

Drupal.behaviors.openlayers_behavior_drawfeatures("GEOMETRYCOLLECTION(POINT(" + lonIn.toFixed(12) + " " + latIn.toFixed(12) + "))" ); (lonIn and latIn being the values, the user entered into the fields) inside my js does nothing.

Which function is called in OpenLayers or the Drupal.openlayers, when a user is clicking on the map and setting the point? And how can I access this function, so that my OpenLayersInputMap thinks the user has set the point and puts it on the position the user has entered?

Would be nice if someone could give a hint how to do that or has done something similiar and can help me with this problem.

Regards Paddy

Comments

pgr1973’s picture

Priority: Normal » Major

No idea anybody?

pgr1973’s picture

After quite some trial&error I got a solution:

[...]
  // lebende OpenLayers Karte aus dem jQuery.data Teil holen 
  var jdol = $('#openlayers-cck-widget-map-field_gp').data('openlayers'); 
  
  // Kartenzentrum auf eingegeben Werte und Zoomstufe 15 setzen 
  jdol.openlayers.setCenter(new OpenLayers.LonLat(lonIn, latIn).transform(jdol.openlayers.displayProjection, jdol.openlayers.projection), 15); 
  
  // Feature aus den eingegebenen Werten bauen und auf den Featurelayer hinzufügen 
  var inputFeature = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(lonIn.toFixed(12), latIn.toFixed(12)).transform(jdol.openlayers.displayProjection, jdol.openlayers.projection)); 
  var featuresLayer = jdol.openlayers.layers[3]; 
  featuresLayer.addFeatures(inputFeature); 
[...] 

This inserts an input point on the input-map at the positions latIn/lonIn (values taken from the input-form, the user has entered them). '#openlayers-cck-widget-map-field_gp' is dependent on the content-type one has created inside drupal (has another id with different content-type and different field-name) and 'layers[3]' from 'jdol.openlayers.layers[3]' is the layer with the drupalID 'openlayers_drawfeatures_layer' but I couldn't get it via the drupalID, so I chose the absolute way. Which may be different depending on the configuration of the input-map of the drupal openlayers-module.

Regards Paddy

zzolo’s picture

Priority: Major » Normal

Hi @pgr1973. Glad that you figured it out. Is this good enough for you? Should this issue be closed?

pgr1973’s picture

Should this issue be closed?

Yes, I think it can be closed. At least I got my stuff running now (http://gmna.de and klick on "Koordinaten"
at the bottom left of the Map; Longitude and Latitude are the two input fields that I use for setting the
point on the input-map; the whole JS sits in /sites/all/themes/gmna/js_gmna_gp_form.js where I also
programmed a solution to prevent users from submitting an empty WKT-Field which is a different
issue of the OpenLayers Module.).
Maybe there are more elegant or easier ways to achieve this (which I really would like to know), but
for now the problem is solved. ;-)

Regards Paddy

pgr1973’s picture

Status: Active » Closed (fixed)
victor0909’s picture

Hello!

I have more or less the same problem: I want to set a feature representing a point, but I need that this point will be stored in database, after saving the node.

I'm using Drupal 7 and openlayers 7.x-2.0, and I couldn't see the "openlayers_drawfeatures_layer". I would want to know in which layer I have to add the new feature representing the point, or how to do the storage of the point (as if the user use the pencil in the top-right corner).

Any help?!

Thanks a lot.