谷歌地图信息窗口显示在左上角

时间:2016-01-29 11:22:19

标签: html css angularjs google-maps ng-map

当我点击marker时,info window显示在左上角,但它应显示在标记的顶部。

这是情况的图像:http://i.stack.imgur.com/GHHDE.png

此元素样式应设置为左侧,顶部css属性为每个标记的infoWindow设置动态。但是如果你看一下生成的元素,你会看到没有左边或顶部的css属性......

<div class="ng-map-info-window" 
     style="cursor: default; 
            position:absolute; 
            width: 110px; 
            height: 84px;>

任何想法?

------更新(插入代码)

这是我的angularjs控制器,用于显示和隐藏信息窗口

vm.showDetail = function (e, p) {
    vm.p = p;
    vm.map.showInfoWindow('foo-iw', p.locationId);
};

vm.hideDetail = function () {
    vm.map.hideInfoWindow('foo-iw');
};

这是我的ui

<marker id='{{p.locationId}}' 
                   ng-repeat="p in locations track by $index" 
                   position="[{{p.locationX}},{{p.locationY}}]" 
                   on-click="vm.showDetail(p)">
                <marker>     
<info-window id="foo-iw">
           <div ng-non-bindable="">
                id: {{vm.p.locationId}}<br/>
                name: {{vm.p.locationName}}<br/> 
                <a href="#" ng-click="vm.clicked()">Click Here</a>
           </div>
     </info-window>

1 个答案:

答案 0 :(得分:1)

由于showInfoWindow函数接受标记对象作为第二个参数,因此信息窗口未正确定位,因此请替换该行:

vm.map.showInfoWindow('foo-iw', p.locationId);

使用:

vm.map.showInfoWindow('foo-iw', this);

我也在您发布的示例中修复了一些拼写错误,这是一个固定版本:

&#13;
&#13;
angular.module('mapApp', ['ngMap'])
    .controller('mapController', function(NgMap) {
        var vm = this;

        NgMap.getMap().then(function(map) {
            vm.map = map;
        });
        vm.locations = [
            { locationId: 1, locationName: 'Oslo', locationX: 59.923043, locationY: 10.752839 },
            { locationId: 2, locationName: 'Stockholm', locationX: 59.339025, locationY: 18.065818 },
            { locationId: 3, locationName: 'Copenhagen', locationX: 55.675507, locationY: 12.574227 },
            { locationId: 4, locationName: 'Berlin', locationX: 52.521248, locationY: 13.399038 },
            { locationId: 5, locationName: 'Paris', locationX: 48.856127, locationY: 2.346525 }
        ];
        
        /*$scope.showCity = function(event, city) {
            $scope.selectedCity = city;
            $scope.map.showInfoWindow('myInfoWindow', this);
        };*/

        vm.showDetail = function (e, p) {
          vm.p = p;
          //vm.map.showInfoWindow('foo-iw', p.locationId);
          vm.map.showInfoWindow('foo-iw', this);
        };

        vm.hideDetail = function () {
           vm.map.hideInfoWindow('foo-iw');
        };

    });
&#13;
<link href="style.css" rel="stylesheet">
<script src="https://maps.google.com/maps/api/js"></script>
<script src="https://code.angularjs.org/1.3.15/angular.js"></script>
<script src="https://rawgit.com/allenhwkim/angularjs-google-maps/master/build/scripts/ng-map.js"></script>
<div ng-app="mapApp" ng-controller="mapController as vm">
    <ng-map default-style="true" zoom="5" center="59.339025, 18.065818">
        
        <marker id='{{p.locationId}}' 
                   ng-repeat="p in vm.locations track by $index" 
                   position="[{{p.locationX}},{{p.locationY}}]" 
                   on-click="vm.showDetail(p)">
        </marker>     
        <info-window id="foo-iw">
           <div ng-non-bindable="">
                id: {{vm.p.locationId}}<br/>
                name: {{vm.p.locationName}}<br/> 
                <a href="#" ng-click="vm.clicked()">Click Here</a>
           </div>
        </info-window>
    </ng-map>
</div>
&#13;
&#13;
&#13;