JS通过面向对象实现封装地图标点的简单DEMO初稿

2017-02-09 15:07:34  访问(2325) 赞(0) 踩(0)

// info.js //
// 这里定义地图相关的逻辑类 //

function PointInfo() { }

PointInfo.prototype =
{
    PointId: "",
    Icon: "",
    Coordinate: "wgs84",
    GpsTime: "",
    Longitude: 0,
    Latitude: 0,
    Speed: 0,
    Direction: 0,
    Location: "" 
}
 
// eklbs.js //
(function () {

	var EKG = {};

	window["EKG"] = EKG;

	// 地图相关的方法 //
	var ConverFn = {
		ToPoint: function (theValue) {
			markers = [{
				icon: theValue.Icon,
				coordinate: theValue.Coordinate,
				position: [theValue.Longitude, theValue.Latitude]
			}];

			return markers;
		}
	};
	window["EKG"]["ConverFn"] = ConverFn;


	// 地图相关的方法 //
	var MapFn = {
		AddPoint: function (theValue) {
			var mV = ConverFn.ToPoint(theValue);

			mV.forEach(function (marker) {
				new AMap.Marker({
					map: map,
					icon: marker.icon,
					position: [marker.position[0], marker.position[1]], 
				});
			});
		}
	};
	window["EKG"]["MapFn"] = MapFn;

 

	/************End******************/
})();


// main.js //
var idx = 0;
            function fnShowTime() {
                alert('dd');
                ++idx;

                var pI = new PointInfo();

                if (idx == 1) {

                    pI.Icon = 'http://webapi.amap.com/theme/v1.3/markers/n/mark_b1.png';
                    pI.Longitude = 110.460;
                    pI.Latitude = 19.9347710974642;
                }
                else if (idx == 2) {
                    pI.Icon = 'http://webapi.amap.com/theme/v1.3/markers/n/mark_b1.png';
                    pI.Longitude = 110.461;
                    pI.Latitude = 19.9347710974642;
                }
                else if (idx == 3) {
                    pI.Icon = 'http://webapi.amap.com/theme/v1.3/markers/n/mark_b1.png';
                    pI.Longitude = 110.462;
                    pI.Latitude = 19.9347710974642;
                }
                else
                    return;

                EKG.MapFn.AddPoint(pI);
}


标签:JS通过面向对象实现封装地图标点的简单DEMO初稿 

上一条:

下一条:


 

相关评论

评论加载中……
 

发表评论

类型:
内容:
  (Alt+Enter)
 
  ┈全部┈  
 
(显示默认分类)