问题描述
我只知道一种方法:
右键点击'删除我'
别的我可以删除谷歌地图上的标记吗?
现在是我的代码:
GEvent.addListener(marker,'mousedown',function(e){
alert(e)
if(e.button == 2){
alert('sss')
map.removeOverlay(marker);
}
当我右击,它提醒(40.23141543543321,114.3214121421)
;当我查看API时,我看到这个:
mousedown(latlng:GLatLng)
所以我认为 e
不是一个事件,而是一个'GLatLng'
如果我使用'singlerightclick',当我右击时。
这是我的完整代码:
<!DOCTYPE HTML PUBLIC - // WAPFORUM // DTD XHTML Mobile 1.0 // ENhttp://www.wapforum.org/DTD/xhtml-mobile10.dtd\"&b $ b< html xmlns =http: //万维网。 w3.org/1999/xhtml>
< head>
< meta http-equiv =Content-Typecontent =text / html; charset = UTF-8>
< meta name =viewportcontent =width = device-width,minimum-scale = 0.3,maximum-scale = 5.0,user-scalable = yes>
< / head>
< body onload =initialize()onunload =GUnload()>
< style type =text / css>
* {
margin:0;
padding:0;
}
#head {
height:70px;
背景:#a00;
}
#logo {
颜色:白色;
font-weight:bold;
line-height:70px;
margin-left:100px;
}
#main {
position:relative;
margin-top:1px;
}
#left {
border:1px纯红色;
height:700px;
margin-right:202px;
}
#top {
font-weight:bold;
line-height:70px;
margin-left:120px;
}
#map_canvas {
height:630px;
}
#right {
background:#ff0;
float:right;
height:702px;
位置:绝对;
right:0;
top:0;
width:200px;
}
.container {
border:5px纯红色;
height:50px;
margin-left:50px;
padding:17px 0 0 20px;
宽度:85%;
}
.b {
background:url(img / xr.png)right no-repeat;
}
.b> div {
width:30px;
height:31px;
background:url(img / xpinIcon.png)0 0 no-repeat;
}
.c {
background:url(img / xr.png)right no-repeat;
margin-left:60px;
}
.c> div {
width:30px;
height:31px;
background:url(img / xlineIcon.png)0 0不重复;
}
< / style>
<! - < div style =width:100px; height:100px; background:blue;> < / DIV> - >
< div id = head>
< div id = logo>徽标< / div>
< / div>
< div id = main>
< div id = left>
< div id = top> search
< input type =textname =id =style =width:80%/>
< / div>
< div id =map_canvas>< / div>
< / div>
< div id = right>< / div>
< / div>
< script src =jquery-1.4.2.jstype =text / javascript>< / script>
< script src =jquery-ui-1.8rc3.custom.min.jstype =text / javascript>< / script>
< script type =text / javascriptsrc =nicEdit.js>< / script>
< script src =http://ditu.google.cn/maps?file=api&v=2&sensor=false&key=ABQIAAAA-7cuV3vqp7w6zUNiN_F4uBRi_j0U6kJrkFvY4-OX2XYmEAa76BSNz0ifabgugotzJgrxyodPDmheRAtype = 文本/ JavaScript的 >< /脚本>
< script type =text / javascript>
var aFn;
// **********
函数initialize(){
if(GBrowserIsCompatible()){
// **** ********
函数a(){
}
// if(GControl)
a.prototype = new GControl();
a.prototype.initialize = function(map){
var container = document.createElement(div);
var a ='';
for(i = 0; i a + ='< div class = b style =position:absolute;>< div>< / div><< ; / div>'
}
for(i = 0; i a + ='< div class = c style =position:absolute;> < div>< / div>< / div>'
}
$(container).addClass('container');
$(map.getContainer())。append($(container).append(a));
返回容器;
}
a.prototype.getDefaultPosition = function(){
return new GControlPosition(G_ANCHOR_TOP_LEFT,new GSize(7,7));
}
// ************
var map = new GMap2(document.getElementById(map_canvas));
map.addControl(new a());
map.enableScrollWheelZoom();
var center = new GLatLng(39.9493,116.3975);
map.setCenter(center,13);
aFn = function(x,y){
var point = new GPoint(x,y)
point = map.fromContainerPixelToLatLng(point );
var marker = new GMarker(point,{draggable:true});
var a = $(
'< form method =postaction =style =height:100px; overflow:hidden; width:230px;>'+
'< textarea id =area1cols =22rows =5style =border:none> cilck edit< / textarea>'+
'< / form> ')
var一次;
a.click(function(){
if(!once)var area1 = new nicEditor({buttonList:['bold','fontSize','left','center','right' ,'forecolor']})。panelInstance('area1')
once = 1;
})
GEvent.addListener(marker,click,function(){
marker.openInfoWindowHtml(a [0]);
});
map.addOverlay(marker);
GEvent.addListener(marker,'singlerightclick',function(point,source,overlay){
alert('sss')
map.removeOverlay(marker);
}) ;
$ b $(。b)。draggable({
revert:true,
revertDuration:0
});
$('。container')。droppable({greedy:true});
$ b $(#map_canvas)。droppable({
drop:function(event,ui){
Fn(event.pageX - $(#map_canvas))。 offset()。left,event.pageY - $(#map_canvas)。offset()。top);
//}
}
});
}
}
// *************
< / script>
< / body>
< / html>
我想我已经明白了这一点:
GEvent.addListener(map,'singlerightclick',function(point,source,overlay){
map.removeOverlay(marker);
});
但是不,这会删除标记,不管在哪里我点击地图。
我想我现在拥有它:
GEvent。 (标记)
map.removeOverlay(marker);
});
var marker = new GMarker(latlng);
map.addOverlay(marker);
GEvent.addListener(marker,'singlerightclick',function(point,source,overlay){
this.setMap(null);
});
I only know of one way:
Right click and click 'delete me'
How else can I delete markers on Google Maps?
This is my code now:
GEvent.addListener(marker, 'mousedown', function(e) {
alert(e)
if (e.button == 2){
alert('sss')
map.removeOverlay(marker);
}
When i right-click, it alerts (40.23141543543321,114.3214121421)
; when I look at the API, I see this:
mousedown(latlng:GLatLng)
so I think that e
is not an event, but a 'GLatLng'
If I use the 'singlerightclick', nothing happens when i right-click.
This is my full code:
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width,minimum-scale=0.3,maximum-scale=5.0,user-scalable=yes">
</head>
<body onload="initialize()" onunload="GUnload()">
<style type="text/css">
*{
margin:0;
padding:0;
}
#head{
height:70px;
background:#a00;
}
#logo{
color:white;
font-weight:bold;
line-height:70px;
margin-left:100px;
}
#main{
position:relative;
margin-top:1px;
}
#left{
border:1px solid red;
height:700px;
margin-right:202px;
}
#top{
font-weight:bold;
line-height:70px;
margin-left:120px;
}
#map_canvas{
height:630px;
}
#right{
background:#ff0;
float:right;
height:702px;
position:absolute;
right:0;
top:0;
width:200px;
}
.container{
border:5px solid red;
height:50px;
margin-left:50px;
padding:17px 0 0 20px;
width:85%;
}
.b{
background:url(img/xr.png) right no-repeat;
}
.b > div{
width:30px;
height:31px;
background:url(img/xpinIcon.png) 0 0 no-repeat;
}
.c{
background:url(img/xr.png) right no-repeat;
margin-left:60px;
}
.c > div{
width:30px;
height:31px;
background:url(img/xlineIcon.png) 0 0 no-repeat;
}
</style>
<!--<div style="width:100px;height:100px;background:blue;"> </div>-->
<div id=head>
<div id=logo>logo</div>
</div>
<div id=main>
<div id=left>
<div id=top>search
<input type="text" name="" id="" style="width:80%"/>
</div>
<div id="map_canvas" ></div>
</div>
<div id=right ></div>
</div>
<script src="jquery-1.4.2.js" type="text/javascript"></script>
<script src="jquery-ui-1.8rc3.custom.min.js" type="text/javascript"></script>
<script type="text/javascript" src="nicEdit.js"></script>
<script src="http://ditu.google.cn/maps?file=api&v=2&sensor=false&key=ABQIAAAA-7cuV3vqp7w6zUNiN_F4uBRi_j0U6kJrkFvY4-OX2XYmEAa76BSNz0ifabgugotzJgrxyodPDmheRA" type="text/javascript"></script>
<script type="text/javascript">
var aFn;
//**********
function initialize() {
if (GBrowserIsCompatible()) {
//************
function a() {
}
//if(GControl)
a.prototype = new GControl();
a.prototype.initialize = function(map) {
var container = document.createElement("div");
var a='';
for(i=0;i<2;i++){
a+='<div class=b style="position:absolute;"><div></div></div>'
}
for(i=0;i<2;i++){
a+='<div class=c style="position:absolute;"><div></div></div>'
}
$(container).addClass('container');
$(map.getContainer()).append($(container).append(a));
return container;
}
a.prototype.getDefaultPosition = function() {
return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(7, 7));
}
//************
var map = new GMap2(document.getElementById("map_canvas"));
map.addControl(new a());
map.enableScrollWheelZoom();
var center=new GLatLng(39.9493, 116.3975);
map.setCenter(center, 13);
aFn=function(x,y){
var point =new GPoint(x,y)
point = map.fromContainerPixelToLatLng(point);
var marker = new GMarker(point,{draggable:true});
var a=$(
'<form method="post" action="" style="height:100px;overflow:hidden;width:230px;">'+
'<textarea id="area1" cols="22" rows="5" style="border:none">cilck edit</textarea>'+
'</form>')
var once;
a.click(function(){
if(!once)var area1=new nicEditor({buttonList : ['bold','fontSize','left','center','right','forecolor']}).panelInstance('area1')
once=1;
})
GEvent.addListener(marker, "click", function(){
marker.openInfoWindowHtml(a[0]);
});
map.addOverlay(marker);
GEvent.addListener(marker, 'singlerightclick', function(point, source, overlay) {
alert('sss')
map.removeOverlay(marker);
});
}
$(".b").draggable({
revert: true,
revertDuration: 0
});
$('.container').droppable({greedy: true});
$("#map_canvas").droppable({
drop: function(event,ui) {
aFn(event.pageX-$("#map_canvas").offset().left,event.pageY-$("#map_canvas").offset().top);
//}
}
});
}
}
//*************
</script>
</body>
</html>
I thought I figured it out with this:
GEvent.addListener(map, 'singlerightclick', function(point, source, overlay) {
map.removeOverlay(marker);
});
but no, this removes the marker no matter where I click on the map.
I think I have it now:
GEvent.addListener(map, 'singlerightclick', function(pixel,tile, marker) {
if(marker)
map.removeOverlay(marker);
});
var marker = new GMarker(latlng);
map.addOverlay(marker);
GEvent.addListener(marker, 'singlerightclick', function(point, source, overlay) {
this.setMap(null);
});
这篇关于如何删除Google地图上的标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!