| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323 |
- import common from '../../utils/util';
- import main from '../../utils/main';
- import constant from '../../utils/constant';
- const app = getApp();
- var mapSetting = {
- latitude: 31.232116445550176,
- longitude: 121.47281159374998,
- scale: 9,
- };
- Page({
- data: {
- latitude: mapSetting.latitude,
- longitude: mapSetting.longitude,
- scale: mapSetting.scale,
- markers: [],
- SchoolType: constant.arrSchoolType,
- },
- onReady: function (e) {
- this.mapCtx = wx.createMapContext('myMap');
- },
- onLoad: function (options) {
- var that = this;
- that.setData({
- Containnerheight: main.getWindowHeight(),
- IsShow:app.globalData.userInfo.IsShow,
- PageType: options.PageType,
- SchoolTypeIndex: -1,
- Options: options,
- School: [],
- });
- var title = "";
- if (options.PageType == 1) {
- title = "校址·" + options.SchoolShortName;
- for (var j = 0; j < that.data.SchoolType.length; j++) {
- that.data.SchoolType[j].CSS = "";
- }
- that.setData({
- SchoolType: that.data.SchoolType,
- SchoolName:options.SchoolShortName,
- });
- } else if (options.PageType == 2) {
- title = "地图·" + options.DistrictName;
- that.setData({
- SchoolTypeIndex: 0,
- DistrictName:options.DistrictName,
- });
- } else if (options.PageType == 3) {
- for (var j = 0; j < that.data.SchoolType.length; j++) {
- that.data.SchoolType[j].CSS = "Selected";
- }
- that.setData({
- SchoolType: that.data.SchoolType
- });
- title = "高中校址地图";
- that.setData({
- SchoolTypeIndex: 0,
- });
- }
- wx.setNavigationBarTitle({
- title: title,
- });
- that.setMap();
- },
- mapChange: function (e) {
- if (e.type == "end") {
- mapSetting = {
- latitude: e.detail.centerLocation.latitude,
- longitude: e.detail.centerLocation.longitude,
- scale: e.detail.scale,
- };
- }
- },
- onSelect: function (event) {
- var that = this;
- main.onSelect(that, event, function (obj, e, result) {
- if (e.currentTarget.dataset.object == "SchoolType") {
- var selectIndex = e.currentTarget.dataset.index;
- var selectText = that.data.SchoolType[selectIndex].Name;
- var isSelect = that.data.SchoolType[selectIndex].CSS == "Selected";
- that.setData({
- SchoolType: that.data.SchoolType,
- latitude: mapSetting.latitude,
- longitude: mapSetting.longitude,
- scale: mapSetting.scale,
- });
- that.setMap();
- }
- });
- },
- setMap: function () {
- var that = this;
- var markers = [];
- that.getCurrentPosition(that, markers, function (markers) {
- that.getCurrentSchoolPosition(that, markers, function (markers) {
- that.getSchoolPosition(that, markers, function (markers) {
- that.setData({
- markers: markers,
- });
- });
- });
- });
- },
- getCurrentPosition: function (obj, markers, callback) {
- var that = this;
- wx.getLocation({
- type: 'wgs84',
- success(res) {
- var mypos = {
- id: 9999,
- latitude: res.latitude,
- longitude: res.longitude,
- zIndex: 10,
- callout: {
- content: "我的位置",
- color: '#EB5C28',
- fontSize: 14,
- borderWidth: 2,
- borderRadius: 10,
- borderColor: '#EB5C28',
- padding: 5,
- display: 'ALWAYS',
- textAlign: 'center'
- },
- }
- markers.push(mypos);
- callback(markers);
- },
- fail(res) {
- callback(markers);
- }
- });
- },
- getCurrentSchoolPosition: function (obj, markers, callback) {
- if (obj.data.Options.ID) {
- var arr1 = obj.data.Options.Coordinates.split(",");
- obj.setData({
- Address: obj.data.Options.Address,
- });
- var pos = {
- id: Number(obj.data.Options.ID),
- latitude: arr1[0],
- longitude: arr1[1],
- zIndex: 9,
- callout: {
- content: obj.data.Options.Name,
- color: '#EB5C28',
- fontSize: 14,
- borderWidth: 2,
- borderRadius: 10,
- borderColor: '#EB5C28',
- padding: 5,
- display: 'ALWAYS',
- textAlign: 'center'
- },
- }
- markers.push(pos);
- }
- callback(markers);
- },
- getDistrict: function (obj, markers, callback) {
- var that=this;
- if (obj.data.School.length > 0)
- callback(markers);
- else {
- var arr=[];
- if (that.data.PageType == 3) {
- main.getCollect(function(data){
- arr=getSchool(data["收藏的高中"]);
- obj.setData({
- School: arr,
- });
- callback(markers);
- });
- } else {
- wx.showLoading();
- main.getData("GetMPSSchool?SchoolType1=高中&DistrictID=" + Number(obj.data.Options.DistrictID), function (data) {
- arr=getSchool(data);
- obj.setData({
- School: arr,
- });
- callback(markers);
- setTimeout(function () {
- wx.hideLoading();
- }, 800);
- });
- }
-
- }
- function getSchool(data){
- var arr = [];
- for (var i = 0; i < data.length; i++) {
- var item = data[i];
- var school = {};
- school.ID = item.ID;
- school.Name = item.SchoolShortName;
- school.IsSchoolType2Short = false;
- if (item.SchoolType2Short == "市重点")
- school.IsSchoolType2Short = true;
- if (item.Coordinates) {
- var arr1 = item.Coordinates.split(",");
- school.Latitude = arr1[0];
- school.Longitude = arr1[1];
- if (item.SchoolType2Short == "区重点(特色)")
- item.SchoolType2Short = item.SchoolType2Short.substr(0, 3);
- school.SchoolType2Short = item.SchoolType2Short;
- arr.push(school);
- }
- }
- return arr;
- }
- },
- getSchoolPosition: function (obj, markers, callback) {
- var that = this;
- obj.getDistrict(obj, markers, function (markers) {
- for (var i = 0; i < obj.data.School.length; i++) {
- var item = obj.data.School[i];
- item.IsSchoolType2Short = false;
- for (var j = 0; j < that.data.SchoolType.length; j++) {
- if (that.data.SchoolType[j].CSS == "Selected" &&
- item.SchoolType2Short == that.data.SchoolType[j].Name)
- item.IsSchoolType2Short = true;
- }
- if (item.IsSchoolType2Short &&
- (!obj.data.Options.ID || (obj.data.Options.ID && obj.data.Options.ID != item.ID))) {
- var pos = {
- id: item.ID,
- latitude: item.Latitude,
- longitude: item.Longitude,
- alpha: 0.8,
- callout: {
- content: item.Name,
- color: '#4D4D4D',
- fontSize: 14,
- borderWidth: 2,
- borderRadius: 10,
- borderColor: '#4D4D4D',
- bgColor: '#fff',
- padding: 5,
- display: 'ALWAYS',
- textAlign: 'center'
- },
- }
- markers.push(pos);
- }
- }
- callback(markers);
- });
- },
- goto: function (e) {
- app.globalData.FeedbackUrl="map?id="+this.data.Info.ID+"&DistrictID="+this.data.DistrictID;
- main.goto(e);
- },
- copyUrl:function(e){
- var url=e.currentTarget.dataset.url;
- wx.setClipboardData({
- data: url,
- success (res) {
- wx.showToast({
- title: '已复制',
- });
- }
- });
- },
- onMarkerTap(e) {
- //console.log('@@ markertap', e)
- this.gotoSchool(e);
- },
- onCalloutTap(e) {
- //console.log('@@ onCalloutTap', e)
- this.gotoSchool(e);
- },
- onLabelTap(e) {
- //console.log('@@ labletap', e)
- this.gotoSchool(e);
- },
- gotoSchool(e){
- var id=e.detail.markerId;
- if (id<9999)
- main.goto({currentTarget:{dataset:{url:"school?ID="+id}}});
- },
- onShareTimeline: function () {
- return this.onShareAppMessage();
- },
- onShareAppMessage: function () {
- var that=this;
- var title="上海中招";
- var path=app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID;
- if (that.data.PageType == 1) {
- title+="校址·"+that.data.SchoolName;
- path+='&type=school&ID='+that.data.Options.ID;
- }
- else if (that.data.PageType == 2) {
- title+="学校地图·"+that.data.DistrictName;
- path+='&type=district&ID='+that.data.DistriceID+'&Name='+that.data.DistrictName;
- }
- else{
- title=app.globalData.ShareTitle;
- }
- debugger;
- return {
- title: title,
- path: path
- }
- },
- })
|