Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cluster layer #789

Merged
merged 10 commits into from
Aug 15, 2023
7 changes: 5 additions & 2 deletions addon/components/base-layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,10 @@ export default Ember.Component.extend(
Ember.set(this.get('layerModel'), 'leafletObjectGetter', this.getLeafletObject.bind(this));
}

if (Ember.isNone(this.get('layerModel.returnLeafletObject'))) {
Ember.set(this.get('layerModel'), 'returnLeafletObject', this.returnLeafletObject.bind(this));
}

// Save the reference to the instance method for getting attributes options.
if (Ember.isNone(this.get('layerModel._attributesOptions'))) {
Ember.set(this.get('layerModel'), '_attributesOptions', this._getAttributesOptions.bind(this));
Expand Down Expand Up @@ -630,8 +634,7 @@ export default Ember.Component.extend(
return;
}

let leafletLayerIsCluster = leafletLayer instanceof L.MarkerClusterGroup;
let continueLoading = leafletLayerIsCluster ? leafletLayer._originalVectorLayer.options.continueLoading : leafletLayer.options.continueLoading;
let continueLoading = this.returnLeafletObject().options.continueLoading;

if (continueLoading) {
let e = {
Expand Down
95 changes: 61 additions & 34 deletions addon/components/base-vector-layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,29 @@ export default BaseLayer.extend({
return container[0];
},

/**
Returns leaflet layer.

@method returnLeafletObject
@returns leafletObject
*/
returnLeafletObject() {
let leafletObject = this.get('_leafletObject');

if (Ember.isNone(leafletObject)) {
return;
}

// Clustering vector layer contains the wfsLayer context in the "_leafletObject._originalVectorLayer" path
// The context of the original vector layer is important for map handlers, methods instead of cluster group
if (leafletObject instanceof L.MarkerClusterGroup) {
let originalVectorLayer = Ember.get(leafletObject, '_originalVectorLayer');
leafletObject = originalVectorLayer ? originalVectorLayer : leafletObject;
}

return leafletObject;
},

/**
@method _getContainerPaneLabelMulti
@return HTMLElement
Expand Down Expand Up @@ -164,7 +187,7 @@ export default BaseLayer.extend({

_setFeaturesProcessCallback(leafletObject) {
if (!leafletObject) {
leafletObject = this.get('_leafletObject');
leafletObject = this.returnLeafletObject();
}

leafletObject.on('load', (loaded) => {
Expand All @@ -178,7 +201,7 @@ export default BaseLayer.extend({
_featuresProcessCallback(layers, leafletObject) {
return new Ember.RSVP.Promise((resolve) => {
if (!leafletObject) {
leafletObject = this.get('_leafletObject');
leafletObject = this.returnLeafletObject();
}

if (!layers) {
Expand All @@ -200,6 +223,14 @@ export default BaseLayer.extend({

if (this.get('labelSettings.signMapObjects')) {
this._addLabelsToLeafletContainer(layers, leafletObject);

// Sometimes featuresProcessCallBack is triggered returning 0 features
// Then adds labels of layer features that is inside a cluster,
// It is necessary to clean up the labels with the cluster layer handler
// that works only for _originalVectorLayer feature addition
if (this.get('_leafletObject') instanceof L.MarkerClusterGroup) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

тут тоже нужны комментарии. я не понимаю зачем это

Copy link
Contributor Author

@viatkinviatkin viatkinviatkin Aug 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Иногда featuresProcessCallBack добавляет на карту надписи объектов слоя, который находится внутри кластера, необходимо почистить надписи обработчиком кластерного слоя

image

  • на картинке видно, что на событие зума карты триггернулся featuresProcessCallBack (подгрузилось 0 объектов) внутреннего _originalVectorLayer,
  • отработал метод _addLabelsToLeafletContainer, который добавил на карту все надписи внутреннего _originalVectorLayer
  • а обработчик надписей для L.MarkerClusterGroup не триггернулся, поскольку он работает только на событие layeradd внутреннего слоя

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Добавил комментарии

this.loadClusterLayer({ type:'layeradd', target: this.returnLeafletObject(), layer: {} });
}
}

leafletObject.fire('loadCompleted');
Expand Down Expand Up @@ -449,7 +480,7 @@ export default BaseLayer.extend({
}

let clusterLayer = this.get('_leafletObject');
if (clusterLayer instanceof L.MarkerClusterGroup) {
if (!(clusterLayer instanceof L.MarkerClusterGroup)) {
return;
}

Expand Down Expand Up @@ -525,7 +556,7 @@ export default BaseLayer.extend({
*/
showAllLayerObjects() {
return new Ember.RSVP.Promise((resolve, reject) => {
let leafletObject = this.get('_leafletObject');
let leafletObject = this.returnLeafletObject();
DaryaNeko marked this conversation as resolved.
Show resolved Hide resolved
let map = this.get('leafletMap');
let layer = this.get('layerModel');

Expand Down Expand Up @@ -602,7 +633,7 @@ export default BaseLayer.extend({
@return nothing
*/
hideAllLayerObjects() {
let leafletObject = this.get('_leafletObject');
let leafletObject = this.returnLeafletObject();
let map = this.get('leafletMap');
let layer = this.get('layerModel');

Expand Down Expand Up @@ -645,7 +676,7 @@ export default BaseLayer.extend({
*/
_setVisibilityObjects(objectIds, visibility = false) {
return new Ember.RSVP.Promise((resolve, reject) => {
let leafletObject = this.get('_leafletObject');
let leafletObject = this.returnLeafletObject();
let map = this.get('leafletMap');
let layer = this.get('layerModel');

Expand Down Expand Up @@ -892,7 +923,7 @@ export default BaseLayer.extend({
try {
let features = Ember.A();
let bounds = new Terraformer.Primitive(e.polygonLayer.toGeoJSON());
let leafletLayer = this.get('_leafletObject');
let leafletLayer = this.returnLeafletObject();
let mapModel = this.get('mapApi').getFromApi('mapModel');
let scale = this.get('mapApi').getFromApi('precisionScale');
leafletLayer.eachLayer(function (layer) {
Expand Down Expand Up @@ -933,7 +964,7 @@ export default BaseLayer.extend({
search(e) {
return new Ember.RSVP.Promise((resolve, reject) => {
let searchSettingsPath = 'layerModel.settingsAsObject.searchSettings';
let leafletLayer = this.get('_leafletObject');
let leafletLayer = this.returnLeafletObject();
let features = Ember.A();

let searchFields = (e.context ? this.get(`${searchSettingsPath}.contextSearchFields`) : this.get(`${searchSettingsPath}.searchFields`)) || Ember.A();
Expand Down Expand Up @@ -994,7 +1025,7 @@ export default BaseLayer.extend({
}
});

let leafletLayer = this.get('_leafletObject');
let leafletLayer = this.returnLeafletObject();
leafletLayer.eachLayer((layer) => {
let feature = Ember.get(layer, 'feature');
let meet = true;
Expand All @@ -1020,7 +1051,7 @@ export default BaseLayer.extend({
*/
loadLayerFeatures(e) {
return new Ember.RSVP.Promise((resolve, reject) => {
resolve(this.get('_leafletObject'));
resolve(this.returnLeafletObject());
});
},

Expand All @@ -1033,7 +1064,7 @@ export default BaseLayer.extend({
*/
getLayerFeatures(e) {
return new Ember.RSVP.Promise((resolve, reject) => {
let leafletObject = this.get('_leafletObject');
let leafletObject = this.returnLeafletObject();
let featureIds = e.featureIds;
if (Ember.isArray(featureIds) && !Ember.isNone(featureIds)) {
let objects = [];
Expand Down Expand Up @@ -1067,7 +1098,7 @@ export default BaseLayer.extend({

e.results.push({
layerModel: this.get('layerModel'),
leafletObject: this.get('_leafletObject'),
leafletObject: this.returnLeafletObject(),
features: e.load ? this.loadLayerFeatures(e) : this.getLayerFeatures(e)
});
},
Expand Down Expand Up @@ -1095,7 +1126,7 @@ export default BaseLayer.extend({
// Call public identify method, if layer should be continueLoad.
e.results.push({
layerModel: this.get('layerModel'),
promise: this.continueLoad(this.get('_leafletObject'))
promise: this.continueLoad(this.returnLeafletObject())
});
},

Expand All @@ -1108,7 +1139,7 @@ export default BaseLayer.extend({
reload() {
this.clearChanges();

let leafletObject = this.get('_leafletObject');
let leafletObject = this.returnLeafletObject();
let map = this.get('leafletMap');

leafletObject.eachLayer((layerShape) => {
Expand All @@ -1119,7 +1150,7 @@ export default BaseLayer.extend({
leafletObject.clearLayers();

if (this.get('labelSettings.signMapObjects') && !Ember.isNone(this.get('_labelsLayer')) &&
!Ember.isNone(this.get('_leafletObject._labelsLayer'))) {
!Ember.isNone(leafletObject._labelsLayer)) {
leafletObject._labelsLayer.eachLayer((layerShape) => {
if (map.hasLayer(layerShape)) {
map.removeLayer(layerShape);
Expand All @@ -1129,7 +1160,7 @@ export default BaseLayer.extend({
}

if (this.get('labelSettings.signMapObjects') && !Ember.isNone(this.get('additionalZoomLabel')) &&
!Ember.isNone(this.get('_leafletObject.additionalZoomLabel'))) {
!Ember.isNone(leafletObject.additionalZoomLabel)) {
this.get('additionalZoomLabel').forEach(zoomLabels => {
zoomLabels.eachLayer((layerShape) => {
if (map.hasLayer(layerShape)) {
Expand Down Expand Up @@ -1175,7 +1206,7 @@ export default BaseLayer.extend({
@private
*/
_checkZoomPane() {
let leafletObject = this.get('_leafletObject');
let leafletObject = this.returnLeafletObject();
let thisPane = this.get('_pane');
let leafletMap = this.get('leafletMap');
if (!Ember.isNone(leafletMap) && thisPane && !Ember.isNone(leafletObject)) {
Expand Down Expand Up @@ -1296,12 +1327,7 @@ export default BaseLayer.extend({
let hasReplace = false;
let propName;

let leafletObject = this.get('_leafletObject');

// Clustering vector layer contains the leaflet's main context in the "_leafletObject._originalVectorLayer" path
if (leafletObject instanceof L.MarkerClusterGroup) {
leafletObject = this.get('_leafletObject._originalVectorLayer');
}
let leafletObject = this.returnLeafletObject();

try {
propName = Ember.$('<p>' + str + '</p>').find('propertyname');
Expand Down Expand Up @@ -1415,7 +1441,7 @@ export default BaseLayer.extend({
_showLabelsMovingMap() {
let additionalZoomLabel = this.get('additionalZoomLabel');
let _labelsLayer = this.get('_labelsLayer');
let leafletObject = this.get('_leafletObject');
let leafletObject = this.returnLeafletObject();
if (this.get('leafletMap').hasLayer(_labelsLayer) && leafletObject) {
this._createStringLabel(leafletObject.getLayers(), _labelsLayer, additionalZoomLabel);
}
Expand Down Expand Up @@ -2095,7 +2121,7 @@ export default BaseLayer.extend({
*/
_updatePositionLabelForLine() {
let additionalZoomLabel = this.get('additionalZoomLabel');
let leafletObject = this.get('_leafletObject');
let leafletObject = this.returnLeafletObject();

let _this = this;

Expand Down Expand Up @@ -2181,7 +2207,7 @@ export default BaseLayer.extend({
if (!Ember.isNone(labelSettingsString)) {
let leafletMap = this.get('leafletMap');
if (!leafletObject) {
leafletObject = this.get('_leafletObject');
leafletObject = this.returnLeafletObject();
}

let additionalZoomLabel = this.get('additionalZoomLabel');
Expand Down Expand Up @@ -2285,7 +2311,7 @@ export default BaseLayer.extend({
let leafletContainer = this.get('leafletContainer');

if (!leafletObject) {
leafletObject = this.get('_leafletObject') instanceof L.MarkerClusterGroup ? this.get('_leafletObject._originalVectorLayer') : this.get('_leafletObject');
leafletObject = this.returnLeafletObject();
}

let thisPane = this.get('_paneLabel');
Expand Down Expand Up @@ -2362,16 +2388,17 @@ export default BaseLayer.extend({
if (this.get('visibility')) {
this._addLayerToLeafletContainer();

let leafletObject = this.get('_leafletObject');

// Clustering vector layer contains the leaflet's main context in the "_leafletObject._originalVectorLayer" path
if (leafletObject instanceof L.MarkerClusterGroup) {
leafletObject = this.get('_leafletObject._originalVectorLayer');
}
let leafletObject = this.returnLeafletObject();

if (this.get('labelSettings.signMapObjects') && !Ember.isNone(this.get('_labelsLayer')) &&
!Ember.isNone(Ember.get(leafletObject, '_labelsLayer'))) {
this._addLabelsToLeafletContainer();

// _setLayerVisibility method handles <load> action of default wfs-layer
// For L.MarkerClusterGroup there is <updateClusterLayer> handler that defines label visibility in its own way
if (!(this.get('_leafletObject') instanceof L.MarkerClusterGroup)) {
this._addLabelsToLeafletContainer();
}

this._checkZoomPane();
if (this.get('typeGeometry') === 'polyline') {
this._updatePositionLabelForLine();
Expand Down
7 changes: 4 additions & 3 deletions addon/components/feature-result-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,9 +355,10 @@ export default Ember.Component.extend(ResultFeatureInitializer, {
if (feature.geometry && feature.geometry.type &&
(feature.geometry.type === 'Point' || feature.geometry.type === 'MultiPoint' ||
feature.geometry.type === 'LineString' || feature.geometry.type === 'MultiLineString')) {
let layerTolerance = feature.layerModel.get('_leafletObject.options.renderer.options.tolerance');
if (Ember.isPresent(layerTolerance) && layerTolerance === 0) {
Ember.set(feature.layerModel.get('_leafletObject.options.renderer.options'), 'tolerance', 3);
let leafletObject = feature.layerModel.returnLeafletObject();
let layerOptions = Ember.get(leafletObject, 'options.renderer.options');
if (Ember.isPresent(layerOptions) && layerOptions.tolerance === 0) {
Ember.set(layerOptions, 'tolerance', 3);
}
}

Expand Down
4 changes: 3 additions & 1 deletion addon/components/flexberry-edit-layermap.js
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,7 @@ export default Ember.Component.extend(
let keyWords = this.get('layer.keyWords');
let boundingBox = this.get('layer.boundingBox');
let leafletObjectGetter = this.get('layer.leafletObjectGetter');
let returnLeafletObject = this.get('layer.returnLeafletObject');
let bounds = getBounds(boundingBox);

let crs = this.get('layer.coordinateReferenceSystem');
Expand Down Expand Up @@ -637,7 +638,8 @@ export default Ember.Component.extend(
maxLat: bounds.maxLat,
maxLng: bounds.maxLng,
},
leafletObjectGetter: leafletObjectGetter
leafletObjectGetter: leafletObjectGetter,
returnLeafletObject: returnLeafletObject
});
},

Expand Down
8 changes: 4 additions & 4 deletions addon/components/flexberry-maplayers.js
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ let FlexberryMaplayersComponent = Ember.Component.extend(
rightLayer: null,

/**
Proprty containing current active layers.
Property containing current active layers.

@property currentLayers
@type Array
Expand Down Expand Up @@ -481,13 +481,13 @@ let FlexberryMaplayersComponent = Ember.Component.extend(
let layersToAdd = this.get('currentLayers');
let layers = this.get('layers');
layers.forEach(layer => {
const leafletLayer = layer.get('_leafletObject');
const leafletLayer = layer.returnLeafletObject();
if (leafletLayer && leafletLayer.getContainer && leafletLayer.getContainer()) {
leafletLayer.getContainer().style.clip = '';
}

if (layer.get('settingsAsObject.labelSettings.signMapObjects')) {
const labelsAdditionalOriginalLayer = layer.get('_leafletObject.additionalZoomLabel');
const labelsAdditionalOriginalLayer = layer.returnLeafletObject().additionalZoomLabel;
if (labelsAdditionalOriginalLayer) {
labelsAdditionalOriginalLayer.forEach(zoomLabels => {
if (zoomLabels && zoomLabels.getContainer && zoomLabels.getContainer()) {
Expand All @@ -496,7 +496,7 @@ let FlexberryMaplayersComponent = Ember.Component.extend(
});
}

const labelsOriginalLayer = layer.get('_leafletObject._labelsLayer');
const labelsOriginalLayer = layer.returnLeafletObject()._labelsLayer;
if (labelsOriginalLayer && labelsOriginalLayer.getContainer && labelsOriginalLayer.getContainer()) {
leafletLayer.getContainer().style.clip = '';
}
Expand Down
Loading