Ravinder Singh
Ravinder Singh

Reputation: 3133

How to open a marker from outside the map in openstreetmap?

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

Upvotes: 1

Views: 1490

Answers (1)

Ravinder Singh
Ravinder Singh

Reputation: 3133

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); }

Upvotes: 0

Related Questions