A Map instance

#pragma warning (disable : 4786 )
//...
#include <map>
#include <string>
//...
#include <iostream>
using namespace std;

class strmap1
{
    typedef std : :map <std : :string, int > type_map;
    typedef type_map : :iterator type_iter;

    type_map    mm;
    type_iter   it;
    int         id;

public :
    strmap1 ( ) : it (NULL ), id ( 0 )
    {
        //init
        id = 0;
        mm [ "i" ] = + +id;
        mm [ "you" ] = + +id;
        mm [ "he" ] = + +id;
    }

    int find ( const char * s )
    {
        cout < < "find " < < s < < endl;
        int ret = 0;
        it = mm.find (s );
        if (mm.end ( ) ! = it ) {
            ret = it - >second;
            cout < < s < < "'s id is " < < ret < < endl;
        } else {
            cout < < "can't find " < < s < < "'s id" < < endl;
        }
        return ret;
    }

    int insert ( const char * s )
    {
        cout < < "insert " < < s < < endl;
        int ret = + +id;
        mm.insert (type_map : :value_type (s, ret ) );
        //mm[s] = ret;//ok
        return ret;
    }

    void remove ( const char * s )
    {
        cout < < "remove " < < s < < endl;
        mm.erase (s );
    }
};

int main ( int argc, char * argv [ ] )
{
    cout < < "(strmap1)string map 1(simple use std::map<string, int>)" < < endl;
    strmap1 o;

    cout < < endl;
    o.find ( "i" );
   
    cout < < endl;
    o.find ( "she" );
   
    cout < < endl;
    o.find ( "you" );
    o.find ( "he" );

    cout < < endl;
    o.insert ( "she" );
    o.remove ( "you" );
    o.remove ( "he" );
   
    cout < < endl;
    o.find ( "you" );
    o.find ( "he" );
    o.find ( "she" );
   
    cout < < endl;
    cout < < "haha~~~now only i and she" < < endl;
    return 0;
}

--输出结果--
(strmap1)string map 1(simple use std::map<string, int>)
find i
i's id is 1
find she
can't find she's id
find you
you's id is 2
find he
he's id is 3
insert she
remove you
remove he
find you
can't find you's id
find he
can't find he's id
find she
she's id is 4
haha~~~now only i and she
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在 Vue3 的 `setup` 函数中,可以使用 `ref` 函数创建响应式数据,使用 `onMounted` 函数在组件挂载时执行操作。 关于高德地图点聚合,需要先在 `index.html` 中引入高德地图 JavaScript API 的 SDK,并在 `setup` 函数中使用 `onMounted` 函数异步加载 SDK 完成后再使用。 以下是一个示例代码: ```html <template> <div id="map"></div> </template> <script> import { ref, onMounted } from 'vue' export default { setup() { const mapInstance = ref(null) // 地图实例 const markers = ref([]) // 标记点数组 onMounted(() => { // 异步加载高德地图 SDK const script = document.createElement('script') script.type = 'text/javascript' script.src = `https://webapi.amap.com/maps?v=1.4.15&key=<your_amap_key>&callback=initMap` document.body.appendChild(script) // 初始化地图 window.initMap = () => { const map = new window.AMap.Map('map', { zoom: 13, center: [116.39, 39.9], viewMode: '3D', // 开启3D视图 pitch: 45, // 俯仰角度 rotation: -20 // 地图旋转角度 }) mapInstance.value = map // 创建标记点 const marker1 = new window.AMap.Marker({ position: [116.397428, 39.90923] }) const marker2 = new window.AMap.Marker({ position: [116.397428, 39.90924] }) markers.value = [marker1, marker2] // 添加标记点到地图 map.add(markers.value) // 加载点聚合插件 const AMapUI = window.AMapUI || {} AMapUI.loadUI(['misc/MarkerClusterer'], function (MarkerClusterer) { // 初始化点聚合 new MarkerClusterer(map, markers.value, { gridSize: 80, maxZoom: 15, zoomOnClick: true }) }) } }) return { mapInstance } } } </script> ``` 需要注意的是,需要在 `AMapUI.loadUI` 方法中加载点聚合插件,而不是直接使用 `AMap.MarkerClusterer`。另外,需要替换代码中的 `<your_amap_key>` 为自己的高德地图开发者密钥。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值