第19行: |
第19行: |
| <html> | | <html> |
| <head> | | <head> |
− | <meta charset="utf-8">
| + | <meta charset="utf-8"> |
− | <meta name="keywords" content="高德地图,DIY地图,高德地图生成器">
| + | <meta name="keywords" content="高德地图,DIY地图,高德地图生成器"> |
− | <meta name="description" content="高德地图,DIY地图,自己制作地图,生成自己的高德地图">
| + | <meta name="description" content="高德地图,DIY地图,自己制作地图,生成自己的高德地图"> |
− | <title>高德地图 - DIY我的地图</title>
| + | <title>高德地图 - DIY我的地图</title> |
− | <style>
| + | <style> |
− | body { margin: 0; font: 100% "Microsoft YaHei", "Helvetica Neue", "Sans-Serif"; min-height: 960px; min-width: 600px; }
| + | body { margin: 0; font: 100% "Microsoft YaHei", "Helvetica Neue", "Sans-Serif"; min-height: 960px; min-width: 600px; } |
− | .my-map { margin: 0 auto; width: 600px; height: 600px; }
| + | .my-map { margin: 0 auto; width: 600px; height: 600px; } |
− | .my-map .icon { background: url(http://lbs.amap.com/console/public/show/marker.png) no-repeat; }
| + | .my-map .icon { background: url(http://lbs.amap.com/console/public/show/marker.png) no-repeat; } |
− | .my-map .icon-cir { height: 31px; width: 28px; }
| + | .my-map .icon-cir { height: 31px; width: 28px; } |
− | .my-map .icon-cir-red { background-position: -11px -5px; }
| + | .my-map .icon-cir-red { background-position: -11px -5px; } |
− | .amap-container{height: 100%;}
| + | .amap-container{height: 100%;} |
− | </style>
| + | </style> |
| </head> | | </head> |
| <body> | | <body> |
− | <div id="wrap" class="my-map">
| + | <div id="wrap" class="my-map"> |
− | <div id="mapContainer"></div>
| + | <div id="mapContainer"></div> |
− | </div>
| + | </div> |
− | <script src="http://webapi.amap.com/maps?v=1.3&key=8325164e247e15eea68b59e89200988b"></script>
| + | <script src="http://webapi.amap.com/maps?v=1.3&key=8325164e247e15eea68b59e89200988b"></script> |
− | <script>
| + | <script> |
− | !function(){
| + | !function(){ |
− | var infoWindow, map, level = 15,
| + | var infoWindow, map, level = 15, |
− | center = {lng: 113.21406, lat: 22.380806},
| + | center = {lng: 113.21406, lat: 22.380806}, |
− | features = [{type: "Marker", name: "西安渡口", desc: "", color: "red", icon: "cir", offset: {x: -9, y: -31}, lnglat: {lng: 113.217404, lat: 22.381277}},
| + | features = [{type: "Marker", name: "西安渡口", desc: "", color: "red", icon: "cir", offset: {x: -9, y: -31}, lnglat: {lng: 113.217404, lat: 22.381277}}, |
− | {type: "Marker", name: "围头渡口", desc: "", color: "red", icon: "cir", offset: {x: -9, y: -31}, lnglat: {lng: 113.213917, lat: 22.381053}},
| + | {type: "Marker", name: "围头渡口", desc: "", color: "red", icon: "cir", offset: {x: -9, y: -31}, lnglat: {lng: 113.213917, lat: 22.381053}}, |
− | {type: "Polyline", name: "西安至围头线", desc: "", strokeWeight: 5, strokeColor: "#F0202F", strokeOpacity: 0.8, lnglat: [{lng: 113.217468, lat: 22.381197}, {lng: 113.213949, lat: 22.381098}, {lng: 113.213903, lat: 22.381138}]}];
| + | {type: "Polyline", name: "西安至围头线", desc: "", strokeWeight: 5, strokeColor: "#F0202F", strokeOpacity: 0.8, lnglat: [{lng: 113.217468, lat: 22.381197}, {lng: 113.213949, lat: 22.381098}, {lng: 113.213903, lat: 22.381138}]}]; |
| | | |
− | function loadFeatures(){
| + | function loadFeatures(){ |
− | for(var feature, data, i = 0, len = features.length, j, jl, path; i < len; i++){
| + | for(var feature, data, i = 0, len = features.length, j, jl, path; i < len; i++){ |
− | data = features[i];
| + | data = features[i]; |
− | switch(data.type){
| + | switch(data.type){ |
− | case "Marker":
| + | case "Marker": |
− | feature = new AMap.Marker({ map: map, position: new AMap.LngLat(data.lnglat.lng, data.lnglat.lat),
| + | feature = new AMap.Marker({ map: map, position: new AMap.LngLat(data.lnglat.lng, data.lnglat.lat), |
− | zIndex: 3, extData: data, offset: new AMap.Pixel(data.offset.x, data.offset.y), title: data.name,
| + | zIndex: 3, extData: data, offset: new AMap.Pixel(data.offset.x, data.offset.y), title: data.name, |
− | content: '<div class="icon icon-' + data.icon + ' icon-'+ data.icon +'-' + data.color +'"></div>' });
| + | content: '<div class="icon icon-' + data.icon + ' icon-'+ data.icon +'-' + data.color +'"></div>' }); |
− | break;
| + | break; |
− | case "Polyline":
| + | case "Polyline": |
− | for(j = 0, jl = data.lnglat.length, path = []; j < jl; j++){
| + | for(j = 0, jl = data.lnglat.length, path = []; j < jl; j++){ |
− | path.push(new AMap.LngLat(data.lnglat[j].lng, data.lnglat[j].lat));
| + | path.push(new AMap.LngLat(data.lnglat[j].lng, data.lnglat[j].lat)); |
− | }
| + | } |
− | feature = new AMap.Polyline({ map: map, path: path, extData: data, zIndex: 2,
| + | feature = new AMap.Polyline({ map: map, path: path, extData: data, zIndex: 2, |
− | strokeWeight: data.strokeWeight, strokeColor: data.strokeColor, strokeOpacity: data.strokeOpacity });
| + | strokeWeight: data.strokeWeight, strokeColor: data.strokeColor, strokeOpacity: data.strokeOpacity }); |
− | break;
| + | break; |
− | case "Polygon":
| + | case "Polygon": |
− | for(j = 0, jl = data.lnglat.length, path = []; j < jl; j++){
| + | for(j = 0, jl = data.lnglat.length, path = []; j < jl; j++){ |
− | path.push(new AMap.LngLat(data.lnglat[j].lng, data.lnglat[j].lat));
| + | path.push(new AMap.LngLat(data.lnglat[j].lng, data.lnglat[j].lat)); |
− | }
| + | } |
− | feature = new AMap.Polygon({ map: map, path: path, extData: data, zIndex: 1,
| + | feature = new AMap.Polygon({ map: map, path: path, extData: data, zIndex: 1, |
− | strokeWeight: data.strokeWeight, strokeColor: data.strokeColor, strokeOpacity: data.strokeOpacity,
| + | strokeWeight: data.strokeWeight, strokeColor: data.strokeColor, strokeOpacity: data.strokeOpacity, |
− | fillColor: data.fillColor, fillOpacity: data.fillOpacity });
| + | fillColor: data.fillColor, fillOpacity: data.fillOpacity }); |
− | break;
| + | break; |
− | default: feature = null;
| + | default: feature = null; |
− | }
| + | } |
− | if(feature){ AMap.event.addListener(feature, "click", mapFeatureClick); }
| + | if(feature){ AMap.event.addListener(feature, "click", mapFeatureClick); } |
− | }
| + | } |
− | }
| + | } |
| | | |
− | function mapFeatureClick(e){
| + | function mapFeatureClick(e){ |
− | if(!infoWindow){ infoWindow = new AMap.InfoWindow({autoMove: true}); }
| + | if(!infoWindow){ infoWindow = new AMap.InfoWindow({autoMove: true}); } |
− | var extData = e.target.getExtData();
| + | var extData = e.target.getExtData(); |
− | infoWindow.setContent("<h5>" + extData.name + "</h5><div>" + extData.desc + "</div>");
| + | infoWindow.setContent("<h5>" + extData.name + "</h5><div>" + extData.desc + "</div>"); |
− | infoWindow.open(map, e.lnglat);
| + | infoWindow.open(map, e.lnglat); |
− | }
| + | } |
| | | |
− | map = new AMap.Map("mapContainer", {center: new AMap.LngLat(center.lng, center.lat), level: level});
| + | map = new AMap.Map("mapContainer", {center: new AMap.LngLat(center.lng, center.lat), level: level}); |
− | new AMap.TileLayer.RoadNet({map: map, zIndex: 2});
| + | new AMap.TileLayer.RoadNet({map: map, zIndex: 2}); |
− | loadFeatures();
| + | loadFeatures(); |
| | | |
− | map.on('complete', function(){
| + | map.on('complete', function(){ |
− | map.plugin(["AMap.ToolBar", "AMap.OverView", "AMap.Scale"], function(){
| + | map.plugin(["AMap.ToolBar", "AMap.OverView", "AMap.Scale"], function(){ |
− | map.addControl(new AMap.ToolBar);
| + | map.addControl(new AMap.ToolBar); |
− | map.addControl(new AMap.OverView({isOpen: true}));
| + | map.addControl(new AMap.OverView({isOpen: true})); |
− | map.addControl(new AMap.Scale);
| + | map.addControl(new AMap.Scale); |
− | });
| + | }); |
− | })
| + | }) |
− |
| + | |
− | }();
| + | }(); |
− | </script>
| + | </script> |
| </body> | | </body> |
| </html> | | </html> |