GIS开发核心能力
交互开发技能
地图个性化展示
精准点位标注与交互
Marker
自定义图标+InfoWindow
弹窗组合,实现点位信息深度展示。灵活的信息窗体控制
<script type="text/javascript">
window._AMapSecurityConfig = {
securityJsCode: "「你的安全密钥」",
};
script>
<script src="https://webapi.amap.com/maps?v=2.0&key=「你的Key」">script>
// 地图初始化(含自定义样式)
const map = new AMap.Map("container", {
zoom: 11,
center: [116.4074, 39.9042],
mapStyle: "amap://styles/「你的样式ID」", // 自定义样式或内置样式
});
// 1. 创建带自定义图标的门店标注
const storeMarker = new AMap.Marker({
position: [116.4074, 39.9042], // 门店坐标
icon: new AMap.Icon({
image: "https://example.com/store-icon.png", // 门店图标URL
size: new AMap.Size(32, 32), // 图标尺寸
imageOffset: new AMap.Pixel(-16, -32) // 定位点偏移(图标底部居中)
}),
offset: new AMap.Pixel(0, 0),
title: "旗舰店"
});
map.add(storeMarker);
// 2. 标注点击事件(打开信息窗体)
storeMarker.on('click', () => {
storeInfoWindow.open(map, storeMarker.getPosition());
});
// 1. 初始化信息窗体(带复杂交互)
const storeInfoWindow = new AMap.InfoWindow({
content: `
旗舰店
地址:北京市朝阳区建国路88号
营业时间:9:00-22:00
`,
offset: new AMap.Pixel(0, -30), // 窗体相对于标注的偏移
closeWhenClickMap: true,
autoMove: true,
isCustom: true
});
// 2. 窗体内部事件绑定(在open回调中执行)
storeInfoWindow.on('open', () => {
// 导航按钮事件
document.getElementById('navigate-btn').addEventListener('click', () => {
// 调用高德导航API
AMap.plugin('AMap.Drive', () => {
const drive = new AMap.Drive({
map: map,
panel: "drive-panel"
});
drive.search(storeMarker.getPosition(), "我的位置");
});
document.getElementById('action-result').textContent = '正在加载导航...';
});
// 分享按钮事件
document.getElementById('share-btn').addEventListener('click', () => {
// 模拟分享逻辑
document.getElementById('action-result').textContent = '分享成功!';
setTimeout(() => {
document.getElementById('action-result').textContent = '';
}, 2000);
});
});
// 3. 手动打开窗体(非标注触发场景)
document.getElementById('show-store-btn').addEventListener('click', () => {
storeInfoWindow.open(map, storeMarker.getPosition());
});
// 城市数据集合
const citiesData = [
{ name: "北京", pos: [116.4074, 39.9042], type: "首都" },
{ name: "上海", pos: [121.4737, 31.2304], type: "经济中心" },
{ name: "广州", pos: [113.2649, 23.1291], type: "贸易中心" }
];
// 批量创建标注并绑定动态事件
citiesData.forEach(city => {
const marker = new AMap.Marker({
position: city.pos,
title: city.name,
icon: getCityIcon(city.type) // 根据城市类型返回不同图标
});
marker.on('click', () => {
// 动态更新窗体内容
cityInfoWindow.setContent(`
${city.name}
类型:${city.type}
坐标:${city.pos.join(',')}
`);
cityInfoWindow.open(map, city.pos);
// 动态绑定按钮事件
setTimeout(() => {
document.querySelector('.view-data').addEventListener('click', (e) => {
const cityName = e.currentTarget.dataset.city;
fetchCityData(cityName); // 模拟加载城市数据
});
}, 0);
});
map.add(marker);
});
物流配送系统
Marker
+InfoWindow
+AMap.Drive
路径规划API。旅游导览APP
setCenter
地图定位。商业选址分析
InfoWindow
内嵌ECharts图表+事件监听数据交互。模块 | 关键技术点 | 解决的问题 |
---|---|---|
地图初始化 | 样式ID配置、中心点/缩放设置 | 个性化地图展示 |
标注系统 | 图标自定义、居中偏移计算 | 点位精准可视化 |
信息窗体 | 内容动态更新、事件绑定时机控制 | 复杂信息交互展示 |
交互逻辑 | 手动触发弹窗、多标注数据联动 | 非标注场景的地图交互需求 |
通过以上实践,可快速构建具备专业交互能力的GIS应用,满足从基础地图展示到复杂业务逻辑的开发需求。