duanbi3151 2012-04-09 07:06
浏览 190
已采纳

如何在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

  • 写回答

1条回答 默认 最新

  • dtxooq1020 2012-04-22 08:19
    关注

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样