gaode.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. var map = new AMap.Map("container", {
  2. resizeEnable: true
  3. });
  4. var placeSearch = false;
  5. var marker = false;
  6. AMap.service(["AMap.PlaceSearch"], function() {
  7. placeSearch = new AMap.PlaceSearch({
  8. pageSize: 5,
  9. pageIndex: 1,
  10. map: map,
  11. panel: "panel"
  12. });
  13. });
  14. var clickEventListener = map.on('click', function(e) {
  15. var x = e.lnglat.getLng();
  16. var y = e.lnglat.getLat();
  17. var z = map.getZoom();
  18. parent.setMap(x, y, z);
  19. setMaker(x, y);
  20. });
  21. function search(txt) {
  22. if (txt.indexOf(',') != -1) {
  23. var temp = txt.split(',');
  24. txt = temp[0];
  25. var x = temp[1];
  26. var y = temp[2];
  27. setMaker(x, y);
  28. }
  29. parent.closeMsg();
  30. placeSearch.search(txt);
  31. }
  32. function setMaker(x, y) {
  33. if (marker) {
  34. marker.setPosition([x, y]);
  35. } else {
  36. marker = new AMap.Marker({
  37. icon: "https://webapi.amap.com/theme/v1.3/markers/n/mark_r.png",
  38. position: [x, y]
  39. });
  40. marker.setMap(map);
  41. }
  42. }
  43. function showMaker(txt) {
  44. if (txt.indexOf(',') != -1) {
  45. var temp = txt.split(',');
  46. txt = temp[0];
  47. var x = temp[1];
  48. var y = temp[2];
  49. var z = temp[3];
  50. } else {
  51. return;
  52. }
  53. map.setZoomAndCenter(z, [x, y]);
  54. new AMap.Marker({
  55. map: map,
  56. position: [x, y]
  57. });
  58. }