angular模态框位置_angularjs 高德地图 选取坐标 bootstrap modal

index.html

{{point|json}}

click show

'use strict';

var app = angular.module('app', ['ngAnimate', 'ui.bootstrap'])

app.controller('ctrl', function ($scope, GdMapModalService) {

$scope.point = {}

$scope.show = function () {

GdMapModalService.showModal($scope.point).result.then(function (point) {

$scope.point = point

})

}

})

GdMapModal.js

(function (angular) {

function controller($scope, $uibModalInstance, point) {

$scope.init = function () {

$scope.point = point

}

$scope.$on('map-click', function (event, e) {

$scope.point = {

lat: e.lnglat.getLat(),

lng: e.lnglat.getLng()

}

//$scope.$apply()

})

$scope.search = function (q) {

AMap.service(["AMap.PlaceSearch"], function () {

var placeSearch = new AMap.PlaceSearch({ //构造地点查询类

pageSize: 1,

pageIndex: 1,

//city: "010", //城市

//map: self.map,

//panel: "panel"

})

//关键字查询

placeSearch.search(q, function (status, result) {

//TODO : 按照自己需求处理查询结果

var poiList = result.poiList

if (poiList.count > 0) {

var p = poiList.pois[0]

$scope.$broadcast('setCenter', [p.location.lng, p.location.lat])

}

})

})

}

$scope.ok = function () {

$uibModalInstance.close($scope.point);

}

$scope.cancel = function () {

$uibModalInstance.dismiss('cancel');

}

}

var app = angular.module('app');

app.factory('GdMapModalService', ['$uibModal', function ($uibModal) {

var service = {};

service.showModal = function (point) {

var modalInstance = $uibModal.open({

//animation: false,

templateUrl: 'GdMapModal.html',

controller: ['$scope', '$uibModalInstance', 'point', controller],

size: 'lg',

resolve: {

point: function () {

return point;

},

}

});

return modalInstance;

}

return service

}]);

app.directive('gdMap', function ($timeout) {

return {

restrict: 'EA',

scope: {

point: '=?',

},

template: '

replace: true,

link: function (scope, el, attr, ctrl) {

scope.map = new AMap.Map(el[0], {

resizeEnable: true,

zoom: 12,

})

if (scope.point.lat && scope.point.lng) {

var center = [scope.point.lng, scope.point.lat]

scope.map.setCenter(center)

scope.marker = new AMap.Marker({ map: scope.map })

scope.marker.setPosition(center)

}

scope.map.on('click', function (e) {

scope.$emit('map-click', e)

if (!scope.marker) {

scope.marker = new AMap.Marker({ map: scope.map })

}

scope.marker.setPosition([e.lnglat.getLng(), e.lnglat.getLat()])

})

scope.$on('setCenter', function (event, center) {

if (!scope.map) return

scope.map.setCenter(center)

})

}

}

})

})(window.angular)

GdMapModal.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值