[英]Google Maps API v3 disabling markers
I've been working on a Google Maps project that allows you to draw and save a boundary (polygon) onto a map. 我一直在研究Google Maps项目,该项目可让您在地图上绘制和保存边界(多边形)。 This is then saved to a database and the page refreshes and pulls back the information onto the map.
然后将其保存到数据库中,页面刷新并将信息拉回到地图上。
I found the code below from another users post and adapted it to my needs which works perfectly until you draw the polygon on from the database. 我从另一个用户的帖子中找到了下面的代码,并将其适应了我的需求,直到您从数据库中绘制多边形为止,该代码才能完美运行。
google.maps.event.addDomListener(drawingManager, 'polygoncomplete', function(polygon) {
polygon.setEditable(true);
google.maps.event.addListener(polygon.getPath(), 'set_at', function () {
document.getElementById("coordsField").value = updateArray(polygon);
});
google.maps.event.addListener(polygon.getPath(), 'insert_at', function () {
document.getElementById("coordsField").value = updateArray(polygon);
});
});
The code creates a listener that waits for the polygon to be complete. 该代码创建一个侦听器,该侦听器等待多边形完成。 It then sets the polygon to be editable and creates two more listeners.
然后将多边形设置为可编辑状态,并再创建两个侦听器。 The first waits for a current point to be updated and the second waits for a new point to be created, both of them then update an array with all of the points and saves this to a hidden field when triggered.
第一个等待当前点的更新,第二个等待创建新的点,然后两个都更新所有点的数组,并在触发时将其保存到隐藏字段中。
This code works perfectly for creating a new polygon however when a polygon is created from the database this is another story. 该代码非常适合创建新的多边形,但是从数据库中创建多边形时,这是另一回事了。 As the listener waits for a polygon to be complete it never triggers as it is actioned automatically.
侦听器在等待多边形完成时,它不会触发,因为它是自动操作的。 I have attempted to remove the wrapper:
我试图删除包装器:
google.maps.event.addDomListener(drawingManager, 'polygoncomplete', function(polygon) {}
and add the update listeners however I get an error for 'polygon is undefined'. 并添加更新侦听器,但是出现“多边形未定义”错误。 Would somebody be able to explain how to resolve this?
有人可以解释如何解决这个问题吗?
trigger the polygoncomplete-event for the drawingManager and pass the automatically created polygon-instance as argument to the callback(3rd argument of trigger
): 触发drawingManager的polygoncomplete-event,并将自动创建的polygon-instance作为参数传递给callback(
trigger
第三个参数):
polygonInstance = new google.maps.Polygon(/*options*/);
google.maps.event.trigger(drawingManager,
'polygoncomplete',
polygonInstance);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.