Closed (fixed)
Project:
Openlayers
Version:
7.x-2.0-beta1
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
24 Jul 2012 at 13:52 UTC
Updated:
26 Dec 2012 at 20:01 UTC
hi,
My question is not directly about ol module, but I use it in other part.
I try by creating a module to generate a page with a simple map(drupal7 firefox or opera on debian squeeze).
I have no javascript errors, no conflict, but the page don't load the map.
why ? please see below the module code and please tell me where I am wrong :
<?php
// $Id$
/**
* @file
*/
/**
* Implements hook_menu().
*/
function tests_menu() {
$items['tests'] = array(
'title' => 'Tests',
'description' => 'tests',
'page callback' => 'tests_inserts',
'access callback' => TRUE,
);
return $items;
}
/**
*
*/
function tests_inserts() {
drupal_add_library('tests', 'openlayers');
drupal_add_js("window.onload = init;var map;var center;function init(){var map = new OpenLayers.Map('container'); map.addLayer( new OpenLayers.Layer.OSM() );var center = new OpenLayers.LonLat(30000,5800000);map.setCenter(center, 6);alert('testinit2')}",'inline');
$output = '';
$output .= '<div style="width:100%; height:100%; border: 1px blue solid;">TESTS</div>';
$output .= '<div id="container" style="border: 1px red solid;"></div>';
return $output;
}
/**
* Implements hook_library().
*/
function tests_library() {
$libraries['openlayers'] = array(
'title' => 'OpenLayers',
'website' => 'http://openlayers.org/',
'version' => '2.11',
'js' => array(
drupal_get_path('module', 'tests') . '/OpenLayers.js' => array(),
),
);
return $libraries;
}
/**
* Implements hook_library_alter().
*/
function tests_library_alter(&$libraries, $module) {
return;
}
Comments
Comment #1
zzolo commentedHi @sayayin. You are not even using this module at all. Please see the API for this module to add maps. This module is based around map configurations and displaying that.
If you are looking to manually create an OpenLayers map, this module is way overkill.
Comment #2
sayayin commentedHi @zzolo
Please tell me how I can include a map in my module, and in a form, using the OL API.
For example, in your book, Mapping Drupal, p.82 (I am a registered buyer), you show us an exportable map code.
How I can inject it in the code of my module to display this map?
Comment #3
zzolo commentedThe basic steps are:
1) Make a map in the interface (your exportable).
2) Call openlayers_load_map($map_name); (or something like that)
Please see the documentation that comes with the module:
http://drupalcode.org/project/openlayers.git/blob/refs/heads/7.x-2.x:/do...
http://drupalcode.org/project/openlayers.git/blob/refs/heads/7.x-2.x:/do...
http://drupalcode.org/project/openlayers.git/blob/refs/heads/7.x-2.x:/op...
Comment #4
sayayin commented@zzolo : sorry, really sorry but I want & I need to perform that simple operation :
- I create the map with center and zoom,
- I add in my module code
;
but apache's log tell me
"Error: Call to undefined function openlayers_load_map() ".
I am stupid surely but please give me a path to perform it.
Comment #5
steinmb commentedYou need to tell PHP what code that define function openlayers_load_map() else nothing works.
Comment #6
akalam commentedThis worked for me:
http://trac.osgeo.org/openlayers/wiki/Release/2.11/GoogleMaps37
so, I added at the end of my views-view--page-view-name.tpl.php:
Comment #7
Viveks commentedI have two view for the openlayers map.
this is working fine on the front page view , but it is not working in the inner page , so What can i do, in it pls help me!!!
Comment #8
polRead links in comment #3.