S
S
sinneren2017-06-13 12:01:42
JavaScript
sinneren, 2017-06-13 12:01:42

How to correctly load ajax objectManager object data on click?

1. I create templates for balloons and icons.
2. While loading, I make an ajax request, where I get only id and coordinates.
3. By clicking on the object, I make another request, where I pass the id, I get the data.
4. setObjectOptions in the object creates options and distributes data there, and I already have everything in properties, so I have to pass properties to the object without wrappers:

objectManager.objects._objectsById[objectId].properties = {
  address: json[objectId].name,
  pic: json[objectId].photo
}

Hence the problem: when clicking, the balloon opens, but it is empty, in order to display the data, I have to close the balloon and open it again. That is, the data apparently does not have time to load, but setTimeout is too crutch and unreliable. What is the correct solution please?

And at the same time, if I suddenly have experience, with boundschange, I also load objects from this area, but the current opened object collapses, is it possible to somehow set the minimum shift size so that only then my loading methods work out?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sinneren, 2017-06-13
@sinneren

What a fine fellow I am, I will answer myself:

var object = objectManager.objects.getById(objectId);
            object.properties = {
              address: json[objectId].name,
              pic: json[objectId].photo
            }
            var objectState = objectManager.getObjectState(objectId);
            if (!objectState.isClustered) {
              objectManager.objects.balloon.open(objectId);
            }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question