基于JS抓取某高校附近共享单车位置 使用web方式展示位置变化代码实例
程序员文章站
2023-12-03 23:53:28
效果如图
使用了高德地图api:
js代码如下:
function mapoperate() {
}
mapoperate.proto...
效果如图
使用了高德地图api:
js代码如下:
function mapoperate() { } mapoperate.prototype.listensubmit = function () { var self = this; var submitbut = $(".submit-btn"); var time_id = $("#time-id"); var time_now = new date(time_id.html()); submitbut.click(function () { var btn = $(this); var data_id = btn.attr('data-id'); var datas = self.format(time_now, "yyyy-mm-dd hh:mm"); switch (data_id) { case data_id = "a": console.log("a"); time_now = new date(time_id.html()); var t = time_now.gettime(); t -= 1900000; datas = new date(t); datas = self.format(datas, "yyyy-mm-dd hh:mm"); break; case data_id = "b": console.log("b"); time_now = new date(time_id.html()); var t = time_now.gettime(); t -= 120000; datas = new date(t); datas = self.format(datas, "yyyy-mm-dd hh:mm"); break; case data_id = "c": console.log("c"); datas = "2019-05-05 12:01"; break; case data_id = "d": console.log("d"); time_now = new date(time_id.html()); var t = time_now.gettime(); t += 120000; datas = new date(t); datas = self.format(datas, "yyyy-mm-dd hh:mm"); break; case data_id = "e": console.log("e"); time_now = new date(time_id.html()); var t = time_now.gettime(); t += 1900000; datas = new date(t); datas = self.format(datas, "yyyy-mm-dd hh:mm"); break; } console.log(datas); var div = document.getelementbyid("time-id"); div.innertext = datas; $.ajax({ type: 'post', async: false, url: '/index', data: { "datas": datas, }, success: function (result) { //stringify()用于从一个对象解析出字符串 // jsondata = json.stringify(result['result']); // console.log(jsondata); //json.parse用于从一个字符串中解析出json对象 var map = new amap.map('container', { zoom:15, center: [119.03797, 33.548503] }); var jsondata = json.stringify(result['result']); var dt = json.parse(jsondata); if (dt.length > 0) { var style = [{ url: 'https://a.amap.com/jsapi_demos/static/images/mass0.png', anchor: new amap.pixel(6, 6), size: new amap.size(8, 8) }, { url: 'https://a.amap.com/jsapi_demos/static/images/mass0.png', anchor: new amap.pixel(3, 3), size: new amap.size(8, 8) }, { url: 'https://a.amap.com/jsapi_demos/static/images/mass0.png', anchor: new amap.pixel(4, 4), size: new amap.size(8, 8) } ]; var massmarks = []; for (var i = 0; i < dt.length; i++) { var point = {'lnglat': [dt[i][0], dt[i][1]], 'name': "1", 'id': i}; massmarks.push(point); } var mass = new amap.massmarks(massmarks, { opacity: 0.8, zindex: 111, cursor: 'pointer', style: style }); var marker = new amap.marker({content: ' ', map: map}); mass.on('mouseover', function (e) { marker.setposition(e.data.lnglat); marker.setlabel({content: e.data.name}) }); mass.setmap(map); } } }); }); }; mapoperate.prototype.run = function () { var self = this; self.listensubmit(); }; mapoperate.prototype.tool = function (resultlist) { // 创建地图实例 var map = new amap.map("container", { zoom: 13, center: [119.038, 33.548], resizeenable: true, mapstyle: 'amap://styles/whitesmoke' }); var positions = resultlist; var anchor = [ 'bottom-left', 'bottom-center', 'bottom-right', 'middle-left', 'center', 'middle-right', 'top-left', 'top-center', 'top-right' ]; var pos_icon = []; var pos_marker = []; var icon = []; var marker = []; for (var i = 0; i < 100; i++) { // 创建一个 icon pos_icon[i] = new amap.icon({ // 图标尺寸 size: new amap.size(12, 12), // 图标的取图地址 image: '//a.amap.com/jsapi_demos/static/demo-center/marker/marker.png', // 图标所用图片大小 imagesize: new amap.size(12, 12), }); // 将 icon 传入 marker pos_marker[i] = new amap.marker({ position: positions[i], icon: pos_icon[i], anchor: 'center', //设置锚点 offset: new amap.pixel(0, 0) //设置偏移量 }); map.add(pos_marker[i]); } }; $(function () { var map = new mapoperate(); map.run(); }); mapoperate.prototype.format = function (now, mask) { var d = now; var zeroize = function (value, length) { if (!length) length = 2; value = string(value); for (var i = 0, zeros = ''; i < (length - value.length); i++) { zeros += '0'; } return zeros + value; }; return mask.replace(/"[^"]*"|'[^']*'|\b(?:d{1,4}|m{1,4}|yy(?:yy)?|([hhmstt])\1?|[llz])\b/g, function ($0) { switch ($0) { case 'd': return d.getdate(); case 'dd': return zeroize(d.getdate()); case 'ddd': return ['sun', 'mon', 'tue', 'wed', 'thr', 'fri', 'sat'][d.getday()]; case 'dddd': return ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'][d.getday()]; case 'm': return d.getmonth() + 1; case 'mm': return zeroize(d.getmonth() + 1); case 'mmm': return ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec'][d.getmonth()]; case 'mmmm': return ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'][d.getmonth()]; case 'yy': return string(d.getfullyear()).substr(2); case 'yyyy': return d.getfullyear(); case 'h': return d.gethours() % 12 || 12; case 'hh': return zeroize(d.gethours() % 12 || 12); case 'h': return d.gethours(); case 'hh': return zeroize(d.gethours()); case 'm': return d.getminutes(); case 'mm': return zeroize(d.getminutes()); case 's': return d.getseconds(); case 'ss': return zeroize(d.getseconds()); case 'l': return zeroize(d.getmilliseconds(), 3); case 'l': var m = d.getmilliseconds(); if (m > 99) m = math.round(m / 10); return zeroize(m); case 'tt': return d.gethours() < 12 ? 'am' : 'pm'; case 'tt': return d.gethours() < 12 ? 'am' : 'pm'; case 'z': return d.toutcstring().match(/[a-z]+$/); // return quoted strings with the surrounding quotes removed default: return $0.substr(1, $0.length - 2); } }); }
项目地址:https://github.com/longbigbeard/hellobike_webshow
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
上一篇: JS用最简单的方法实现四舍五入
下一篇: 网络剧的销售新渠道,自建视频付费点播商城