Hello all,

I'm currently implementing a new element in OpenLayers: openlayers.
As this stuff is pretty new for me, I'm still learning to do it properly.

Branch deleted. You can see my work in this branch (1895530): http://drupalcode.org/project/openlayers.git/tree/refs/heads/1895530

Example of code:

$form['map'] = array(
  '#type' => 'openlayers',
  '#map' => 'default'
);

This will allow you to use OpenLayers in forms too and we'll try to use it everywhere in the module instead of using:

$form['map'] = array(
  '#markup' => theme('openlayers', array($map))'
);

The Geofield module will be able to use it too through the widget and formatters.

Why doing this

  1. Loading map in Ajax will be easier and faster
  2. The code will be lighter and easier to read
  3. The upgrade to D8 will probably be easier
  4. Less code to maintain in other module like Geofield

Current status

Displaying maps is working.
I also succeeded to create an element where you can draw feature and get the WKT in the field, but it will be for later, that code is mainly taken from GeoField.

TODO

  • DONE. Load behaviors and layer types js through the element #attached key.
  • DONE. Automatically load JS and CSS files related to layers and behaviors without specifying them.
  • Find a way to automatically load external JS files in AJAX and wait before they are loaded, for example for Google Maps.

Current problems

  1. If you go to admin/structure/openlayers, you'll see the new map preview using AJAX. It works for every kind of map who do not require external JS to be loaded. For example, if your default map is 'default', then switch to 'Example Google Map', it will fail with: ReferenceError: google is not defined because the Google JS file is not loaded. If you submit the page, you'll be able to see the Google Map just after.
  2. OpenLayers is bundled with a module for views and it's implementing a new display style. This display style is using the same template as the element. ('register theme' set to FALSE in the plugin definition).Everything works, except that in the Views UI, when I go in 'Theme: information', it says in red: Style output: openlayers.tpl.php (File not found, in folder ./)
    But the rendering works !
    Do you have any idea on how to get rid of the error ? Is this OpenLayers or Views related ?
    It looks like it's a Views bug/problem, so problem gone.

Comments

Pol’s picture

Issue summary: View changes

Updated issue summary.

Pol’s picture

Issue summary: View changes

Updated issue summary.

Pol’s picture

Issue summary: View changes

Updated issue summary.

Pol’s picture

Issue summary: View changes

Updated issue summary.

Pol’s picture

Issue summary: View changes

Updates.

Pol’s picture

Issue summary: View changes

Updated issue summary.

Pol’s picture

Issue summary: View changes

Updated issue summary.

FranciscoLuz’s picture

So, from your TODO list, ajax loading is not working, specially with Google Layers, at this point in time, is it right?

FranciscoLuz’s picture

Please forgive me if I am being too naive, wouldn't it work if you tried to load all the necessary external JS at the hook_init() or hook_boot()?

Pol’s picture

Francisco: Yes it will work if I load all external JS in a hook_init() but I don't think that this would be a solution because it will load them all the time, even if there is no map to display !

FranciscoLuz’s picture

Right I see.

You probably have already thought of it but I need to ask you anyway.

How about having a function or method for loading the external JS that I can call before programatically loading a OL Map or a OL view?

I could pass some arguments along for specifying what kind of map layer I am interested in, google maps for instance.

Pol’s picture

Status: Active » Closed (duplicate)
Pol’s picture

Issue summary: View changes

Updated issue summary.

Pol’s picture

Issue summary: View changes

Updated issue summary.

Pol’s picture

Issue summary: View changes

Updates