Giter Site home page Giter Site logo

Comments (5)

nerdess avatar nerdess commented on June 11, 2024 1

The fix introduced here #1013 was also fixing my issue. Hope there will be a release soon to add it to the official codebase :)

from ol-ext.

Viglino avatar Viglino commented on June 11, 2024

It's seems there is a scale factor on the icons...
Do you have an online example?

from ol-ext.

nerdess avatar nerdess commented on June 11, 2024

Hm...building an online example would take a while...

I didn't change the code though, I just bumped Open Layers from 6.x to 8.x.

This is the style of the black circle features:

(The ICONS are svg's)


const getScale = (resolution) => {
	const result = 1 / Math.pow(resolution, 1);
	return result > 0.4 ? 0.4 : result;
};

return [
	new olStyle.Style({
		image: new olStyle.Circle({
			radius: 30,
			scale: getScale(resolution) * 1.5,
			fill: new olStyle.Fill({
				color: hover || selected ? '#1F54A0' : 'rgba(51, 51, 51, 0.8)',
			}),
		}),
	}),
	new olStyle.Style({
		image: new olStyle.Icon({
			src: ICONS[category_tag || 'uncategorized'].src,
			scale: getScale(resolution),
		}),
	}),
];

from ol-ext.

mike-000 avatar mike-000 commented on June 11, 2024

Possibly due to repeatedly reloading images (which is asynchronous) if the total number of icon sources exceeds the built in cache. You could define your own style caches outside the style function

const circleCache = {};
const iconCache = {};

Then in the style function simply look up the color or src, only creating a new style and adding to the cache if it does not exist, then you only need set the scale used to render it

const color = hover || selected ? '#1F54A0' : 'rgba(51, 51, 51, 0.8)';
let circle = circleCache[color];
if (!circle) {
	circle = new olStyle.Circle({
		radius: 30 * 1.5;,
		fill: new olStyle.Fill({
			color: color,
		}),
	});
	circleCache[color] = circle;
}

const src = ICONS[category_tag || 'uncategorized'].src;
let icon = iconCache[src];
if (!icon) {
	icon = new olStyle.Style({
		image: new olStyle.Icon({
			src: src,
		}),
	}),
	iconCache[src] = icon;
}

const scale = Math.min(0.4, 1 / resolution);
circle.getImage().setScale(scale);
icon.getImage().setScale(scale);

return [circle, icon];

from ol-ext.

Viglino avatar Viglino commented on June 11, 2024

May be related to #1013

from ol-ext.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.