123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- function checkhHtml5() {
- if (typeof(Worker) === "undefined") {
- if(navigator.userAgent.indexOf("MSIE 9.0")<=0) {
- alert("请使用: chrome、firefox、safari、IE10 浏览器");
- }
- }
- }
- checkhHtml5();
- var bdMap;
- // 初始化地图
- function initBdMap () {
- bdMap = new BMap.Map('mapContainer');
- // 设置中心点
- if(curCityInfo.lng && curCityInfo.lat){
- var point = new BMap.Point(curCityInfo.lng, curCityInfo.lat);
- bdMap.centerAndZoom(point, curCityInfo.zoom || 10);
- }
- else{
- // 创建地址解析器实例
- var myGeo = new BMap.Geocoder();
- // 将地址解析结果显示在地图上,并调整地图视野
- var address = curCityInfo.name;
- myGeo.getPoint(address, function (point) {
- if (point) {
- bdMap.centerAndZoom(point, curCityInfo.zoom || 10);
- } else {
- alert("您选择地址没有解析到结果!");
- }
- }, address);
- }
- bdMap.enableScrollWheelZoom(true);
-
- // 设置地图风格
- var mapStyle ={
- features: ["road", "building","water","land"],//隐藏地图上的poi
- style : "midnight"
- };
- bdMap.setMapStyle(mapStyle);
- bdMap.clearOverlays();
- // 初始化宠物医院数据
- localStorage.getItem('isShowHospital') && initHospital();
- // 初始化宠物数据
- localStorage.getItem('isShowPets') && initPets();
- }
- // 宠物医院
- function initHospital() {
- let length = hospitalData.length;
- if (length == 0) {
- return;
- }
- var config = {
- icon: compbase + '/icon/hospital.png',
- iconWidth: 32,
- iconHeight: 32,
- };
- for(var i=0; i<length; i++) {
- let point = new BMap.Point(hospitalData[i]['Longitude'],hospitalData[i]['Latitude']);
- addBdMarker(point, config);
- }
-
- }
- // 宠物数据
- function initPets() {
- let length = 0;
- let mapPetData = [];
- for (index in petData) {
- petData[index] && $.merge(mapPetData, petData[index]);
- }
- length = mapPetData.length;
-
- if (length == 0) {
- return;
- }
- var config = {
- icon: compbase + '/icon/dog.png',
- iconWidth: 32,
- iconHeight: 32,
- };
- for(var i=0; i<length; i++) {
- let point = new BMap.Point(mapPetData[i]['Longitude'],mapPetData[i]['Latitude']);
- addBdMarker(point, config);
- }
-
- }
- // 添加覆盖物
- function addBdMarker(point, config){
- var options = {};
- // 图标尺寸
- var iconWidth = config.iconWidth || 32;
- var iconHeight = config.iconHeight || 32;
- var iconSize = new BMap.Size(iconWidth,iconHeight);
- if (config.icon) {
- options.icon = new BMap.Icon(config.icon,iconSize);
- }
-
- var marker = new BMap.Marker(point, options);
- bdMap.addOverlay(marker);
- }
|