High moral map - labeled as new Click to switch position

Claim:

1. A central point of the map and the map display level is set arbitrarily, and add a marker at the center point.

2. Set a mouse-like style for little hands.

3. Click on the map to bind event, add a click on the marker in place, while the previous mark should clear.

(See the effect of the specific effects of video)

 

Task (step):

1 Create a map using the new AMap.Map ().

2. A central point of the map and the map display level is set arbitrarily, and use AMap.Marker () method to add a mark in the center of the map

3. The method of setting a small hand setDefaultCursor like a mouse style

4. Click map binding event, add a click tag in place, while the previous mark should use map.remove () method to clear.

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.11&key=9de88a718781910c9a1c81230827d1ce&plugin=AMap.Autocomplete,AMap.PlaceSearch"></script>
        <title>5-4添加标记练习</title>
        <style>
            *{
                padding: 0;
                margin: 0;
            }
            #container{
                position: absolute;
                top: 0;
                left: 0;
                width: 100%;
                height: 100%;
            }
        </style>
    </head>
    <body>
        <div id="container"></div>
        
        <script>
            var map = new AMap.Map('container',{
                zoom:10,
                center:[116.379391,39.861536]
            });
            
            map.setDefaultCursor('pointer');
            
            var marker = new AMap.Marker({
                icon:'https://a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-default.png',
                position:[116,39]
            })
            
            map.on('click',function(e){
                map.remove([marker])
                marker = new AMap.Marker({
                    icon:'https://a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-default.png',
                    position:[e.lnglat.lng,e.lnglat.lat],
                    offset:new AMap.Pixel(-10,-20)
                });
                
                map.add([marker]);
            })
            
        </script>
    </body>
</html>

 

Guess you like

Origin www.cnblogs.com/rickdiculous/p/11431603.html