精华内容
下载资源
问答
  • InfoWindow

    2017-06-28 14:47:39
    自定义arcgis api for javascript窗口的样式
  • 可以在地图上显示多个InfoWindow框架 这个框架可以在地图上的marker上显示多个infoWindow(高德默认只能同时显示一个infoWindow) 效果图如下: 使用 !!!!! 请在使用前 将高德地图的sdk加到工程中 allprojects { ...
  • 高德地图自定义infowindow,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
  • 无法在infowindow里面添加的div进行绑定事件处理,官方的API,发现了google.maps.InfoWindow下面的Events里面有个domready事件
  • 百度地图创建InfoWindow自定义View显示-附件资源
  • 方法一: function popup() { $(.esriPopup .titlePane).css({ 'background-color':'rgba(64,64,64,0.8)' }) $(.esriPopup .contentPane).css({ 'background-color':'rgba(64,64,64,0.8)', ...
  • 百度InfoWindow实现的demo有详细注释,看不懂代码可以下载这个demo自己调试
  • SuperMap iClient 示例演示了在地图上同时显示多个InfoWindow
  • 百度地图上展示多个marker的同时,能展示多个infowindow,避免只有最后一个infowindow能展示的问题。 博客地址:http://blog.csdn.net/qq_19666821/article/details/70195267
  • 示范使用SuperMap iClient 6R for Flex开发模式,通过设置InfoWindow 类的各种Styles属性,自定义信息窗InfoWindow样式。
  • arcgis javascript中自定义infowindow实现,包含infowindow.js和infowindow.css和一个测试用的html页面,通过继承InfoWindowBase来实现
  • arcgis 自定义infowindow

    2018-08-28 09:42:51
    自定义的infowindow,想弹几个弹几个,不受约束,源码支持修改
  • Arcgis API for js自定义InfoWindow

    千次下载 热门讨论 2014-05-28 13:29:27
    Arcgis API for js自定义InfoWindow
  • 学习笔记,方便以后查阅。 添加可以拖拽的图钉。这次采用超图本身的接口。Pushpin和InfoWindow类。
  • 代码为博客实例代码:http://blog.csdn.net/lmj623565791/article/details/37737213 有问题请博客中留言
  • infowindow应用

    2020-12-18 14:38:57
    map.infoWindow.setContent( '' + "XCoord : " +attributes.XCoord +'' ); map.infoWindow.show(evt.mapPoint, map.getInfoWindowAnchor(evt.screenPoint)); }; 3.隐藏弹出框; map.infoWindow.hide(); 4....
    1.从后台获取数据后,循环时对每个要素进行属性设置;
    hexfeature.setAttributes( {"XCoord":111,"YCoord":222,"Plant":"Mesa Mint"});
    2.将要素添加到要素图层上,当点击要素图层时,响应点击事件,点击后弹出弹出框;
    var showInfowindow= hexlayer.on("click",addInfo);
     function addInfo(evt){
            var attributes=evt.graphic.attributes;
                    map.infoWindow.setTitle("Coordinates");
                    map.infoWindow.setContent(
                        '<div style="background-color:lightblue;color:white;">' +
                      "XCoord : " +attributes.XCoord +'</div>'
                    );
                    map.infoWindow.show(evt.mapPoint, map.getInfoWindowAnchor(evt.screenPoint));
                };
    3.隐藏弹出框;
    map.infoWindow.hide();
    4.解除弹出框绑定事件;
    showInfowindow.remove();

     

    展开全文
  • 几步实现高德地图自定义InfoWindow

    千次阅读 2018-06-20 17:24:18
    高德的地图显示,定位,再到根据后台给你的经纬度在地图上标记Marker,以及Marker的点击事件,以及Marker的InfoWindow,还有导航等 都有,这篇文章主要是讲InfoWindow的。 我会贴出全部代码 ,供大家参考。 先看效果...

    最近做地图相关的比较多,对照着高德开发者文档,发现如果要实现定位,mark,地图显示等多种功能的时候,很多代码都是重复的,而且每个部分的教程里用到的代码对象名称都不一样,比如同样是MapView,有的是aMapView,有的是mapView,这对于新手来说看起来很头疼啊,对着写到一半,发现同一个对象,名称换了,所以不如百度搜了一些资料。自己亲自测试过,这里整理编辑给大家,高德的地图显示,定位,再到根据后台给你的经纬度在地图上标记Marker,以及Marker的点击事件,以及Marker的InfoWindow,还有导航等都有,这篇文章主要是讲InfoWindow的。我会贴出全部代码,供大家参考。

    先看效果:


    首先,肯定是按照自己的文件包名去注册key,然后在清单文件Mainfest里面去注册service和key,以及权限啦!标红的为需要申请的部分

    
        <!--//地图包、搜索包需要的基础权限-->
        <!--允许程序打开网络套接字-->
        <uses-permission android:name="android.permission.INTERNET" />
        <!--允许程序设置内置sd卡的写权限-->
        <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
        <!--允许程序获取网络状态-->
        <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
        <!--允许程序访问WiFi网络信息-->
        <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
        <!--允许程序读写手机状态和身份-->
        <uses-permission android:name="android.permission.READ_PHONE_STATE" />
        <!--允许程序访问CellID或WiFi热点来获取粗略的位置-->
        <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
        <uses-permission android:name="android.permission.CALL_PHONE"/>
        <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
    
        <application
            android:name=".base.BaseApplication"
           >
            <meta-data
                android:name="com.amap.api.v2.apikey"
                android:value="XXXXXXXXXXXXXXXXXXXXXXXXXXX">//开发者申请的key
            </meta-data>
    
            <activity android:name=".MainActivity">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
    
            <!--高德地图定位服务-->
            <service android:name="com.amap.api.location.APSService"/>
    
        </application>
    
    </manifest>
    然后先来写布局:view_infowindow
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="horizontal"
        android:layout_width="wrap_content"
        android:layout_height="127dp"
        android:background="#0000"
        >
        <LinearLayout
            android:layout_width="209dp"
            android:layout_height="127dp"
            android:orientation="vertical"
            android:background="@drawable/inforwindow_bg">
    
            <TextView
                android:id="@+id/name"
                android:layout_marginLeft="14dp"
                android:layout_marginRight="14dp"
                android:layout_marginTop="11dp"
                android:layout_width="match_parent"
                android:layout_height="20dp"
                android:textSize="14sp"
                android:textColor="@color/black_text"/>
    
            <TextView
                android:id="@+id/addr"
                android:layout_marginLeft="14dp"
                android:layout_marginRight="14dp"
                android:layout_marginTop="2dp"
                android:layout_width="match_parent"
                android:layout_height="34dp"
                android:textSize="12sp"
                android:lines="2"
                android:ellipsize="end"
                android:textColor="#3d3d3d"/>
    
            <View
                android:layout_marginLeft="6dp"
                android:layout_marginRight="6dp"
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:layout_marginTop="9dp"
                android:background="#DFDFDF"/>
    
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">
                <LinearLayout
                    android:layout_marginTop="9dp"
                    android:id="@+id/navigation_LL"
                    android:layout_width="0dp"
                    android:layout_weight="1"
                    android:layout_height="wrap_content"
                    >
                    <ImageView
                        android:layout_marginLeft="27dp"
                        android:layout_width="17dp"
                        android:layout_height="18dp"
                        android:scaleType="centerCrop"
                        android:src="@drawable/inforwindow_navigation"/>
                    <TextView
                        android:layout_marginLeft="10dp"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="@string/infowindow_navigation"
                        android:textSize="14sp"
                        android:textColor="@color/black_text"/>
                </LinearLayout>
    
                <View
                    android:layout_width="1dp"
                    android:layout_height="30dp"
                    android:layout_marginTop="5dp"
                    android:layout_marginBottom="13dp"
                    android:background="#DFDFDF"/>
    
                <LinearLayout
                    android:layout_marginTop="9dp"
                    android:id="@+id/call_LL"
                    android:layout_width="0dp"
                    android:layout_weight="1"
                    android:layout_height="wrap_content"
                    >
    
                    <ImageView
                        android:layout_marginLeft="23dp"
                        android:layout_width="19dp"
                        android:layout_height="18dp"
                        android:scaleType="centerCrop"
                        android:src="@drawable/inforwindow_call"/>
                    <TextView
                        android:layout_marginLeft="10dp"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="@string/infowindow_call"
                        android:textSize="14sp"
                        android:textColor="@color/black_text"/>
                </LinearLayout>
    
            </LinearLayout>
    
        </LinearLayout>
    
         <!--用来偏移inforwindow的位置-->
        <TextView
            android:layout_width="38dp"
            android:layout_height="match_parent" />
    
    </LinearLayout>

    activity_main,这里要说明的是我导入的是高德2d的定位的包,不是仅仅显示地图的那个包哦……

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context="teprinciple.yang.amapinforwindowdemo.MainActivity">
    
        <com.amap.api.maps2d.MapView
            android:id="@+id/mapView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>
    </RelativeLayout>
    
    好了,下面进行写代码。

    实体类Marker和Constant

    
    public class Marker {
    
        private String name;
        private String address;
    
        public String getName() {
            return name;
        }
    
        public void setName(String name) {
            this.name = name;
        }
    
        public String getAddress() {
            return address;
        }
    
        public void setAddress(String address) {
            this.address = address;
        }
    }
    
    public class Constant {
    
        //武汉的经纬度
        public static final LatLng WUHAN = new LatLng(30.49473, 114.163954);
    }
    
    BaseApplication
    import android.app.Application;
    
    public class BaseApplication extends Application {
    
        private static BaseApplication mApplication;
    
    
        @Override
        public void onCreate() {
            super.onCreate();
            mApplication = this;
    
        }
    
        public static BaseApplication getIntance() {
            return mApplication;
        }
    
    }
    BaseActivity
    package teprinciple.yang.amapinforwindowdemo.base;
    
    import android.annotation.TargetApi;
    import android.os.Build;
    import android.os.Bundle;
    import android.support.annotation.IdRes;
    import android.support.v7.app.AppCompatActivity;
    import android.view.View;
    import android.view.Window;
    import android.view.WindowManager;
    
    
    public class BaseActivity extends AppCompatActivity implements View.OnClickListener{
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
        }
    
        public View initV(@IdRes int id) {
            return findViewById(id);
        }
    
        public View initVclick(@IdRes int id) {
            View view = initV(id);
            view.setOnClickListener(this);
            return view;
        }
    
        @Override
        public void onClick(View view) {
    
        }
    
    
    
    }
    

    动态申请权限类CheckPermissionsActivity

    
    
    import android.Manifest;
    import android.app.Activity;
    import android.app.AlertDialog;
    import android.content.DialogInterface;
    import android.content.Intent;
    import android.content.pm.PackageManager;
    import android.net.Uri;
    import android.provider.Settings;
    import android.support.v4.app.ActivityCompat;
    import android.support.v4.content.ContextCompat;
    import android.support.v7.app.AppCompatActivity;
    import android.view.KeyEvent;
    
    
    import java.util.ArrayList;
    import java.util.List;
    
    import teprinciple.yang.amapinforwindowdemo.R;
    import teprinciple.yang.amapinforwindowdemo.base.BaseActivity;
    
    
    public class CheckPermissionsActivity extends BaseActivity
    		implements
    			ActivityCompat.OnRequestPermissionsResultCallback {
    	/**
    	 * 需要进行检测的权限数组
    	 */
    	protected String[] needPermissions = {
    			Manifest.permission.ACCESS_COARSE_LOCATION,
    			Manifest.permission.ACCESS_FINE_LOCATION,
    			Manifest.permission.WRITE_EXTERNAL_STORAGE,
    			Manifest.permission.READ_EXTERNAL_STORAGE,
    			Manifest.permission.READ_PHONE_STATE
    			};
    	
    	private static final int PERMISSON_REQUESTCODE = 0;
    	
    	/**
    	 * 判断是否需要检测,防止不停的弹框
    	 */
    	private boolean isNeedCheck = true;
    	
    	@Override
    	protected void onResume() {
    		super.onResume();
    		if(isNeedCheck){
    			checkPermissions(needPermissions);
    		}
    	}
    	
    	/**
    	 * 
    	 * @since 2.5.0
    	 *
    	 */
    	private void checkPermissions(String... permissions) {
    		List<String> needRequestPermissonList = findDeniedPermissions(permissions);
    		if (null != needRequestPermissonList
    				&& needRequestPermissonList.size() > 0) {
    			ActivityCompat.requestPermissions(this,
    					needRequestPermissonList.toArray(
    							new String[needRequestPermissonList.size()]),
    					PERMISSON_REQUESTCODE);
    		}
    	}
    
    	/**
    	 * 获取权限集中需要申请权限的列表
    	 * 
    	 * @param permissions
    	 * @return
    	 * @since 2.5.0
    	 *
    	 */
    	private List<String> findDeniedPermissions(String[] permissions) {
    		List<String> needRequestPermissonList = new ArrayList<String>();
    		for (String perm : permissions) {
    			if (ContextCompat.checkSelfPermission(this,
    					perm) != PackageManager.PERMISSION_GRANTED) {
    				needRequestPermissonList.add(perm);
    			} else {
    				if (ActivityCompat.shouldShowRequestPermissionRationale(
    						this, perm)) {
    					needRequestPermissonList.add(perm);
    				} 
    			}
    		}
    		return needRequestPermissonList;
    	}
    
    	/**
    	 * 检测是否说有的权限都已经授权
    	 * @param grantResults
    	 * @return
    	 * @since 2.5.0
    	 *
    	 */
    	private boolean verifyPermissions(int[] grantResults) {
    		for (int result : grantResults) {
    			if (result != PackageManager.PERMISSION_GRANTED) {
    				return false;
    			}
    		}
    		return true;
    	}
    
    	@Override
    	public void onRequestPermissionsResult(int requestCode,
    		String[] permissions, int[] paramArrayOfInt) {
    		if (requestCode == PERMISSON_REQUESTCODE) {
    			if (!verifyPermissions(paramArrayOfInt)) {
    				showMissingPermissionDialog();
    				isNeedCheck = false;
    			}
    		}
    	}
    
    
        private void showMissingPermissionDialog() {
    //    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    //    builder.setTitle(R.string.notifyTitle);
    //    builder.setMessage(R.string.notifyMsg);
    //
    //    // 拒绝, 退出应用
    //    builder.setNegativeButton(R.string.cancel,
    //          new DialogInterface.OnClickListener() {
    //             @Override
    //             public void onClick(DialogInterface dialog, int which) {
    //                finish();
    //             }
    //          });
    //
    //    builder.setPositiveButton(R.string.setting,
    //          new DialogInterface.OnClickListener() {
    //             @Override
    //             public void onClick(DialogInterface dialog, int which) {
    //                startAppSettings();
    //             }
    //          });
    //
    //    builder.setCancelable(false);
    //
    //    builder.show();
       }
    /** * 启动应用的设置 * * @since 2.5.0 * */private void startAppSettings() {Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);intent.setData(Uri.parse("package:" + getPackageName()));startActivity(intent);}@Overridepublic boolean onKeyDown(int keyCode, KeyEvent event) {if(keyCode == KeyEvent.KEYCODE_BACK){this.finish();return true;}return super.onKeyDown(keyCode, event);}}
    跳转到高德地图进行导航的工具类
    NavigationUtils
    
    
    
    
    import android.content.Context;
    import android.content.Intent;
    import android.net.Uri;
    import android.widget.Toast;
    
    import com.amap.api.maps2d.model.LatLng;
    
    import java.io.File;
    
    import teprinciple.yang.amapinforwindowdemo.base.BaseApplication;
    
    
    /**
     * Created by Teprinciple on 2016/8/22.
     * 跳转到高德地图进行导航
     */
    public class NavigationUtils {
    
        private static Context mContext;
    
        public static void Navigation(LatLng latLng){
            mContext = BaseApplication.getIntance().getBaseContext();
    
    
            if(isInstallPackage("com.autonavi.minimap")){
    //            Toast.makeText(getContext(), "安装有高德地图", Toast.LENGTH_SHORT).show();
                SkipToGD(latLng);
            }else {
                Toast.makeText(mContext, "请下载安装高德地图", Toast.LENGTH_SHORT).show();
                DownloadMapApp();
            }
        }
    
        /**
         * 到应用市场下载高德地图app
         */
        private static void DownloadMapApp() {
            //显示手机上所有的market商店
            Uri uri = Uri.parse("market://details?id=com.autonavi.minimap");
            Intent intent = new Intent(Intent.ACTION_VIEW, uri);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            mContext.startActivity(intent);
        }
    
        /**
         * 判断是否安装 高德地图app
         * @param packageName
         * @return
         */
        private static boolean isInstallPackage(String packageName) {
            return new File("/data/data/" + packageName).exists();
        }
    
        /**
         * 跳转到高德地图进行导航
         */
        private static void SkipToGD(LatLng latLng) {
            //跳转导航
            //dev 是否偏移(0:lat 和 lon 是已经加密后的,不需要国测加密; 1:需要国测加密)
            //style 导航方式(0 速度快; 1 费用少; 2 路程短; 3 不走高速;4 躲避拥堵;
            // 5 不走高速且避免收费;6 不走高速且躲避拥堵;7 躲避收费和拥堵;8 不走高速躲避收费和拥堵))
            Uri uri = Uri.parse("androidamap://navi?sourceApplication=CloudPatient&lat="+latLng.latitude+"&lon="+latLng.longitude+"&dev=1&style=2");
            Intent intent = new Intent("android.intent.action.VIEW", uri);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            mContext.startActivity(intent);
        }
    }
    
    打电话工具类
    PhoneCallUtils
    package teprinciple.yang.amapinforwindowdemo.utils;
    
    import android.content.Context;
    import android.content.Intent;
    import android.net.Uri;
    import android.text.TextUtils;
    
    import teprinciple.yang.amapinforwindowdemo.base.BaseApplication;
    
    
    /**
     * Created by Teprinciple on 2016/8/22.
     * 打电话工具类
     */
    public class PhoneCallUtils {
        private static Context mContext  = BaseApplication.getIntance().getBaseContext();;
        public static void call(String phoneNum){
    
            if (TextUtils.isEmpty(phoneNum)){ //电话号码为空
                return;
            }
    
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_CALL);
            Uri uri = Uri.parse("tel:"+phoneNum);   //设置要操作界面的具体内容  拨打电话固定格式: tel:
            intent.setData(uri);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            mContext.startActivity(intent);
        }
    }
    
    重点来了,InfoWinAdapter,用来显示这个infowindow的数据的
    
    
    import android.content.Context;
    import android.support.annotation.NonNull;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.widget.LinearLayout;
    import android.widget.TextView;
    
    import com.amap.api.maps2d.AMap;
    import com.amap.api.maps2d.model.LatLng;
    import com.amap.api.maps2d.model.Marker;
    
    import teprinciple.yang.amapinforwindowdemo.base.BaseApplication;
    import teprinciple.yang.amapinforwindowdemo.R;
    import teprinciple.yang.amapinforwindowdemo.utils.NavigationUtils;
    import teprinciple.yang.amapinforwindowdemo.utils.PhoneCallUtils;
    
    
    /**
     * Created by Teprinciple on 2016/8/23.
     * 地图上自定义的infowindow的适配器
     */
    public class InfoWinAdapter implements AMap.InfoWindowAdapter, View.OnClickListener {
        private Context mContext = BaseApplication.getIntance().getBaseContext();
        private LatLng latLng;
        private LinearLayout call;
        private LinearLayout navigation;
        private TextView nameTV;
        private String agentName;
        private TextView addrTV;
        private String snippet;
    
        @Override
        public View getInfoWindow(Marker marker) {
            initData(marker);
            View view = initView();
            return view;
        }
        @Override
        public View getInfoContents(Marker marker) {
            return null;
        }
    
        private void initData(Marker marker) {
            latLng = marker.getPosition();
            snippet = marker.getSnippet();
            agentName = marker.getTitle();
        }
    
        @NonNull
        private View initView() {
            View view = LayoutInflater.from(mContext).inflate(R.layout.view_infowindow, null);
            navigation = (LinearLayout) view.findViewById(R.id.navigation_LL);
            call = (LinearLayout) view.findViewById(R.id.call_LL);
            nameTV = (TextView) view.findViewById(R.id.name);
            addrTV = (TextView) view.findViewById(R.id.addr);
    
            nameTV.setText(agentName);
            addrTV.setText(String.format(mContext.getString(R.string.agent_addr),snippet));
    
            navigation.setOnClickListener(this);
            call.setOnClickListener(this);
            return view;
        }
    
    
        @Override
        public void onClick(View v) {
            int id = v.getId();
            switch (id){
                case R.id.navigation_LL:  //点击导航
                    NavigationUtils.Navigation(latLng);
                    break;
    
                case R.id.call_LL:  //点击打电话
                    PhoneCallUtils.call("10086"); //TODO 处理电话号码
                    break;
            }
        }
    
    }
    
    最后
    MainActivity
    
    
    import android.graphics.Color;
    import android.os.Bundle;
    import android.util.Log;
    
    import com.amap.api.location.AMapLocation;
    import com.amap.api.location.AMapLocationClient;
    import com.amap.api.location.AMapLocationClientOption;
    import com.amap.api.location.AMapLocationListener;
    import com.amap.api.maps2d.AMap;
    import com.amap.api.maps2d.CameraUpdateFactory;
    import com.amap.api.maps2d.LocationSource;
    import com.amap.api.maps2d.MapView;
    import com.amap.api.maps2d.UiSettings;
    import com.amap.api.maps2d.model.BitmapDescriptorFactory;
    import com.amap.api.maps2d.model.LatLng;
    import com.amap.api.maps2d.model.Marker;
    import com.amap.api.maps2d.model.MarkerOptions;
    import com.amap.api.maps2d.model.MyLocationStyle;
    
    import teprinciple.yang.amapinforwindowdemo.adapter.InfoWinAdapter;
    import teprinciple.yang.amapinforwindowdemo.base.BaseActivity;
    import teprinciple.yang.amapinforwindowdemo.entity.Constant;
    import teprinciple.yang.amapinforwindowdemo.utils.CheckPermissionsActivity;
    
    public class MainActivity extends CheckPermissionsActivity implements AMap.OnMapClickListener, AMap.OnMarkerClickListener, AMapLocationListener, LocationSource {
    
        private MapView mapView;
        //声明AMapLocationClient类对象
        public AMapLocationClient mLocationClient;
        //声明AMapLocationClientOption对象
        private AMapLocationClientOption mLocationOption;
        private AMap aMap;
        private UiSettings uiSettings;
        private InfoWinAdapter adapter;
        private Marker oldMarker;
        private OnLocationChangedListener mListener;
        private LatLng myLatLng;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            initView();
            //在执行onCreateView时执行mMapView.onCreate(savedInstanceState),实现地图生命周期管理
            mapView.onCreate(savedInstanceState);
            initMap();
            initLocation();
        }
    
        private void initView() {
            mapView = (MapView) initV(R.id.mapView);
        }
    
    
        /**
         * 初始化地图
         */
        private void initMap() {
            if (aMap == null) {
                aMap = mapView.getMap();
                uiSettings = aMap.getUiSettings();
                aMap.setOnMapClickListener(this);
            }
            uiSettings.setZoomControlsEnabled(false); //隐藏缩放控件
            //自定义InfoWindow
            aMap.setOnMarkerClickListener(this);
            adapter = new InfoWinAdapter();
            aMap.setInfoWindowAdapter(adapter);
    
            addMarkerToMap(Constant.WUHAN,"武汉","中国湖北省武汉市蔡甸区");
        }
    
    
        /**
         * 初始化定位
         */
        private void initLocation(){
            // 自定义系统定位小蓝点--我的位置
            MyLocationStyle myLocationStyle = new MyLocationStyle();
            myLocationStyle.myLocationIcon(BitmapDescriptorFactory
                    .fromResource(R.drawable.mylocation));// 设置小蓝点的图标
            myLocationStyle.strokeColor(getResources().getColor(R.color.blue));// 设置圆形的边框颜色
            myLocationStyle.radiusFillColor(Color.argb(100, 29, 161, 242));// 设置圆形的填充颜色
            myLocationStyle.strokeWidth(1.0f);// 设置圆形的边框粗细
    //        myLocationStyle.strokeColor(Color.argb(0, 0, 0, 0));
    //        myLocationStyle.radiusFillColor(Color.argb(0, 0, 0, 0));
            aMap.setMyLocationStyle(myLocationStyle);
            aMap.setLocationSource(this);// 设置定位资源。如果不设置此定位资源则定位按钮不可点击。并且实现activate激活定位,停止定位的回调方法
            aMap.getUiSettings().setMyLocationButtonEnabled(true);// 设置默认定位按钮是否显示
            aMap.setMyLocationEnabled(true);// 设置为true表示显示定位层并可触发定位,false表示隐藏定位层并不可触发定位,默认是false
        }
    
    
    
        //激活定位
        //记得注册定位
        //<service android:name="com.amap.api.location.APSService"/>
        @Override
        public void activate(OnLocationChangedListener onLocationChangedListener) {
            mListener = onLocationChangedListener;
            if (mLocationClient == null) {
                mLocationClient = new AMapLocationClient(this);
                mLocationOption = new AMapLocationClientOption();
                //设置定位监听
                mLocationClient.setLocationListener(this);
                //设置为高精度定位模式
                mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
                mLocationOption.setOnceLocation(true);
                //设置是否返回地址信息(默认返回地址信息)
                mLocationOption.setNeedAddress(true);
                //设置定位参数
                mLocationClient.setLocationOption(mLocationOption);
                mLocationClient.startLocation();
            }
        }
    
        //停止定位
        @Override
        public void deactivate() {
            mListener = null;
            if (mLocationClient != null) {
                mLocationClient.stopLocation();
                mLocationClient.onDestroy();
            }
            mLocationClient = null;
        }
    
    
        @Override
        public void onResume() {
            super.onResume();
            mapView.onResume(); //管理地图的生命周期
        }
    
        @Override
        public void onPause() {
            super.onPause();
            mapView.onPause(); //管理地图的生命周期
        }
    
        @Override
        public void onDestroy() {
            super.onDestroy();
            mapView.onDestroy(); //管理地图的生命周期
        }
    
        //地图的点击事件
        @Override
        public void onMapClick(LatLng latLng) {
            //点击地图上没marker 的地方,隐藏inforwindow
            if (oldMarker != null) {
                oldMarker.hideInfoWindow();
                oldMarker.setIcon(BitmapDescriptorFactory.fromResource(R.drawable.marker_normal));
            }
        }
    
        //maker的点击事件
        @Override
        public boolean onMarkerClick(Marker marker) {
    
            if (!marker.getPosition().equals(myLatLng)){ //点击的marker不是自己位置的那个marker
                if (oldMarker != null) {
                    oldMarker.setIcon(BitmapDescriptorFactory.fromResource(R.drawable.marker_normal));
                }
                oldMarker = marker;
                marker.setIcon(BitmapDescriptorFactory.fromResource(R.drawable.marker_selected));
            }
    
            return false; //返回 “false”,除定义的操作之外,默认操作也将会被执行
        }
    
        //定位成功的监听
        @Override
        public void onLocationChanged(AMapLocation aMapLocation) {
    
            if (aMapLocation != null) {
    
                if(mListener != null){
    //                aMap.clear();  清除之前的marker
                    mListener.onLocationChanged(aMapLocation);// 显示系统小蓝点-我的位置
                }
    
                if (aMapLocation.getErrorCode() == 0) {
                    myLatLng = new LatLng(aMapLocation.getLatitude(), aMapLocation.getLongitude());
                    aMap.moveCamera(CameraUpdateFactory.newLatLngZoom(myLatLng, 14));
                    String city = aMapLocation.getCity();
                    String address = aMapLocation.getAddress();
    //                addMarkerToMap(latLng,city,address);
                } else {
                    //定位失败时,可通过ErrCode(错误码)信息来确定失败的原因,errInfo是错误信息,详见错误码表。
                    Log.e("AmapError", "location Error, ErrCode:" + aMapLocation.getErrorCode() + ", errInfo:"
                            + aMapLocation.getErrorInfo());
                }
            }
        }
    
        private void addMarkerToMap(LatLng latLng, String title, String snippet) {
            aMap.addMarker(new MarkerOptions().anchor(0.5f, 0.5f)
                    .position(latLng)
                    .title(title)
                    .snippet(snippet)
                    .icon(BitmapDescriptorFactory.fromResource(R.drawable.marker_normal))
            );
        }
    
    }
    

    
    好了,所有代码都已经公布啦,这里感谢简书的Teprinciple老师
    



    附上老师项目链接:https://github.com/teprinciple/AMapInfoWindowDemo




    展开全文
  • // 设置label markerMC.setLabel({ offset: new AMap.Pixel(20, -10), content: 'label内容' }) // 可配合marker点击方法传入相关参数 function markerClickMC(e) { var infoWindowMenci = new AMap.InfoWindow({ is...
    
    // 创建一个marker 在地图上显示
                  var markerMC = new AMap.Marker({
                    icon: '',//图标
                    title:'',//标题
                    position: ['经度','纬度'],
                    map: map
                  });
                  markerMC.content = `自定义marker内容`;
                  markerMC.on('click', markerClickMC);//点击marker点调用方法
                  // markerMC.emit('click', {   : markerMC });默认点击
    
    // 设置label
                  markerMC.setLabel({
                      offset: new AMap.Pixel(20, -10),
                      content: 'label内容'
                    })
    
    
    
    // 可配合marker点击方法传入相关参数
        function markerClickMC(e) {
          var infoWindowMenci = new AMap.InfoWindow({
            isCustom: true,//启用自定义窗体
            content: InfoWindowMC(e.target.content),//调用窗体方法 传入html字符串
            offset: new AMap.Pixel(0, -30)//信息窗偏移
          });
          // 设置了infowindows content就不能显示自定义信息窗体?
          // infoWindowMenci.setContent(e.target.content);
          infoWindowMenci.open(map, e.target.getPosition());//打开信息窗
        }
    
    
    
    //构建自定义信息窗体
    function InfoWindowMC(cont) {
      // cont自定义内容 html字符串
      var info = document.createElement("div");
        info.className = "custom-info input-card content-window-card";
    
        //可以通过下面的方式修改自定义窗体的宽高
        //info.style.width = "400px";
        // 定义顶部标题
        var top = document.createElement("div");
        var titleD = document.createElement("div");
        var closeX = document.createElement("img");
        top.className = "info-top";
        // titleD.innerHTML = title;
        closeX.src = "https://webapi.amap.com/images/close2.gif";
        closeX.style.float='right'
        closeX.onclick = closeInfoWindow;
    
        top.appendChild(titleD);
        top.appendChild(closeX);
        info.appendChild(top);
    
        // 定义中部内容
        var middle = document.createElement("div");
        middle.className = "info-middle";
        middle.style.backgroundColor = '';
        middle.innerHTML = cont;
        info.appendChild(middle);
    
        // 定义底部内容
        var bottom = document.createElement("div");
        bottom.className = "info-bottom";
        bottom.style.position = 'relative';
        bottom.style.top = '0px';
        bottom.style.margin = '0 auto';
        var sharp = document.createElement("img");
        sharp.src = "";
        bottom.appendChild(sharp);
        info.appendChild(bottom);
        return info;
    }

    // 点击关闭信息窗体
    function closeInfoWindow() {
        map.clearInfoWindow();
    }

    展开全文
  • 百度地图V3.6.0系列——覆盖物和InfoWindow的使用
  • vue给InfoWindow添加按钮绑定事件

    千次阅读 2019-09-20 17:40:37
    info[i] = new BMap.InfoWindow(content) info[i].addEventListener("click", function() { this.buttonClick(device.id) }); marker[i].addEventListener('click', function() { this.openInfoWindow(info[i]...

    在这里插入图片描述

    点击测试修改创建时间

    关键在于market监听click,还要监听infowindowopen
    marker[i].addEventListener(‘click’, function() {
    this.openInfoWindow(info[i])//悬浮监听提示方法
    })
    marker[i].addEventListener(‘infowindowopen’,function() {XXX})
    下面是完整代码

    <template>
      <baidu-map
        class="map"
        :center="center"
        :zoom="zoom"
        :scroll-wheel-zoom="true"
        @click="clickPoint"
        @moving="syncCenterAndZoom"
        @moveend="syncCenterAndZoom"
        @zoomend="syncCenterAndZoom"
        @ready="handler">
        <!--地图类型-->
        <bm-map-type :map-types="['BMAP_NORMAL_MAP', 'BMAP_SATELLITE_MAP']" anchor="BMAP_ANCHOR_TOP_RIGHT"></bm-map-type>
        <!--缩放-->
        <!--<bm-navigation anchor="BMAP_ANCHOR_TOP_RIGHT"></bm-navigation>-->
        <!--定位当前位置-->
        <bm-geolocation anchor="BMAP_ANCHOR_BOTTOM_RIGHT" :showAddressBar="true" :autoLocation="true"></bm-geolocation>
        <bm-marker :position="center" :dragging="false"></bm-marker>
      </baidu-map>
    </template>
    <script>
      import { httpAction ,getAction } from '@/api/manage'
    
      export default {
        data() {
          return {
            center: { lng: 0, lat: 0 },
            zoom: 3,
            devices: [],
            active: false,
            BMap: '',
            map: '',
            url: {
              list: '/map/myMap/list',
              test: '/map/myMap/test',
            }
          }
        },
        mounted() {
          this.loadData()
        },
        watch: {
        //监听devices,不监听的话只有第一次进入页面会渲染图标,之后addMarket在loadData之前,导致devices没有数据
          devices: function(devices, old) {
            let that = this
            this.addMarket({ BMap: that.BMap, map: that.map })
          },
        },
        methods: {
          loadData() {
            getAction(this.url.list).then((res) => {
              if (res.success) {
                this.devices = res.result.records
                console.log(this.devices)
              } else {
                that.$message.warning(res.message)
              }
            })
          },
          draw({ BMap, map, el }) {
            const pixel = map.pointToOverlayPixel(new BMap.Point(114.42993, 30.475798))
            el.style.left = pixel.x - 10 + 'px'
            el.style.top = pixel.y - 10 + 'px'
          },
          handler({ BMap, map }) {
            this.BMap = BMap
            this.map = map
            console.log('handler')
            this.center.lng = 114.429211
            this.center.lat = 30.477168
            this.zoom = 14
            //不添加的话第一次进入页面没有
            this.addMarket({ BMap, map })
          },
          addMarket({ BMap, map }) {
            let that = this;
            console.log('addMarket')
            let point = new Array()//定义数组标注经纬信息
            let marker = new Array()//定义数组点对象信息
            let info = new Array()//定义悬浮提示信息
            let myIcon = new Array()//定义数组图标
            //根据自己需求设置图片
            myIcon[0] = new BMap.Icon('http://aaa.png', new BMap.Size(25, 25))
            myIcon[1] = new BMap.Icon('http://bbb.png', new BMap.Size(25, 25))
            myIcon[2] = new BMap.Icon('http://ccc.png', new BMap.Size(25, 25))
            console.log(this.devices.length)
            for (let i = 0; i < this.devices.length; i++) {
              let device = this.devices[i]
              point[i] = new BMap.Point(device.lng, device.lat)
              marker[i] = new BMap.Marker(point[i])
              map.addOverlay(marker[i])
              /*var label = new BMap.Label(device.remark,{offset: new BMap.Size(10,-10)});
              marker[i].setLabel(label);*/
              let type = device.type
              marker[i].setIcon(myIcon[type - 1])
              //设置信息窗口
              let content = '<table>'
                + `<tr><td> 经度:${device.lng}</td></tr>`
                +`<tr><td> 纬度:${device.lat}</td></tr>`
                +`<tr><td> 设备类型:${device.type }</td></tr>`
                +`<tr><td id="time${device.id}"> 创建时间:${device.createTime }</td></tr>`
                //预留id绑定事件,直接写onclick无效
                +`<tr><td><button id="${device.id}">测试</button></td></tr>`
                +`</table>`;
              info[i] = new BMap.InfoWindow(content)
              info[i].addEventListener("click",  function() {
                this.buttonClick(device.id)
              });
              marker[i].addEventListener('click', function() {
                this.openInfoWindow(info[i])//悬浮监听提示方法
              })
              //监听信息窗打开,打开的时候才能根据之前设置id获取元素,不然实际上页面没有这个元素
              marker[i].addEventListener('infowindowopen',function() {
                let id = device.id
                if (document.getElementById(id)){
                  document.getElementById(id).addEventListener("click", function() {
                  //简单的测试方法,修改了createTime
                    httpAction(that.url.test,{id:id},"put").then((res) => {
                      if (res.success) {
                        console.log(res)
                        that.$message.warning(res.message)
                        更新信息显示窗口,实际开发中还要更改this.devices
                        document.getElementById(`time${id}`).innerText = `创建时间:${res.result.createTime}`
                      } else {
                        that.$message.warning(res.message)
                      }
                    })
                  })
                }else {
                  console.log("else")
                }
              })
            }
          },
    
          clickPoint(e) {
            console.log(e.point)
          },
          syncCenterAndZoom(e) {
            const { lng, lat } = e.target.getCenter()
            this.center.lng = lng
            this.center.lat = lat
            this.zoom = e.target.getZoom()
          }
        }
      }
    </script>
    <style>
      .map {
        height: 500px;
      }
      
      .BMap_cpyCtrl {
        display: none !important;
      }
    
      .anchorBL {
        display: none !important;
      }
    
      div.main {
        margin: -12px -12px 0px;
      }
    </style>
    
    展开全文
  • <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8">...meta content="width=device-width,initial-scale=1.0,maxi...
  •  var infoWindowSpotYes = new AMap.InfoWindow({  content: "<div class='tr_title'><div class='tit'>" + clouddata.title + "</div></div>" +  "<div class='tr_winImg'><img src=" + clouddata.img + ">" +...
  • esri infowindow 样式修改与格式化定制

    千次阅读 2018-09-29 17:01:31
    要使用带有infoWindow内容的延迟,您必须使用实例esri/dijit/InfoWindow作为地图的infoWindow,或者监听地图单击事件,启动异步操作,然后调用Popup.setContent()以及Popup.setTitle()何时完成异步操作。 单击地图...
  • 在使用高德地图做地图相关开发时,经常会使用到标记点marker功能,如果业务较复杂,标记点需要增加自定义的信息窗口infoWindow,自定义信息窗口支持传入content参数,content 可以是 dom 对象,也可以是 html 识别的...
  • 笔者自定义的infoWindow效果如图 图中的infoWindow背景用的是图片,自定义infoWindow用到的主要方法如下 @Override public View getInfoContents(Marker arg0) { return null; } /** * 监听自定义...
  • 如图: 如果想设备Infowindow相对于点标记的位置时,可以在创建时就通过offset设置偏移量。 具体设置如下图,第一位数字表示左右偏移量,第二位数字表示上下偏移量;

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 6,148
精华内容 2,459
关键字:

infowindow