Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a piece of code that takes a map layer and places a vector layer on top of that. Currently, I'm just trying to place a few points on top of the map, unsuccessfully.

I managed to place 1 point but it would only stay in the middle of the map.

I took all the html code and simplified it. Here is the code for the whole page, it's standalone, so you can just copy paste into a new html page and see the problem.

<body onload="initMapp()">
    <div id="mapp" class="smallmap"></div>
  <script src=""></script>
  <script src=""></script>
        //      $(document).ready(function() {
        //          initMapp();
        //      })

        var lon = 0;
        var lat = 0;
        var zoom = 3    ;

        var map; //complex object of type OpenLayers.Map

        function initMapp() {

            map = new OpenLayers.Map("mapp", {
                units : 'm'

            layerMapnik = new OpenLayers.Layer.OSM.Mapnik("Mapnik");


            var switcherControl = new OpenLayers.Control.LayerSwitcher();

            if (!map.getCenter()) {
                var lonLat = new OpenLayers.LonLat(lon, lat).transform(new OpenLayers.Projection("EPSG:4326"), map
                map.setCenter(lonLat, zoom);

        function addPointToMap(pMap){
            var coordinates = new Array();

            var pointStyle = {externalGraphic: '', graphicHeight: 20, graphicWidth: 20}

            // Make Point
            coordinates.push(new OpenLayers.Geometry.Point(33, 33));
            var pointsGeometry = new OpenLayers.Geometry.MultiPoint(coordinates);
            var pointFeature =  new OpenLayers.Feature.Vector(pointsGeometry, null, pointStyle);

            // Layer
            var pointsLayer = new OpenLayers.Layer.Vector("Points Layer");
.smallmap {
    height: 80%;
    width: 80%;

To reiterate, how do you place the point at some location on the map? (I have lon/lat)



Just to make it easier for readers in the future. The answer which is marked as the solution below only hints at the full solution. The 'full solution' is to modify the point creation code as such:

// Make Point
coordinates.push(new OpenLayers.Geometry.Point(33, 33).transform(new OpenLayers.Projection("EPSG:4326"), map
share|improve this question
Hi @Ben, welcome to our site! I removed the "newbie" from your title because questions ought to stand on their own quality; you have done a great job formulating your question and simplifying the code (which is very non-newbie behavior); and you don't seem to be asking for watered-down answers. – whuber Jul 21 '11 at 13:43
@whuber Fair Enough. Thanks. – Ben Jul 21 '11 at 13:44
up vote 6 down vote accepted

Check this similar question: Overlaying lat/lon points on Google layer in OpenLayers. It's for Google Maps but you can just as well use OSM as a background. The rest still applies.

share|improve this answer
Thanks. Through your answer I added the .transform() to the point location and it works – Ben Jul 21 '11 at 13:52

Your Answer


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.