Skip to content

Conversation

@wang1212
Copy link

@wang1212 wang1212 commented Oct 31, 2019

  • add getGroupLayersId method

Although I can iterate over all the layers to get the ids of all the layers of a particular id group, I think it's best to hide the implementation details of metadata.group for the user, so I added the getGroupLayersId method.

  • fix metadata be undefined exception

All layers added through the plugin have a non-empty metadata attribute, but I don't think there is any need to add all layers through the plugin, such as a map initialization layer, in which case the layer's metadata will be undefined, causing the exception to occur.

- add 'getGroupLayersId' method
- fix missing 'metadata' error
`addLayerToGroup(map, groupId, layer, beforeId)` 

The calculated `beforeId` is incorrect when `beforeId ` is not specified
@wang1212
Copy link
Author

I also found that the addLayerToGroup(map, groupId, layer, beforeId) method gets the wrong beforeId when beforeId is not specified.

  • source code
if (beforeId && !ignoreBeforeIdCheck && (!isLayer(map, beforeId) || getLayerGroup(map, beforeId) !== groupId)) {
	throw new Error('beforeId must be the id of a layer within the same group');
} else if (!beforeId && !ignoreBeforeIdCheck) {
	beforeId = getLayerIdFromIndex(map, getGroupFirstLayerId(map, groupId) - 1);
}
  • modified code
if (beforeId && !ignoreBeforeIdCheck && (!isLayer(map, beforeId) || getLayerGroup(map, beforeId) !== groupId)) {
	throw new Error('beforeId must be the id of a layer within the same group')
} else if (!beforeId && !ignoreBeforeIdCheck) {

	const lastLayerIndex = getGroupLastLayerIndex(map, groupId)

	if (lastLayerIndex === -1) {
		throw new Error(`the "${ groupId }" layer group does not exist`)
	}

	beforeId = getLayerIdFromIndex(map, lastLayerIndex + 1)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant