| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239 |
- define(['html!templates/menu/baseCalc/advancedAddressSearch',
- 'css!styles/tools/toolPublicPopup',
- 'css!styles/menu/baseCalc/advancedAddressSearch',
- ],
- function (tplLayout) {
- /**
- * 模块状态,用于存储模块的状态 例如:收起,关闭
- * @type {Object}
- */
- var status = {
- initialized: false//是否初始化
- };
- /**
- * 模块数据 用于数据存储和外部调用
- * @type {Object}
- * 数据存放
- */
- var modValue = {
- data: {},
- addressArr: [],
- pointStyle: {
- color: "#2ecc71",
- fontFillColor: "#fff000",
- labelOffset: -15,
- },
- handler: null
- };
- /**
- * 初始化并订阅事件
- * @return {[type]} [description]
- */
- function open(data) {
- if (!status.initialized) {
- setLayout();
- bindEvent();
- subscribe();
- status.initialized = true;
- } else {
- // 重置
- reset();
- }
- modValue.data = data;
- $("#advancedAddressSearchModal .title").text(data.label);
- ONEMAP.C.publisher.publish({
- modName: 'advancedAddressSearch'
- }, 'baseCalc:active');
- };
- function setLayout() {
- $('body').append(tplLayout);
- //拖拽
- $("#advancedAddressSearchModal .popup-ct").dragmove($('#advancedAddressSearchModal'));
- };
- /**
- * 事件绑定
- */
- function bindEvent() {
- $("#advancedAddressSearchModal .close").bind('click', function () {
- close();
- });
- $("#advancedAddressSearchModal .btn-default.sure").bind('click', function () {
- execute()
- });
- //回车执行
- $('#advancedAddressSearchInput, #jumpToLatInput').bind('keydown', function (e) {
- if (e.keyCode === 13) {
- execute();
- }
- });
- };
- /**
- * 注册监听
- * @type {Function}
- */
- function subscribe() {
- ONEMAP.C.publisher.subscribe(remove, 'baseCalc:active');
- };
- /**
- * 关闭模块
- * @return {[type]} [description]
- */
- function remove(options) {
- if (options.modName != 'advancedAddressSearch') {
- close();
- } else {
- $("#advancedAddressSearchModal").show();
- }
- }
- function reset() {
- $("#advancedAddressSearchForm .address").val("");
- $("#advancedAddressSearchForm .outputResult table tr").empty("")
- clearMarker();
- removeMapClickEvent();
- }
- function close() {
- $("#advancedAddressSearchModal").hide();
- reset();
- }
- // 执行
- function execute() {
- let text = $("#advancedAddressSearchForm .address").val();
- getLatLng(text);
- }
- /**
- * 获取并计算经纬度
- * @private
- */
- function getLatLng(text) {
- clearMarker();
- $.ajax({
- type: "get",
- dataType: 'json',
- url: onemapUrlConfig.PROXY_URL + "/searchByNameV3",
- data: {
- address: text,
- },
- success: function (data) {
- if (data.code == 200) {
- data.content.pois.map(function (item) {
- let lon, lat;
- item.location.split(",").map(function (num, index) {
- if (index == 0) lon = Number(num);
- if (index == 1) lat = Number(num);
- })
- modValue.addressArr.push(addMarker(lon, lat, modValue.pointStyle, item))
- })
- $("#advancedAddressSearchForm .outputResult table tr").empty()
- removeMapClickEvent();
- addMapClickEvent();
- }
- },
- error: function (error) {
- console.log(error)
- }
- });
- return;
- };
- function setOutputResult(data) {
- $("#advancedAddressSearchForm .outputResult table tr").empty()
- let html = "";
- html += "<tr><td><span>名称:</span></td><td><span>" + data.name + "</span></td></tr>"
- html += "<tr><td><span>地址:</span></td><td><span>" + data.address + "</span></td></tr>"
- if (Object.getOwnPropertyNames(data.微网格信息).length >= 3) {
- ttttt(data.微网格信息).map(function (item) {
- html += item
- })
- }
- if (Object.getOwnPropertyNames(data.村居信息).length >= 3) {
- ttttt(data.村居信息).map(function (item) {
- html += item
- })
- }
- if (Object.getOwnPropertyNames(data.网格信息).length >= 3) {
- ttttt(data.网格信息).map(function (item) {
- html += item
- })
- }
- function ttttt(obj) {
- let fieldArr = Object.getOwnPropertyNames(obj);
- let htmlArr = fieldArr.map(function (field) {
- return "<tr><td><span>" + field + ":</span></td><td><span>" + obj[field] + "</span></td></tr>"
- })
- return htmlArr;
- }
- $("#advancedAddressSearchForm .outputResult table tr").append(html);
- }
- function addMarker(lon, lat, style, info) {
- let entity = map3DViewer.map.entities.add({
- position: Cesium.Cartesian3.fromDegrees(lon, lat, 0),
- point: {
- color: Cesium.Color.fromCssColorString(style.color), //颜色
- pixelSize: 10, //大小
- outlineColor: Cesium.Color.YELLOW, //轮廓颜色
- outlineWidth: 1
- },
- type: "advancedAddressSearch",
- info: info
- // label: {
- // pixelOffset: new Cesium.Cartesian2(0, style.labelOffset),
- // text: text,
- // font: '24px',
- // fillColor: Cesium.Color.fromCssColorString(style.color)
- // }
- })
- return entity._id;
- }
- function addMapClickEvent() {
- if (modValue.handler != null) return;
- modValue.handler = new Cesium.ScreenSpaceEventHandler(map3DViewer.map.canvas);
- // 监听鼠标点击事件
- modValue.handler.setInputAction(function (click) {
- var pickedObject = map3DViewer.map.scene.pick(click.position);
- if (Cesium.defined(pickedObject) && pickedObject.id instanceof Cesium.Entity) {
- var entity = pickedObject.id;
- if (entity.type == "advancedAddressSearch") {
- let info = entity.info;
- setOutputResult(info);
- }
- }
- }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
- }
- function removeMapClickEvent() {
- if (modValue.handler) {
- modValue.handler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK);
- modValue.handler = null;
- }
- }
- /**
- * 清除marker
- * @return {[type]} [description]
- */
- function clearMarker() {
- if (modValue.addressArr.length > 0) {
- modValue.addressArr.map(function (entityId) {
- map3DViewer.map.entities.removeById(entityId)
- })
- modValue.addressArr = []
- }
- }
- return ONEMAP.M.advancedAddressSearchForm = {
- open: open,
- clearMarker: clearMarker
- };
- })
|