Jquery 从地图外部触发google地图事件onHover

Jquery 从地图外部触发google地图事件onHover,jquery,css,google-maps,google-maps-api-3,Jquery,Css,Google Maps,Google Maps Api 3,我正在尝试修改initMap()GoogleMaps回调之外的多段线 JavaScript: var map; var height = window.innerHeight / 3; var workOrders = { "1":[ { "lat":57.77153, "lng":14.15588, "id":"7861ac93-42e9-45fb-bc2c-a4cd8319fe80" } ] };

我正在尝试修改
initMap()
GoogleMaps回调之外的多段线

JavaScript:

var map;
var height = window.innerHeight / 3;
var workOrders = {
    "1":[
        {
        "lat":57.77153,
        "lng":14.15588,
        "id":"7861ac93-42e9-45fb-bc2c-a4cd8319fe80"
        }
    ]
};   
var latestCoordinates = {
    "lat":57.77153,
    "lng":14.15588,
}

// Global Polyline Object
var coordinateObject = null;

$('#map').css('height', height);
function initMap() {
    map = new google.maps.Map(document.getElementById('map'), {
        center: latestCoordinates, // last added coordinates
        zoom: 13,
        disableDefaultUI: true
    });
    $.each(workOrders, function (key, data) {
        coordinateObject = new google.maps.Polyline({
            path: data,
            geodesic: true,
            strokeColor: '#324D5E',
            strokeOpacity: 1,
            strokeWeight: 8
        });

        google.maps.event.addListener(coordinateObject, 'mouseover', function(e) {
            // var test = workOrders[key][0]['name ']);
            var workOrderId = workOrders[key][0]['id'];
            coordinateObject.setOptions({strokeOpacity: 0.5});
            $('#' + workOrderId + ' .list-headers, #' + workOrderId + ' .list-content').css('background', '#CCCCCC');
        });

        google.maps.event.addListener(coordinateObject, 'mouseout', function(e) {
            var workOrderId = workOrders[key][0]['id'];
            coordinateObject.setOptions({strokeOpacity: 1});
            $('#' + workOrderId + ' .list-headers, #' + workOrderId + ' .list-content').css('background', '#FFFFFF');
        });

        coordinateObject.setMap(map);
    });
}

$(document).on('mouseover', '.list-column', function(e) {
    google.maps.event.trigger(coordinateObject, 'mouseover');
});
HTML:

    <div id="7861ac93-42e9-45fb-bc2c-a4cd8319fe80" class="col-sm-12 list-column">
        <div class="list-headers">
            ...
        </div>
        <div class="list-content">
            ...
        </div>
    </div>
错误

未捕获的TypeError:无法读取未定义commonjs.3的属性“defaultPrevented”

  • _.qi@common.js:3

  • (匿名函数)@poly.js:22

  • _.H.trigger@js?key=XXXXXX&callback=initMap:88

  • (匿名函数)@a7184edc-46e9-4080-b4f3-3e6676d08d07:155*


您的问题可能是因为
coordinateObject
initMap
函数的局部变量。因此,如果您试图在该函数之外访问它,它将无法访问(并且您只会得到一个
null
)。将coordinateObject设置为全局并尝试如下触发:“浏览器看到的代码是什么样子的?”?请提供一份说明问题的报告,包括
$workOrderPositions的数据
$latestCreatedCoordinates,等等。您的问题可能是因为
coordinateObject
initMap
函数的局部变量。因此,如果您试图在该函数之外访问它,它将无法访问(并且您只会得到一个
null
)。将coordinateObject设置为全局并尝试如下触发:“浏览器看到的代码是什么样子的?”?请提供一份说明问题的报告,包括
$workOrderPositions的数据
$latestCreatedCoordinates,等等。
function initMap() {
    map = new google.maps.Map(document.getElementById('map'), {
        center: latestCoordinates, // last added coordinates
        zoom: 13,
        disableDefaultUI: true
    });
    $.each(workOrders, function (key, data) {
        coordinateObject = new google.maps.Polyline({
            path: data,
            geodesic: true,
            strokeColor: '#324D5E',
            strokeOpacity: 1,
            strokeWeight: 8
        });

        addDomListener(google.maps.event, coordinateObject, 'mouseover', workOrders[key][0]['id'], '#CCCCCC', 0.5)
        addDomListener(google.maps.event, coordinateObject, 'mouseout', workOrders[key][0]['id'], '#FFFFFF', 1)

        coordinateObject.setMap(map);
    });
}

function addDomListener(mapEvent, coordinateObject, eventTrigger, workOrderId, onHoverBackground, opacity)
{
    mapEvent.addDomListener(coordinateObject, eventTrigger, function(e) {
        coordinateObject.setOptions({strokeOpacity: opacity});
        $('#' + workOrderId + ' .list-headers, #' + workOrderId + ' .list-content').css('background', onHoverBackground);
    });

    $('#'+workOrderId+'.list-column').each(function() {
        var col = document.getElementById($(this).attr('id'));
        mapEvent.addDomListener(col, eventTrigger, function(event) {
            mapEvent.trigger(coordinateObject, eventTrigger, {

            });
        });
    });
}