1
votes

i am using openstreetmap in my project, earlier i used google map in this project but the request limit is lower than what my client needs and he can't afford what google takes to increase the request limit so i had to switch to openstreetmap, i am searching a lot in openstreetmap documentation but not getting the clue that how to open a marker from a link which is outside the map, can you please help me in solving this. This will be a huge help for me.

Thanks in advance

Hey, I solved it myself, this is the code to open popup of marker from outside the map.

       function openMarker(id,lon,lat,html) 
       {
        jQuery(".olPopup").remove();
        marklonLat = new OpenLayers.LonLat(lon,lat)
          .transform(
            new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984
            map.getProjectionObject() // to Spherical Mercator Projection
        );

        var size = new OpenLayers.Size(200,200);
        popup = new OpenLayers.Popup(id,marklonLat,size,html,true,'' , {keepInMap: true });

        map.addPopup(popup);
    }

jQuery(".olPopup").remove(); -- This will close all the popup's on the map before you open a new popup

html -- this is the content which will be there in the popup

1
openstreetmap is just the data. You must be using something else to draw the map, a web mapping framework like OpenLayers, or Leaflet. Which? Try not to confuse the data with the mapping framework. With Google's maps the data and the mapping framework are very tightly coupled.Spacedman
I am using OpenLayers to draw the map...Ravinder Singh
So now rewrite your question. You want a link (an HTML A tag?) that when people click it shows a marker at some location (decided how?) on the map? Is that it?Spacedman
Hey, i solved it myself, thanks for showing interest in helping me.Ravinder Singh
Now i want to do a big thing, which i never did before, here's what i am doing, I am showing the list of persons on the left, and on the right, i am showing their addresses on the map, ok Now i want to do this, whenever someone zoom-in or zoom-out the map, it updates the list on the left, it should only show the persons on the left, which are visible on map for that zoom, so in this way, it will always show those persons on the left who the user can see on the map. do you think it is there in the openLayer API?Ravinder Singh

1 Answers

0
votes

Just try this :

Pass unique id of the marker, longitude, latitude and html which you want to show in tooltip.

function openMarker(id,lon,lat,html) 
    {
        jQuery(".olPopup").remove();
        marklonLat = new OpenLayers.LonLat(lon,lat)
          .transform(
            new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984
            map.getProjectionObject() // to Spherical Mercator Projection
        );

    var size = new OpenLayers.Size(200,200);
    popup = new OpenLayers.Popup(id,marklonLat,size,strhtml,true,'' , {keepInMap: true });

    map.addPopup(popup);
}