全球理念:首先用户可以添加标记和折线。然后他可以通过dblclick的新窗口为每个标记添加Infowindow。但不幸的是dblclick to marker不起作用。您能给出一些建议:如何通过jQuery向标记添加信息?
var all_overlays = [];
function writeInfo() {
alert("привет!");
}
function addPolyline() {
drawingManager.setDrawingMode(google.maps.drawing.OverlayType.POLYLINE);
}
function addMarker() {
drawingManager.setDrawingMode(google.maps.drawing.OverlayType.MARKER);
}
function initialize() {
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 4,
//maxZoom:7,
minZoom: 2,
disableDoubleClickZoom: true,
center: new google.maps.LatLng(59.32522, 18.07002),
mapTypeId: google.maps.MapTypeId.ROADMAP,
disableDefaultUI: true,
zoomControl: true
});
var polyOptions = {
strokeWeight: 0,
fillOpacity: 0.45,
editable: true
};
drawingManager = new google.maps.drawing.DrawingManager({
drawingControl: false,
drawingControlOptions: {
position: google.maps.ControlPosition.TOP_CENTER,
drawingModes: [
google.maps.drawing.OverlayType.MARKER,
polyLine = google.maps.drawing.OverlayType.POLYLINE,
]
},
markerOptions: {
draggable: true,
animation: google.maps.Animation.DROP
},
polylineOptions: {
editable: true,
geodesic: true
},
map: map
});
google.maps.event.addListener(drawingManager, 'overlaycomplete', function(e) {
var allOverlays = all_overlays.push(e);
if (e.type != google.maps.drawing.OverlayType.MARKER) {
var line = e;
line.type = e.type;
var newShape = e.overlay;
newShape.type = e.type;
google.maps.event.addListener(newShape, 'click', function() {
setSelection(newShape);
});
setSelection(newShape);
}
});
google.maps.event.addListener(all_overlays, 'dblclick', writeInfo);
google.maps.event.addListener(“这必须是存储对象的变量,是吗?”,“dblclick”,writeInfo);
答案 0 :(得分:0)
如果我将双击监听器添加到标记(或其他叠加层),它适用于我,来自google's examples in the documentation的修改代码:
function initialize() {
var mapOptions = {
center: new google.maps.LatLng(-34.397, 150.644),
zoom: 8
};
var map = new google.maps.Map(document.getElementById('map-canvas'),
mapOptions);
var drawingManager = new google.maps.drawing.DrawingManager({
drawingMode: google.maps.drawing.OverlayType.MARKER,
drawingControl: true,
drawingControlOptions: {
position: google.maps.ControlPosition.TOP_CENTER,
drawingModes: [
google.maps.drawing.OverlayType.MARKER,
google.maps.drawing.OverlayType.CIRCLE,
google.maps.drawing.OverlayType.POLYGON,
google.maps.drawing.OverlayType.POLYLINE,
google.maps.drawing.OverlayType.RECTANGLE
]
},
markerOptions: {
draggable: true,
animation: google.maps.Animation.DROP
},
circleOptions: {
fillColor: '#ffff00',
fillOpacity: 1,
strokeWeight: 5,
clickable: false,
editable: true,
zIndex: 1
},
polylineOptions: {
editable: true,
geodesic: true
},
map: map
});
drawingManager.setMap(map);
google.maps.event.addListener(drawingManager, 'overlaycomplete', function(event) {
if (event.type == google.maps.drawing.OverlayType.CIRCLE) {
var radius = event.overlay.getRadius();
} else if (event.type == google.maps.drawing.OverlayType.MARKER) {
google.maps.event.addListener(event.overlay, 'dblclick', writeInfo);
} else if (event.type == google.maps.drawing.OverlayType.POLYGON) {
google.maps.event.addListener(event.overlay, 'dblclick', writeInfo);
} else if (event.type == google.maps.drawing.OverlayType.POLYLINE) {
google.maps.event.addListener(event.overlay, 'dblclick', writeInfo);
}
});
google.maps.event.addListener(map, 'dblclick', writeInfo);
}
google.maps.event.addDomListener(window, 'load', initialize);
function writeInfo() {
alert("привет!");
}
答案 1 :(得分:0)
它帮助我:
google.maps.event.addListener(drawingManager, 'overlaycomplete', function(e) {
var allOverlays = all_overlays.push(e);
if (e.type != google.maps.drawing.OverlayType.MARKER) {
var line = e;
line.type = e.type;
var newShape = e.overlay;
newShape.type = e.type;
google.maps.event.addListener(newShape, 'click', function() {
setSelection(newShape);
});
setSelection(newShape);
}
if (e.type == google.maps.drawing.OverlayType.MARKER) {
var choiceMarker = e.overlay;
choiceMarker.type = e.type;
google.maps.event.addListener(choiceMarker, 'dblclick', function() {
alert(choiceMarker.getPosition());
});
}
});