Removed polygon latLnag dependency and added polygon marker and click event

This commit is contained in:
Maksym Dudnik 2019-02-06 16:53:15 +02:00
parent b1849e98f7
commit e9328f9e11
15 changed files with 167 additions and 51 deletions

View File

@ -1559,6 +1559,7 @@
"widget-action": { "widget-action": {
"action-cell-button": "Aktionszellenschaltfläche", "action-cell-button": "Aktionszellenschaltfläche",
"row-click": "Klick auf Zeile", "row-click": "Klick auf Zeile",
"polygon-click": "Klick auf Polygon",
"marker-click": "Klick auf Marker", "marker-click": "Klick auf Marker",
"tooltip-tag-action": "Tooltip-Tag-Aktion" "tooltip-tag-action": "Tooltip-Tag-Aktion"
} }

View File

@ -1559,6 +1559,7 @@
"widget-action": { "widget-action": {
"action-cell-button": "Action cell button", "action-cell-button": "Action cell button",
"row-click": "On row click", "row-click": "On row click",
"polygon-click": "On polygon click",
"marker-click": "On marker click", "marker-click": "On marker click",
"tooltip-tag-action": "Tooltip tag action" "tooltip-tag-action": "Tooltip tag action"
} }

View File

@ -1559,7 +1559,8 @@
"widget-action": { "widget-action": {
"action-cell-button": "Botón de acción de celda", "action-cell-button": "Botón de acción de celda",
"row-click": "Clic en la fila", "row-click": "Clic en la fila",
"marker-click": "Clic en el marcador", "polygon-click": "Clic en la fila",
"marker-click": "Clic en el polígono",
"tooltip-tag-action": "Acción de etiqueta para globo de ayuda" "tooltip-tag-action": "Acción de etiqueta para globo de ayuda"
} }
}, },

View File

@ -336,6 +336,7 @@
"action-cell-button": "Action cell button", "action-cell-button": "Action cell button",
"marker-click": "On marker click", "marker-click": "On marker click",
"row-click": "On row click", "row-click": "On row click",
"polygon-click": "On polygon click",
"tooltip-tag-action": "Tooltip tag action" "tooltip-tag-action": "Tooltip tag action"
} }
}, },

View File

@ -1425,6 +1425,7 @@
"widget-action": { "widget-action": {
"action-cell-button": "Action cell button", "action-cell-button": "Action cell button",
"row-click": "On row click", "row-click": "On row click",
"polygon-click": "On polygon click",
"marker-click": "On marker click", "marker-click": "On marker click",
"tooltip-tag-action": "Tooltip tag action" "tooltip-tag-action": "Tooltip tag action"
} }

View File

@ -1442,6 +1442,7 @@
"widget-action": { "widget-action": {
"action-cell-button": "アクションセルボタン", "action-cell-button": "アクションセルボタン",
"row-click": "行のクリック", "row-click": "行のクリック",
"polygon-click": "ポリゴンクリック",
"marker-click": "マーカークリック", "marker-click": "マーカークリック",
"tooltip-tag-action": "ツールチップのタグアクション" "tooltip-tag-action": "ツールチップのタグアクション"
} }

View File

@ -1318,6 +1318,7 @@
"widget-action": { "widget-action": {
"action-cell-button": "Action cell button", "action-cell-button": "Action cell button",
"row-click": "On row click", "row-click": "On row click",
"polygon-click": "On polygon click",
"marker-click": "On marker click", "marker-click": "On marker click",
"tooltip-tag-action": "Tooltip tag action" "tooltip-tag-action": "Tooltip tag action"
} }

View File

@ -1558,6 +1558,7 @@
"action-cell-button": "Кнопка действия ячейки", "action-cell-button": "Кнопка действия ячейки",
"row-click": "Действий при щелчке на строку", "row-click": "Действий при щелчке на строку",
"marker-click": "Действия при щелчке на указателе", "marker-click": "Действия при щелчке на указателе",
"polygon-click": "Действия при щелчке на полигон",
"tooltip-tag-action": "Действие при подсказке" "tooltip-tag-action": "Действие при подсказке"
} }
}, },

View File

@ -1524,7 +1524,8 @@
"widget-action": { "widget-action": {
"action-cell-button": "Eylem hücre butonu", "action-cell-button": "Eylem hücre butonu",
"row-click": "Satır tıklama eylemi", "row-click": "Satır tıklama eylemi",
"marker-click": "İşaretçi tıklama eylemi", "polygon-click": "Satır tıklama eylemi",
"marker-click": "Çokgen tıklama eylemi",
"tooltip-tag-action": "İpucu etiket eylemi" "tooltip-tag-action": "İpucu etiket eylemi"
} }
}, },

View File

@ -1429,6 +1429,7 @@
"action-cell-button": "动作单元格按钮", "action-cell-button": "动作单元格按钮",
"row-click": "点击行", "row-click": "点击行",
"marker-click": "点击标记", "marker-click": "点击标记",
"polygon-click": "单击多边形",
"tooltip-tag-action": "提示标签动作" "tooltip-tag-action": "提示标签动作"
} }
}, },

View File

@ -315,7 +315,7 @@ export default class TbGoogleMap {
} }
createPolygon(latLangs, settings) { createPolygon(latLangs, settings, location, onClickListener, markerArgs) {
let polygon = new google.maps.Polygon({ let polygon = new google.maps.Polygon({
map: this.map, map: this.map,
paths: latLangs, paths: latLangs,
@ -325,6 +325,32 @@ export default class TbGoogleMap {
fillOpacity: settings.polygonOpacity, fillOpacity: settings.polygonOpacity,
strokeWeight: settings.polygonStrokeWeight strokeWeight: settings.polygonStrokeWeight
}); });
//initialize-tooltip
let popup = new google.maps.InfoWindow({
content: ''
});
if (!this.tooltips) this.tooltips = [];
this.tooltips.push({
markerArgs: markerArgs,
popup: popup,
locationSettings: settings,
dsIndex: location.dsIndex
});
if (onClickListener) {
google.maps.event.addListener(polygon, 'click', function (event) {
if (settings.displayTooltip) {
if (!polygon.anchor) {
polygon.anchor = new google.maps.MVCObject();
}
polygon.anchor.set("position", event.latLng);
popup.open(this.map, polygon.anchor);
}
onClickListener();
});
}
return polygon; return polygon;
} }
/* eslint-disable no-undef */ /* eslint-disable no-undef */

View File

@ -233,7 +233,6 @@ export default class TbMapWidgetV2 {
} }
update() { update() {
var tbMap = this; var tbMap = this;
@ -381,6 +380,17 @@ export default class TbMapWidgetV2 {
tbMap.ctx.actionsApi.handleWidgetAction($event, descriptors[0], entityId, entityName); tbMap.ctx.actionsApi.handleWidgetAction($event, descriptors[0], entityId, entityName);
} }
} }
function locationPolygonClick($event, location) {
var descriptors = tbMap.ctx.actionsApi.getActionDescriptors('polygonClick');
if (descriptors.length) {
var datasource = tbMap.subscription.datasources[location.dsIndex];
var entityId = {};
entityId.id = datasource.entityId;
entityId.entityType = datasource.entityType;
var entityName = datasource.entityName;
tbMap.ctx.actionsApi.handleWidgetAction($event, descriptors[0], entityId, entityName);
}
}
function updateLocation(location, data, dataMap) { function updateLocation(location, data, dataMap) {
var locationChanged = false; var locationChanged = false;
@ -427,21 +437,6 @@ export default class TbMapWidgetV2 {
locationChanged = true; locationChanged = true;
} }
} }
if (location.settings.showPolygon && dataMap.dsDataMap[location.dsIndex][location.settings.polygonKeyName] !== null) {
let polygonLatLngsRaw = angular.fromJson(dataMap.dsDataMap[location.dsIndex][location.settings.polygonKeyName]);
let polygonLatLngs = !polygonLatLngsRaw || mapPolygonArray(polygonLatLngsRaw);
if (!location.polygon && polygonLatLngs.length > 0) {
location.polygon = tbMap.map.createPolygon(polygonLatLngs, location.settings);
tbMap.polygons.push(location.polygon);
} else if (polygonLatLngs.length > 0) {
let prevPolygonArr = tbMap.map.getPolygonLatLngs(location.polygon);
if (!prevPolygonArr || !arraysEqual(prevPolygonArr, polygonLatLngs)) {
tbMap.map.setPolygonLatLngs(location.polygon, polygonLatLngs);
}
}
}
} }
if (location.marker) { if (location.marker) {
updateLocationStyle(location, dataMap); updateLocationStyle(location, dataMap);
@ -451,6 +446,25 @@ export default class TbMapWidgetV2 {
return locationChanged; return locationChanged;
} }
function createUpdatePolygon(location, dataMap) {
if (location.settings.showPolygon && dataMap.dsDataMap[location.dsIndex][location.settings.polygonKeyName] !== null) {
let polygonLatLngsRaw = angular.fromJson(dataMap.dsDataMap[location.dsIndex][location.settings.polygonKeyName]);
let polygonLatLngs = !polygonLatLngsRaw || mapPolygonArray(polygonLatLngsRaw);
if (!location.polygon && polygonLatLngs.length > 0) {
location.polygon = tbMap.map.createPolygon(polygonLatLngs, location.settings, location, function (event) {
tbMap.callbacks.onLocationClick(location);
locationPolygonClick(event, location);
}, [location.dsIndex]);
tbMap.polygons.push(location.polygon);
} else if (polygonLatLngs.length > 0) {
let prevPolygonArr = tbMap.map.getPolygonLatLngs(location.polygon);
if (!prevPolygonArr || !arraysEqual(prevPolygonArr, polygonLatLngs)) {
tbMap.map.setPolygonLatLngs(location.polygon, polygonLatLngs);
}
}
}
}
function loadLocations(data, datasources) { function loadLocations(data, datasources) {
var bounds = tbMap.map.createBounds(); var bounds = tbMap.map.createBounds();
tbMap.locations = []; tbMap.locations = [];
@ -459,7 +473,6 @@ export default class TbMapWidgetV2 {
var currentDatasourceIndex = -1; var currentDatasourceIndex = -1;
var latIndex = -1; var latIndex = -1;
var lngIndex = -1; var lngIndex = -1;
for (var i = 0; i < data.length; i++) { for (var i = 0; i < data.length; i++) {
var dataKeyData = data[i]; var dataKeyData = data[i];
var dataKey = dataKeyData.dataKey; var dataKey = dataKeyData.dataKey;
@ -480,7 +493,6 @@ export default class TbMapWidgetV2 {
} else if (nameToCheck === tbMap.locationSettings.lngKeyName) { } else if (nameToCheck === tbMap.locationSettings.lngKeyName) {
lngIndex = i; lngIndex = i;
} }
if (latIndex > -1 && lngIndex > -1) { if (latIndex > -1 && lngIndex > -1) {
var location = { var location = {
latIndex: latIndex, latIndex: latIndex,
@ -499,6 +511,7 @@ export default class TbMapWidgetV2 {
} }
tbMap.locations.push(location); tbMap.locations.push(location);
updateLocation(location, data, dataMap); updateLocation(location, data, dataMap);
if (location.polyline) { if (location.polyline) {
tbMap.map.extendBounds(bounds, location.polyline); tbMap.map.extendBounds(bounds, location.polyline);
} else if (location.marker) { } else if (location.marker) {
@ -507,8 +520,28 @@ export default class TbMapWidgetV2 {
latIndex = -1; latIndex = -1;
lngIndex = -1; lngIndex = -1;
} }
} }
data.forEach(function (dataEl, index) {
let nameToCheck;
if (dataEl.dataKey.locationAttrName) {
nameToCheck = dataEl.dataKey.locationAttrName;
} else {
nameToCheck = dataEl.dataKey.label;
}
if (nameToCheck === tbMap.locationSettings.polygonKeyName) {
let location = {
polIndex: index,
settings: angular.copy(tbMap.locationSettings)
};
location.dsIndex = datasources.findIndex(function (ds) {
return dataEl.datasource.entityId === ds.entityId;
});
tbMap.locations.push(location);
createUpdatePolygon(location, dataMap);
tbMap.map.extendBounds(bounds, location.polygon);
}
});
tbMap.map.fitBounds(bounds); tbMap.map.fitBounds(bounds);
} }
@ -532,10 +565,13 @@ export default class TbMapWidgetV2 {
for (var p = 0; p < tbMap.locations.length; p++) { for (var p = 0; p < tbMap.locations.length; p++) {
var location = tbMap.locations[p]; var location = tbMap.locations[p];
locationsChanged |= updateLocation(location, data, dataMap); locationsChanged |= updateLocation(location, data, dataMap);
createUpdatePolygon(location, dataMap);
if (location.polyline) { if (location.polyline) {
tbMap.map.extendBounds(bounds, location.polyline); tbMap.map.extendBounds(bounds, location.polyline);
} else if (location.marker) { } else if (location.marker) {
tbMap.map.extendBoundsWithMarker(bounds, location.marker); tbMap.map.extendBoundsWithMarker(bounds, location.marker);
} else if (location.polygon) {
tbMap.map.extendBounds(bounds, location.polygon);
} }
} }
if (locationsChanged && tbMap.initBounds) { if (locationsChanged && tbMap.initBounds) {
@ -581,23 +617,30 @@ export default class TbMapWidgetV2 {
} }
} }
} }
} }
resize() { resize() {
if (this.map && this.map.inited()) { if (this.map && this.map.inited()) {
this.map.invalidateSize(); let map = this.map;
if (this.locations && this.locations.length > 0) { if (this.locations && this.locations.length > 0) {
var bounds = this.map.createBounds(); map.invalidateSize();
for (var m = 0; m < this.markers.length; m++) { var bounds = map.createBounds();
this.map.extendBoundsWithMarker(bounds, this.markers[m]); if (this.markers && this.markers.length>0) {
this.markers.forEach(function (marker) {
map.extendBoundsWithMarker(bounds, marker);
});
} }
if (this.polylines) { if (this.polylines && this.polylines.length>0) {
for (var p = 0; p < this.polylines.length; p++) { this.polylines.forEach(function (polyline) {
this.map.extendBounds(bounds, this.polylines[p]); map.extendBounds(bounds, polyline);
} })
} }
this.map.fitBounds(bounds); if (this.polygons && this.polygons.length > 0) {
this.polygons.forEach(function (polygon) {
map.extendBounds(bounds, polygon);
})
}
map.fitBounds(bounds);
} }
} }
} }
@ -634,6 +677,10 @@ export default class TbMapWidgetV2 {
name: 'widget-action.marker-click', name: 'widget-action.marker-click',
multiple: false multiple: false
}, },
'polygonClick': {
name: 'widget-action.polygon-click',
multiple: false
},
'tooltipAction': { 'tooltipAction': {
name: 'widget-action.tooltip-tag-action', name: 'widget-action.tooltip-tag-action',
multiple: true multiple: true

View File

@ -190,7 +190,7 @@ export default class TbOpenStreetMap {
this.map.removeLayer(polyline); this.map.removeLayer(polyline);
} }
createPolygon(latLangs, settings) { createPolygon(latLangs, settings, location, onClickListener, markerArgs) {
let polygon = L.polygon(latLangs, { let polygon = L.polygon(latLangs, {
fill: true, fill: true,
fillColor: settings.polygonColor, fillColor: settings.polygonColor,
@ -199,6 +199,13 @@ export default class TbOpenStreetMap {
fillOpacity: settings.polygonOpacity, fillOpacity: settings.polygonOpacity,
opacity: settings.polygonStrokeOpacity opacity: settings.polygonStrokeOpacity
}).addTo(this.map); }).addTo(this.map);
if (settings.displayTooltip) {
this.createTooltip(polygon, location.dsIndex, settings, markerArgs);
}
if (onClickListener) {
polygon.on('click', onClickListener);
}
return polygon; return polygon;
} }
@ -224,6 +231,7 @@ export default class TbOpenStreetMap {
setPolygonLatLngs(polygon, latLngs) { setPolygonLatLngs(polygon, latLngs) {
polygon.setLatLngs(latLngs); polygon.setLatLngs(latLngs);
polygon.redraw();
} }
fitBounds(bounds) { fitBounds(bounds) {
@ -272,7 +280,7 @@ export default class TbOpenStreetMap {
} }
extendBounds(bounds, polyline) { extendBounds(bounds, polyline) {
if (polyline && polyline.getLatLngs()) { if (polyline && polyline.getLatLngs() && polyline.getBounds()) {
bounds.extend(polyline.getBounds()); bounds.extend(polyline.getBounds());
} }
} }

View File

@ -331,7 +331,7 @@ export default class TbTencentMap {
} }
/* eslint-disable no-undef */ /* eslint-disable no-undef */
createPolygon(latLangs, settings) { createPolygon(latLangs, settings, location, onClickListener, markerArgs) {
let polygon = new qq.maps.Polygon({ let polygon = new qq.maps.Polygon({
map: this.map, map: this.map,
path: latLangs, path: latLangs,
@ -339,8 +339,31 @@ export default class TbTencentMap {
fillColor: settings.polygonColor, fillColor: settings.polygonColor,
strokeWeight: settings.polygonStrokeWeight strokeWeight: settings.polygonStrokeWeight
}); });
//initialize-tooltip
let popup = new qq.maps.InfoWindow({
content: ''
});
if (!this.tooltips) this.tooltips = [];
this.tooltips.push({
markerArgs: markerArgs,
popup: popup,
locationSettings: settings,
dsIndex: location.dsIndex
});
if (onClickListener) {
qq.maps.event.addListener(polygon, 'click', function (event) {
if (settings.displayTooltip) {
popup.setMap(this.map);
popup.setPosition(event.latLng);
popup.open();
}
onClickListener();
});
}
return polygon; return polygon;
} }
/* eslint-disable no-undef */ /* eslint-disable no-undef */
removePolygon (polygon) { removePolygon (polygon) {

View File

@ -73,22 +73,24 @@ export function processPattern(pattern, datasources, dsIndex) {
export function fillPattern(pattern, replaceInfo, data) { export function fillPattern(pattern, replaceInfo, data) {
var text = angular.copy(pattern); var text = angular.copy(pattern);
for (var v = 0; v < replaceInfo.variables.length; v++) { if (replaceInfo) {
var variableInfo = replaceInfo.variables[v]; for (var v = 0; v < replaceInfo.variables.length; v++) {
var txtVal = ''; var variableInfo = replaceInfo.variables[v];
if (variableInfo.dataKeyIndex > -1 && data[variableInfo.dataKeyIndex]) { var txtVal = '';
var varData = data[variableInfo.dataKeyIndex].data; if (variableInfo.dataKeyIndex > -1 && data[variableInfo.dataKeyIndex]) {
if (varData.length > 0) { var varData = data[variableInfo.dataKeyIndex].data;
var val = varData[varData.length - 1][1]; if (varData.length > 0) {
if (isNumber(val)) { var val = varData[varData.length - 1][1];
txtVal = padValue(val, variableInfo.valDec, 0); if (isNumber(val)) {
} else { txtVal = padValue(val, variableInfo.valDec, 0);
txtVal = val; } else {
} txtVal = val;
} }
} }
text = text.split(variableInfo.variable).join(txtVal); }
} text = text.split(variableInfo.variable).join(txtVal);
}
}
return text; return text;
} }