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'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", 
                    "http://vmap0.tiles.osgeo.org/wms/vmap0",
                    {layers: 'basic'} );
            map.addLayer(layer);
            map.setCenter(new OpenLayers.LonLat(lon, lat), zoom);
            var featurecollection = {
              "type": "FeatureCollection", 
              "features": [
                {"geometry": {
                    "type": "GeometryCollection", 
                    "geometries": [
                        {
                            "type": "LineString", 
                            "coordinates": 
                                [[11.0878902207, 45.1602390564], 
                                [15.01953125, 48.1298828125]]
                        }, 
                        {
                            "type": "Polygon", 
                            "coordinates": 
                                [[[11.0878902207, 45.1602390564], 
                                  [14.931640625, 40.9228515625], 
                                  [0.8251953125, 41.0986328125], 
                                  [7.63671875, 48.96484375], 
                                  [11.0878902207, 45.1602390564]]]
                        },
                        {
                            "type":"Point", 
                            "coordinates":[15.87646484375, 44.1748046875]
                        }
                    ]
                }, 
                "type": "Feature", 
                "properties": {}}
              ]
           };
           var geojson_format = new OpenLayers.Format.GeoJSON();
           var vector_layer = new OpenLayers.Layer.Vector(); 
           map.addLayer(vector_layer);
           vector_layer.addFeatures(geojson_format.read(featurecollection));

        }

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.

share|improve this question
    
@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

1 Answer 1

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
share|improve this answer
    
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

 
discard

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

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