日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

OpenLayers 动态添加标记(Marker)和信息窗(Popup)

發布時間:2023/11/27 生活经验 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 OpenLayers 动态添加标记(Marker)和信息窗(Popup) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

方式一:使用marker方式

1、在地圖上添加標記圖層

var markers =newOpenLayers.Layer.Markers("Markers");
map.addLayer(markers);//地圖初始化添加

2、動態添加標記和Popup方法:

//add map initial method
map.events.register('click', this, function(e) {var LonLat=new OpenLayers.getLonLatFromPixel(e.xy);autoAddMarker(LontLat);OpenLayers.Event.stop(e); });//others methodfunction getIcon(){var size =newOpenLayers.Size(21,25);var offset =newOpenLayers.Pixel(-(size.w/2),-size.h);var icon =newOpenLayers.Icon('http://www.openlayers.org/dev/img/marker.png', size, offset);return icon;}function createPopup(marker,LonLat){var size=new OpenLayers.Size(200,120);var html="Lon:"+LonLat.Lon+"</br>Lat:"+LonLat.Lat;var popup=new OpenLayers.Popup(marker,LonLat,size,html,true);}function autoAddMarker(LontLat){var marker=newOpenLayers.Marker(LonLat,getIcon);var popup=createPopup(marker,LonLat);marker.events.register('click',this,function(){map.addPopup(popup,true);popup.show();});markers.addMarker(marker);}

3、事件觸發,點擊地圖獲得marker 及其信息窗口。

如果click不是OpenLayers.Events的register方法,就需要activate Click方法。

方式二:使用feature本身提供的特性

 //顯示矢量信息'pointVectorLayer':new OpenLayers.Layer.Vector("加點圖層", {eventListeners:{'featureselected':function(evt){var feature = evt.feature;if(myPopup) this.map.removePopup(myPopup);myPopup=createPopup(feature.point);feature.popup = myPopup;this.map.addPopup(myPopup);},'featureunselected':function(evt){var feature = evt.feature;this.map.removePopup(feature.popup);feature.popup.destroy();feature.popup = null;}}}),

?直接注冊矢量層的事件,推薦使用第二種方式,它可以與整體彈出框的樣式保持一致,都是popup類型的。

轉載于:https://www.cnblogs.com/boonya/archive/2012/03/18/2404731.html

總結

以上是生活随笔為你收集整理的OpenLayers 动态添加标记(Marker)和信息窗(Popup)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。