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 PinImages and ClusterPinImages not changing pin size #807

Merged
merged 2 commits into from
Jun 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions static/js/theme-map/ClusterPinImages.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,29 @@ class ClusterPinImages {
* @param {string} pin.backgroundColor Background color for the pin
* @param {string} pin.strokeColor Stroke (border) color for the pin
* @param {string} pin.labelColor Label (text) color for the pin
* @param {string} pin.width The width of the pin
* @param {string} pin.height The height of the pin
* @param {number} pin.width The width of the pin
* @param {number} pin.height The height of the pin
* @param {string} pin.labelText The label text for the cluster pin (normally size of cluster)
* @return string The SVG of the pin
* @return {Object} The SVG of the pin, and its width and height
*/
generatePin ({
backgroundColor = '#00759e',
strokeColor = 'black',
labelColor = 'white',
width = '24px',
height= '24px',
width = 24,
height= 24,
labelText = ''
} = {}) {
return `
const svg = `
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
<g fill="none" fill-rule="evenodd">
<circle fill="${backgroundColor}" fill-rule="nonzero" stroke="${strokeColor}" cx="12" cy="12" r="11"/>
<text fill="${labelColor}" font-family="Arial-BoldMT,Arial" font-size="12" font-weight="bold">
<tspan x="50%" y="16" text-anchor="middle">${labelText}</tspan>
</text>
</g>
</svg>
`;
</svg>`;
return { svg, width, height };
};

/**
Expand All @@ -55,8 +55,8 @@ class ClusterPinImages {
backgroundColor: this.defaultPinConfig.backgroundColor,
strokeColor: this.defaultPinConfig.strokeColor,
labelColor: this.defaultPinConfig.labelColor,
width: '24px',
height: '24px',
width: 24,
height: 24,
labelText: pinCount,
});
}
Expand All @@ -71,8 +71,8 @@ class ClusterPinImages {
backgroundColor: this.hoveredPinConfig.backgroundColor,
strokeColor: this.hoveredPinConfig.strokeColor,
labelColor: this.hoveredPinConfig.labelColor,
width: '24px',
height: '24px',
width: 24,
height: 24,
labelText: pinCount,
});
}
Expand All @@ -87,8 +87,8 @@ class ClusterPinImages {
backgroundColor: this.selectedPinConfig.backgroundColor,
strokeColor: this.selectedPinConfig.strokeColor,
labelColor: this.selectedPinConfig.labelColor,
width: '24px',
height: '24px',
width: 24,
height: 24,
labelText: pinCount,
});
}
Expand Down
2 changes: 1 addition & 1 deletion static/js/theme-map/PinClusterer/PinClusterer.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ class PinClusterer {
const pinOptions = this._map.newPinOptions()
.withCoordinate(GeoBounds.fit(coordinates).getCenter(this._mapProjection))
.withHideOffscreen(this._hideOffscreen)
.withPropertiesForStatus(this._propertiesForStatus);
.withPropertiesForStatus(status => this._propertiesForStatus(status, pinCluster.length));

// Build cluster icon(s) from template
for (const [icon, template] of Object.entries(this._iconTemplates)) {
Expand Down
30 changes: 15 additions & 15 deletions static/js/theme-map/PinImages.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,22 @@ class PinImages {
* @param {string} pin.backgroundColor Background color for the pin
* @param {string} pin.strokeColor Stroke (border) color for the pin
* @param {string} pin.labelColor Label (text) color for the pin
* @param {string} pin.width The width of the pin
* @param {string} pin.height The height of the pin
* @param {number} pin.width The width of the pin
* @param {number} pin.height The height of the pin
* @param {string} pin.pinCount The index of the pin for the pin text
* @return string The SVG of the pin
* @return {Object} The SVG of the pin, and its width and height
*/
generatePin ({
backgroundColor = '#00759e',
strokeColor = 'black',
labelColor = 'white',
width = '20px',
height= '27px',
width = 20,
height= 27,
index = '',
profile = ''
} = {}) {
return `
<svg width="${width}" height="${height}" viewBox="0 0 20 27" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
const svg = `
<svg width="${width}" height="${height}" viewBox="0 0 20 27" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>Path</title>
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<path d="M10.0501608,26.9990713 C16.0167203,19.9483571 19,14.5376667 19,10.767 C19,4.82 14.9704545,1 10,1 C5.02954545,1 1,4.82 1,10.767 C1,14.4756667 4.01672027,19.8863571 10.0501608,26.9990713 Z" id="Path" stroke="${strokeColor}" fill="${backgroundColor}" fill-rule="nonzero"></path>
Expand All @@ -46,8 +46,8 @@ class PinImages {
<tspan x="50%" y="15" text-anchor="middle">${index}</tspan>
</text>
</g>
</svg>
`;
</svg>`;
return { svg, width, height };
};

/**
Expand All @@ -60,8 +60,8 @@ class PinImages {
backgroundColor: this.defaultPinConfig.backgroundColor,
strokeColor: this.defaultPinConfig.strokeColor,
labelColor: this.defaultPinConfig.labelColor,
width: '24',
height: '28',
width: 24,
height: 28,
index: '',
profile: profile
});
Expand All @@ -77,8 +77,8 @@ class PinImages {
backgroundColor: this.hoveredPinConfig.backgroundColor,
strokeColor: this.hoveredPinConfig.strokeColor,
labelColor: this.hoveredPinConfig.labelColor,
width: '24',
height: '34',
width: 24,
height: 34,
index: '',
profile: profile
});
Expand All @@ -94,8 +94,8 @@ class PinImages {
backgroundColor: this.selectedPinConfig.backgroundColor,
strokeColor: this.selectedPinConfig.strokeColor,
labelColor: this.selectedPinConfig.labelColor,
width: '24',
height: '34',
width: 24,
height: 34,
index: '',
profile: profile
});
Expand Down
31 changes: 17 additions & 14 deletions static/js/theme-map/ThemeMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,23 +294,23 @@ class ThemeMap extends ANSWERS.Component {
this.config.pinClusterClickListener();
})
.withIconTemplate('default', (pinDetails) => {
return getEncodedSvg(this.config.pinClusterImages.getDefaultPin(pinDetails.pinCount));
return getEncodedSvg(this.config.pinClusterImages.getDefaultPin(pinDetails.pinCount).svg);
})
.withIconTemplate('hovered', (pinDetails) => {
return getEncodedSvg(this.config.pinClusterImages.getHoveredPin(pinDetails.pinCount));
return getEncodedSvg(this.config.pinClusterImages.getHoveredPin(pinDetails.pinCount).svg);
})
.withIconTemplate('selected', (pinDetails) => {
return getEncodedSvg(this.config.pinClusterImages.getSelectedPin(pinDetails.pinCount));
return getEncodedSvg(this.config.pinClusterImages.getSelectedPin(pinDetails.pinCount).svg);
})
.withPropertiesForStatus(status => {
.withPropertiesForStatus((status, pinCount) => {
const defaultPin = this.config.pinClusterImages.getDefaultPin(pinCount);
const properties = new PinProperties()
.setIcon(status.hovered || status.focused || status.selected ? 'hovered' : 'default')
.setWidth(28)
.setHeight(28)
.setWidth(defaultPin.width)
.setHeight(defaultPin.height)
.setAnchorX(this.config.pinClusterAnchors.anchorX)
.setAnchorY(this.config.pinClusterAnchors.anchorY);


return properties;
})
.withMinClusterSize(this.config.minClusterSize)
Expand All @@ -328,17 +328,20 @@ class ThemeMap extends ANSWERS.Component {
*/
buildPin(pinOptions, entity, index) {
const id = 'js-yl-' + entity.profile.meta.id;
const defaultPin = this.config.pinImages.getDefaultPin(index, entity.profile);
const hoveredPin = this.config.pinImages.getHoveredPin(index, entity.profile);
const selectedPin = this.config.pinImages.getSelectedPin(index, entity.profile);
const pin = pinOptions
.withId(id)
.withIcon(
'default',
getEncodedSvg(this.config.pinImages.getDefaultPin(index, entity.profile)))
getEncodedSvg(defaultPin.svg))
.withIcon(
'hovered',
getEncodedSvg(this.config.pinImages.getHoveredPin(index, entity.profile)))
getEncodedSvg(hoveredPin.svg))
.withIcon(
'selected',
getEncodedSvg(this.config.pinImages.getSelectedPin(index, entity.profile)))
getEncodedSvg(selectedPin.svg))
.withHideOffscreen(false)
.withCoordinate(new Coordinate(entity.profile.yextDisplayCoordinate))
.withPropertiesForStatus(status => {
Expand All @@ -349,12 +352,12 @@ class ThemeMap extends ANSWERS.Component {
.setAnchorX(this.config.pinAnchors.anchorX)
.setAnchorY(this.config.pinAnchors.anchorY);

properties.setWidth(24);
properties.setHeight(28);
properties.setWidth(defaultPin.width);
properties.setHeight(defaultPin.height);

if (status.selected) {
properties.setWidth(24);
properties.setHeight(34);
properties.setWidth(selectedPin.width);
properties.setHeight(selectedPin.height);
}

return properties;
Expand Down