This is a static archive of our old OpenStreetMap Help Site. Please post any new questions and answers at community.osm.org.

[closed] How to add three markers to existing javascript code

0

Hi All

I am new to this and need to complete an assignment, i am unable to add three additional markers into this code, i found the below info but it still doesnt help me.

//ADD LAYER MARKERS var markers = new OpenLayers.Layer.Markers( "Markers" ); map.addLayer(markers); markers.addMarker(new OpenLayers.Marker(lonLat,icon));

Below is the code, i have tried to copy "var lonLat = new OpenLayers.LonLat( 13.0 ,47.0 ) //define a new location with these coordinates in WGS84" with new lat lon 13.1, 47.8 but that doesnt work.

WHAT AM I DOING WRONG, PLEASE HELP ME ....

 <!-- COPYRIGHT: http://wiki.openstreetmap.org -->
    <html>
    <head>
    <title>OpenLayers Demo</title>
    <script src="http://www.openlayers.org/api/OpenLayers.js"></script>
    <script>
    function init() {
    map = new OpenLayers.Map("mapdiv"); //create a new map
    var mapnik = new OpenLayers.Layer.OSM(); //add an OpenStreetMap layer to have some data in the mapview
    map.addLayer(mapnik); //add the OSM layer to the map
    var vectorLayer = new OpenLayers.Layer.Vector // Overlay new line
    var feature = new OpenLayers.Feature.Vector // new line
    var markers = new OpenLayers.Layer.Markers( "Markers" ); //add a layer where markers can be put
    map.addLayer(markers); //add the markers layer to the current map
    var lonLat = new OpenLayers.LonLat( 13.0 ,47.0 ) //define a new location with these coordinates in WGS84
    .transform( //transform the location to the coordinate system of our OpenLayers map
    new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984
    map.getProjectionObject() // to Spherical Mercator Projection
    );
    markers.addMarker(new OpenLayers.Marker(lonLat, icon)); //add the newly created marker to the markers layer
    map.setCenter(lonLat, 13); // Use maker to center the map above and set zoom level to 15
    }
    </script>
    </head>
    <body onload="init();">
    <div style="width: 100%; height: 100%;" id="mapdiv"></div>
    ---Here I describe how I solved the assignment---
    </body>
    </html>

asked 26 Feb '13, 07:48

Lizzy7's gravatar image

Lizzy7
11112
accept rate: 0%

closed 26 Feb '13, 08:04

Frederik%20Ramm's gravatar image

Frederik Ramm ♦
82.5k927201273

The question has been closed for the following reason “Question is off-topic or not relevant” by Frederik Ramm 26 Feb ‘13, 08:04


One Answer:

2

This is not an OpenLayers support forum. See www.openlayers.org for help on OpenLayers. There's a multi-marker example here: http://openlayers.org/dev/examples/markers.html

answered 26 Feb '13, 08:03

Frederik%20Ramm's gravatar image

Frederik Ramm ♦
82.5k927201273
accept rate: 23%

Source code available on GitHub .