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

add 'getGroupLayersId' method && fix bugs #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

add 'getGroupLayersId' method && fix bugs #2

wants to merge 2 commits into from

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