I'm brand new to creating gis map applications and I am trying to get a web project that uses

function init(){
            map = new OpenLayers.Map( 'map' );
            layer = new OpenLayers.Layer.WMS( "OpenLayers WMS", 
                    {layers: 'basic'} );
            map.setCenter(new OpenLayers.LonLat(lon, lat), zoom);
            var featurecollection = {
              "type": "FeatureCollection", 
              "features": [
                {"geometry": {
                    "type": "GeometryCollection", 
                    "geometries": [
                            "type": "LineString", 
                                [[11.0878902207, 45.1602390564], 
                                [15.01953125, 48.1298828125]]
                            "type": "Polygon", 
                                [[[11.0878902207, 45.1602390564], 
                                  [14.931640625, 40.9228515625], 
                                  [0.8251953125, 41.0986328125], 
                                  [7.63671875, 48.96484375], 
                                  [11.0878902207, 45.1602390564]]]
                            "coordinates":[15.87646484375, 44.1748046875]
                "type": "Feature", 
                "properties": {}}
           var geojson_format = new OpenLayers.Format.GeoJSON();
           var vector_layer = new OpenLayers.Layer.Vector(); 


I've included the OpenLayers.js with the img and theme folders under the WEB-IMF. When I run it only the text shows, not the map. Is there something I'm missing.

  • @dariapra answer goes in the right direction, but I think you might also have syntax errors in your page. Start with one of the OpenLayers examples and work your way up from there. – unicoletti Dec 7 '12 at 17:26

It seems that you are not calling the function init().

A quick and dirty method to accomplish it would be calling this function from the HTML tag body:

<body onload="javascript: init();">

If you are using JavaScript frameworks like Prototype or JQuery you can call this function just after the DOM is loaded:

document.observe('dom:loaded', init);   // Prototype framework
$(document).ready(init);                // JQuery framework
  • I added the <body onload="javascript: init();"> and the map didn't show up. Is there something else like geojson I need to install. – Mike Dec 7 '12 at 17:42
  • As said by unicoletti, the first step would be checking that there are no syntax errors or of any other kind. In case a needed component has not been loaded, then it would trigger an error message. – dariapra Dec 7 '12 at 18:09
  • I can get it to show a google map but the coordinates feature is not working. I tried it inside of an installed geoserver instance and the coordinates features didn't work either. – Mike Dec 7 '12 at 20:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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