Working on styles.
This commit is contained in:
parent
81ffb65aaf
commit
6e64c8dd4c
|
@ -22,6 +22,7 @@ import { createDefaultStyle } from 'ol/style/Style';
|
||||||
|
|
||||||
import osmIcons, { highlight } from './osm-icons';
|
import osmIcons, { highlight } from './osm-icons';
|
||||||
import { indexOf } from 'lodash';
|
import { indexOf } from 'lodash';
|
||||||
|
import { getZoomInteger } from '../map/Map';
|
||||||
|
|
||||||
interface StyleParameters {
|
interface StyleParameters {
|
||||||
type: string;
|
type: string;
|
||||||
|
@ -159,8 +160,6 @@ const memoizeOptions = {
|
||||||
max: 1024000,
|
max: 1024000,
|
||||||
};
|
};
|
||||||
|
|
||||||
const zoom = () => Math.floor(getState().zoom);
|
|
||||||
|
|
||||||
const styles = {
|
const styles = {
|
||||||
wpt: {
|
wpt: {
|
||||||
getParameters: (feature: Feature) => {
|
getParameters: (feature: Feature) => {
|
||||||
|
@ -169,7 +168,7 @@ const styles = {
|
||||||
isSelected: feature.get('isSelected') ?? false,
|
isSelected: feature.get('isSelected') ?? false,
|
||||||
text: feature.get('name'),
|
text: feature.get('name'),
|
||||||
customIcon: icons[feature.get('sym') as keyof typeof icons],
|
customIcon: icons[feature.get('sym') as keyof typeof icons],
|
||||||
hidden: minZoom && zoom() < minZoom,
|
hidden: minZoom && getZoominteger() < minZoom,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
getStyle: memoize((params: any) => {
|
getStyle: memoize((params: any) => {
|
||||||
|
@ -195,8 +194,8 @@ const styles = {
|
||||||
getParameters: (feature: Feature) => {
|
getParameters: (feature: Feature) => {
|
||||||
return {
|
return {
|
||||||
isSelected: feature.get('isSelected') ?? false,
|
isSelected: feature.get('isSelected') ?? false,
|
||||||
feature: zoom() >= 7 ? feature : undefined,
|
feature: getZoomInteger() >= 7 ? feature : undefined,
|
||||||
zoom: zoom() >= 7 ? Math.floor(zoom()) : undefined,
|
zoom: getZoomInteger() >= 7 ? Math.floor(getZoomInteger()) : undefined,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
getStyle: memoize((params: any) => {
|
getStyle: memoize((params: any) => {
|
||||||
|
@ -334,9 +333,11 @@ const styles = {
|
||||||
name: feature.get('name'),
|
name: feature.get('name'),
|
||||||
klass,
|
klass,
|
||||||
isHighlighted,
|
isHighlighted,
|
||||||
isTextHidden: zoom() < 19,
|
isTextHidden: getZoomInteger() < 19,
|
||||||
// isHidden: !isHighlighted && zoom() < 16,
|
// isHidden: !isHighlighted && getZoomInteger() < 16,
|
||||||
isHidden: true,
|
isHidden:
|
||||||
|
(feature.get('sub-type') === 'tourism' && getZoomInteger() < 14) ||
|
||||||
|
(feature.get('sub-type') !== 'tourism' && getZoomInteger() < 16),
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
getStyle: memoize((params: any) => {
|
getStyle: memoize((params: any) => {
|
||||||
|
@ -374,6 +375,35 @@ const styles = {
|
||||||
});
|
});
|
||||||
}, memoizeOptions),
|
}, memoizeOptions),
|
||||||
},
|
},
|
||||||
|
cluster: {
|
||||||
|
getParameters: (feature: Feature) => {
|
||||||
|
const nbFeatures = feature.get('features').length;
|
||||||
|
// console.log({ caller: 'cluster / getParameters', feature, nbFeatures });
|
||||||
|
return {
|
||||||
|
nbFeatures,
|
||||||
|
subFeature: nbFeatures === 1 ? feature.get('features')[0] : undefined,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
getStyle: memoize((params: any) => {
|
||||||
|
// console.log({ caller: 'cluster / getStyle', params });
|
||||||
|
const { nbFeatures } = params;
|
||||||
|
return new Style({
|
||||||
|
image: new Circle({
|
||||||
|
radius: 15,
|
||||||
|
fill: new Fill({ color: [174, 33, 219, 0.7] }),
|
||||||
|
}),
|
||||||
|
text: new Text({
|
||||||
|
text: `${nbFeatures}`,
|
||||||
|
font: 'bold 14px "Open Sans", "Arial Unicode MS", "sans-serif"',
|
||||||
|
offsetY: +0,
|
||||||
|
padding: [0, 0, 0, 0],
|
||||||
|
fill: new Fill({
|
||||||
|
color: 'black',
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
}, memoizeOptions),
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export const style = (feature: Feature, resolution: number) => {
|
export const style = (feature: Feature, resolution: number) => {
|
||||||
|
@ -389,13 +419,16 @@ export const style = (feature: Feature, resolution: number) => {
|
||||||
if (params?.isHidden) {
|
if (params?.isHidden) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
// if (params.subFeature) {
|
||||||
|
// return style(params.subFeature, resolution);
|
||||||
|
// }
|
||||||
const getStyle = styles[type].getStyle;
|
const getStyle = styles[type].getStyle;
|
||||||
const style = getStyle(params);
|
const result = getStyle(params);
|
||||||
// console.log({ caller: 'style', feature, type, params, style });
|
// console.log({ caller: 'style', feature, type, params, style });
|
||||||
if (style === undefined) {
|
if (result === undefined) {
|
||||||
return createDefaultStyle(feature, resolution)[0];
|
return createDefaultStyle(feature, resolution)[0];
|
||||||
}
|
}
|
||||||
return style;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default style;
|
export default style;
|
||||||
|
|
|
@ -58,7 +58,9 @@ const [getState, setState] = createSignal({
|
||||||
provider: 'osm',
|
provider: 'osm',
|
||||||
});
|
});
|
||||||
|
|
||||||
export { getState };
|
const getZoomInteger = () => Math.floor(getState().zoom);
|
||||||
|
|
||||||
|
export { getState, getZoomInteger };
|
||||||
|
|
||||||
const [getMap, setMap] = createSignal<OlMap | null>(null);
|
const [getMap, setMap] = createSignal<OlMap | null>(null);
|
||||||
|
|
||||||
|
@ -295,14 +297,14 @@ const Map: Component = () => {
|
||||||
|
|
||||||
const clusterSource = new Cluster({
|
const clusterSource = new Cluster({
|
||||||
source: clusterableVectorTileSource,
|
source: clusterableVectorTileSource,
|
||||||
distance: 50,
|
distance: 30,
|
||||||
minDistance: 10,
|
minDistance: 10,
|
||||||
geometryFunction: (feature: Feature) => {
|
geometryFunction: (feature: Feature) => {
|
||||||
// console.log({
|
// console.log({
|
||||||
// caller: 'Map / Cluster / geometryFunction',
|
// caller: 'Map / Cluster / geometryFunction',
|
||||||
// feature,
|
// feature,
|
||||||
// });
|
// });
|
||||||
if (feature.get('sub-type') === 'tourism') {
|
if (getZoomInteger() < 14 && feature.get('sub-type') === 'tourism') {
|
||||||
return feature.getGeometry();
|
return feature.getGeometry();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@ -325,19 +327,7 @@ const Map: Component = () => {
|
||||||
let clusterLayer = new VectorLayer({
|
let clusterLayer = new VectorLayer({
|
||||||
source: clusterSource,
|
source: clusterSource,
|
||||||
zIndex: Infinity,
|
zIndex: Infinity,
|
||||||
// style,
|
style,
|
||||||
style: function (feature) {
|
|
||||||
// console.log({
|
|
||||||
// caller: 'Map / Cluster / style',
|
|
||||||
// feature,
|
|
||||||
// });
|
|
||||||
return new Style({
|
|
||||||
image: new Circle({
|
|
||||||
radius: 20,
|
|
||||||
fill: new Fill({ color: 'black' }),
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
olMap.addLayer(vectorTileLayer);
|
olMap.addLayer(vectorTileLayer);
|
||||||
|
|
Loading…
Reference in New Issue