简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM