gpt4 book ai didi

javascript - angular.js 路由和 map 的问题

转载 作者:行者123 更新时间:2023-12-03 06:21:26 25 4
gpt4 key购买 nike

我有一个问题,当我使用路由时,我不明白为什么但 map 重复,而不是一张 map 我有两张。

HTML 文件:

<div id="contacts" ng-controller="twoCtrl">
<section class="map-wrapper">
<div class="maps" id="mapOne"></div>
<div class="maps" id="mapTwo"></div>
</section>
</div>

CSS: section.map-wrapper { 顶部边距:30px; position:relative; 高度:310像素; 宽度:100%; }

section.map-wrapper .maps {
position: absolute;
height: auto;
height: 310px;
width: 100%;
z-index: 0;
opacity: 0;
transition: opacity .5s;
}

section.map-wrapper .maps.active {
z-index: 1;
opacity: 1;
}

js

var app = angular.module("myApp", ["ngRoute"]);
app.config(function($routeProvider) {
$routeProvider
.when("/", {
templateUrl : "main.html",
controller: 'oneCtrl'
})
.when("/contacts", {
templateUrl : "pages/contacts.html",
controller: 'twoCtrl'
})
});
app.controller('twoCtrl',function($scope){
$(function() {
//maps' active classes
maps();
function maps() {
$(".load-block:first").addClass('active');
$(".maps:first").addClass('active');
$(".office-block[id='office']").addClass("active");
$("#office").click(function() {
$(".office-block[id='branch']").removeClass("active");
$(".office-block[id='office']").addClass("active");
$(".maps").removeClass("active");
$("#mapOne").addClass("active");
});

$("#branch").click(function() {
$(".office-block[id='office']").removeClass("active");
$(".office-block[id='branch']").addClass("active");
$(".maps").removeClass("active");
$("#mapTwo").addClass("active");
});
};

//map
ymaps.ready(init);
var myMap1,
myMap2,
myPlacemark,
myPlacemark2

function init(){
myMap1 = new ymaps.Map("mapOne", {
center: [50.0094033, 36.2345667],
zoom: 16,
controls: []
});

myMap2 = new ymaps.Map("mapTwo", {
center: [49.7118034, 37.6141396],
zoom: 16,
controls: []
});

myPlacemark = new ymaps.Placemark([50.0094033, 36.2345667], {
hintContent: 'Охрана и технологии',
balloonContent: 'г. Харьков, ул. Данилевского, 12 офис 22'
}, {
iconLayout: 'default#image',
iconImageHref: 'includes/icons/map-mark.png',
iconImageSize: [35, 35]
});

myPlacemark2 = new ymaps.Placemark([49.7118034, 37.6141396], {
hintContent: 'Охрана и технологии',
balloonContent: 'г.Купянск, пл.Ленина, оф.34'
}, {
iconLayout: 'default#image',
iconImageHref: 'includes/icons/map-mark.png',
iconImageSize: [35, 35]
});

myMap1.geoObjects.add(myPlacemark);
myMap2.geoObjects.add(myPlacemark2);
}
});

});

最佳答案

只需从 html 代码中删除 ng-controller="twoCtrl"

<div id="contacts" ng-controller="twoCtrl">

您已经在 $routeConfig 中分配了它

关于javascript - angular.js 路由和 map 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38857831/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com