日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

Google Maps實現右鍵菜單

系統 2008 0

Google Maps實現右鍵菜單

??????? 最近在做公司項目( www.youmonitor.us ?它可以幫助你檢測你的網站的穩定性,如果你的網站當了,它會給你發警報,而且是免費的,有興趣的朋友可以去看看,不是廣告,希望版主不要刪我的帖子 )的第二版,需要用到Google Maps的右鍵菜單(類似google maps官方網站的右鍵菜單功能 http://maps.google.com/ ),但是好像google的官方API上面沒有這種示例,于是求助google的搜索引擎,找到了這篇文章: http://www.econym.demon.co.uk/googlemaps/context.htm ,發現google maps自己有一個鼠標右鍵事件:singlerightclick,文章我就不翻譯了,英文不好的朋友可以直接看它的代碼: http://www.econym.demon.co.uk/googlemaps/examples/context.htm 。但是這篇文章還有一個美中不足,就是我希望在用戶點擊了marker以后彈出的右鍵菜單和在別的地方彈出的不一樣。類似這樣的效果:

未命名.bmp

?

?

?

?

?

?

?

?

?

?

?

?

marker上的比其它的多了Clear Search Results這一項,起初我想要使用事件傳進來的參數marker("singlerightclick"的第三個參數是overlay?http://www.google.com/apis/maps/documentation/reference.html)來判斷:???

java 代碼
  1. GEvent.addListener(map, "singlerightclick" ,function(pixel,tile,?marker)?{ ??
  2. ???????? //?store?the?"pixel"?info?in?case?we?need?it?later ??
  3. ???????? //?adjust?the?context?menu?location?if?near?an?egde ??
  4. ???????? //?create?a?GControlPosition ??
  5. ???????? //?apply?it?to?the?context?menu,?and?make?the?context?menu?visible ??
  6. ????????clickedPixel?=?pixel; ??
  7. ????????var?x=pixel.x; ??
  8. ????????var?y=pixel.y; ??
  9. ???????? if ?(x?>?map.getSize().width?-? 120 )?{?x?=?map.getSize().width?-? 120 ?} ??
  10. ???????? if ?(y?>?map.getSize().height?-? 100 )?{?y?=?map.getSize().height?-? 100 ?} ??
  11. ????????var?pos?=? new ?GControlPosition(G_ANCHOR_TOP_LEFT,? new ?GSize(x,y));?? ??
  12. ????????pos.apply(contextmenu); ??
  13. ???? if (marker){ ??
  14. ????????????contextmenu.style.visibility?=? "visible" ; ??
  15. ????} ??
  16. ??????});??

但是好像行不通,不管在不在marker上點擊鼠標右鍵if(marker)永遠成立,這可把我難住了,怎么辦呢?經過一番的探索我發現這個事件的第二個參數"src"里面有一個property叫做:__marker__,是不是這就是我要找的?于是我就把代碼改成這個樣子:

?

java 代碼
  1. if ?(GBrowserIsCompatible())?{ ??
  2. ??
  3. ?????? //?===?Global?variable?that?can?be?used?by?the?context?handling?functions?== ??
  4. ??????var?clickedPixel;? ??
  5. ??
  6. ??????var?map?=? new ?GMap2(document.getElementById( "map" )); ??
  7. ??????map.addControl( new ?GLargeMapControl()); ??
  8. ??????map.addControl( new ?GMapTypeControl()); ??
  9. ??????map.setCenter( new ?GLatLng( 43 ,- 79 ), 8 ); ??
  10. ??????var?marker?=? new ?GMarker( new ?GLatLng( 43 ,- 79 ),{title: "center" });? ??
  11. ??????map.addOverlay(marker); ??
  12. ??????... ??
  13. ?????? //?===?listen?for?singlerightclick?=== ??
  14. ??????GEvent.addListener(map, "singlerightclick" ,function(pixel,tile,?marker)?{ ??
  15. ???????? //?store?the?"pixel"?info?in?case?we?need?it?later ??
  16. ???????? //?adjust?the?context?menu?location?if?near?an?egde ??
  17. ???????? //?create?a?GControlPosition ??
  18. ???????? //?apply?it?to?the?context?menu,?and?make?the?context?menu?visible ??
  19. ????????clickedPixel?=?pixel; ??
  20. ????????var?x=pixel.x; ??
  21. ????????var?y=pixel.y; ??
  22. ???????? if ?(x?>?map.getSize().width?-? 120 )?{?x?=?map.getSize().width?-? 120 ?} ??
  23. ???????? if ?(y?>?map.getSize().height?-? 100 )?{?y?=?map.getSize().height?-? 100 ?} ??
  24. ????????var?pos?=? new ?GControlPosition(G_ANCHOR_TOP_LEFT,? new ?GSize(x,y));?? ??
  25. ????????pos.apply(contextmenu); ??
  26. ???? if (tile.__marker__){alert(tile.__marker__) ??
  27. ????????????contextmenu.style.visibility?=? "visible" ; ??
  28. ????} else { ??
  29. ????????contextmenu.style.visibility?=? "hidden" ; ??
  30. ????} ??
  31. ??????});??

搞定,It works! 原來google還留了一手的,呵呵。

Google Maps實現右鍵菜單


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!?。?/p>

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 贵州省| 鄄城县| 老河口市| 邛崃市| 麻城市| 泾阳县| 贺州市| 青神县| 肥西县| 上虞市| 连江县| 雷波县| 临湘市| 合作市| 彭州市| 镇安县| 巴马| 连南| 京山县| 扬州市| 会泽县| 麻江县| 青田县| 阿拉善右旗| 龙门县| 驻马店市| 西丰县| 静宁县| 浦江县| 江孜县| 南昌县| 乌拉特后旗| 蓬安县| 阜康市| 芷江| 怀来县| 临江市| 瑞金市| 青铜峡市| 崇左市| 托克逊县|