如何解决使用Typeahead js事件将标记添加到传单地图上的搜索位置
我正在尝试创建一个搜索栏,该标记将标记添加到传单地图中要搜索的位置。我想要的是:
- 当用户搜索某个位置并按下搜索按钮时,该位置的坐标上应出现一个标记。
- 这些位置不是通用的。这意味着它们不是像加拿大,北京等受欢迎的地区。它们是我在我的大学中使用typeahead.js手动添加到搜索栏中的位置。代码如下:
var substringMatcher = function(strs) {
return function findMatches(q,cb) {
var matches,substringRegex;
// an array that will be populated with substring matches
matches = [];
// regex used to determine if a string contains the substring `q`
substrRegex = new RegExp(q,'i');
// iterate through the pool of strings and for any string that
// contains the substring `q`,add it to the `matches` array
$.each(strs,function(i,str) {
if (substrRegex.test(str)) {
matches.push(str);
}
});
cb(matches);
};
};
var places = ['Dean Office','HOD Space Sciences','HOD Mechanical Engineering','HOD Electrical Engineering','HOD Materials Science and Engineering','HOD Maths','HOD Aerospace Engineering','Vice Chancellor Office','Department of Avionics and Aerospace','Department of Electrical Engineering','Department of Materials Science and Engineering','Transport Office','Student Affairs'
];
$('#the-basics .typeahead').typeahead({
hint: true,highlight: true,minLength: 1
},{
name: 'places',source: substringMatcher(places)
});
我不知道如何使用预先选择的选项将标记添加到地图,并且对JS函数和事件不是很好。有人可以在用户在搜索栏中选择他/她的选项并单击搜索按钮之后,建议如何将标记添加到地图上吗?
P.S。我试过了,但是没用:
$('#the-basics .typeahead').on('typeahead:selected',function(evt,item) {
var pulsingIcon = L.icon.pulse({iconSize:[10,10],color:'red'});
var search = L.marker([33.521500,73.176870],{icon: pulsingIcon});
if (places == 'Dean Office') {
search.setLatLng([33.521500,73.176870])
}
else (places == 'HOD Space Sciences') {
search.setLatLng([33.519560,73.176355])
}
});
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。