css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <div data-component="PropertyMap" class="component-property-map">
		<script>
				var SPG = SPG || {};
				SPG.markers = [
					{
						type: 'Feature',
						properties: {
							'btype': 'bostad',
							'title': "Anholt 1",
							'description': 'Stockholm'
						},
						geometry: {
							type: 'Point',
							coordinates: [18.063, 59.2978]
						}
					},
					{
						type: 'Feature',
						properties: {
							'btype': 'bostad',
							'title': "Anholt 1",
							'description': 'Stockholm'
						},
						geometry: {
							type: 'Point',
							coordinates: [18.163, 59.2978]
						}
					},
				{
						type: 'Feature',
						properties: {
							'btype': 'bostad',
							'title': "Anholt 1",
							'description': 'Stockholm'
						},
						geometry: {
							type: 'Point',
							coordinates: [18.0547670, 59.3364651]
						}
					},
					{
						type: 'Feature',
						properties: {
							'btype': 'bostad',
							'title': "Norge 2",
							'description': 'Bergen'
						},
						geometry: {
							type: 'Point',
							coordinates: [5.2, 60.3]
						}
					}
				];
				
				SPG.markers2 = [
					{
						type: 'Feature',
						properties: {
							'btype': 'omsorg',
							'title': "Anholt 1",
							'description': 'Stockholm'
						},
						geometry: {
							type: 'Point',
							coordinates: [18.163, 59.2978]
						}
					},
					{
						type: 'Feature',
						properties: {
							'btype': 'omsorg',
							'title': "Anholt 1",
							'description': 'Stockholm'
						},
						geometry: {
							type: 'Point',
							coordinates: [18.263, 59.2978]
						}
					},
				{
						type: 'Feature',
						properties: {
							'btype': 'omsorg',
							'title': "Anholt 1",
							'description': 'Stockholm'
						},
						geometry: {
							type: 'Point',
							coordinates: [18.1547670, 59.3364651]
						}
					},
					{
						type: 'Feature',
						properties: {
							'btype': 'omsorg',
							'title': "Norge 2",
							'description': 'Bergen'
						},
						geometry: {
							type: 'Point',
							coordinates: [6.2, 60.3]
						}
					}
				];
				
				
				
				SPG.markers3 = [
					{
						type: 'Feature',
						properties: {
							'btype': 'utveckling',
							'title': "utveckling 1",
							'description': 'Stockholm'
						},
						geometry: {
							type: 'Point',
							coordinates: [18.363, 59.1978]
						}
					},
				];
		</script>
</div>
            
          
!
            
              * {
  box-sizing: border-box
}
html, body {
  height: 100%
}

.demo-buttons {
	position: absolute;
	z-index: 100;
	top: 0;
	left: 0;
	right: 0;
}

.component-property-map {
	height: 100%;
}

@keyframes drop-in {
	from {
		transform: translateY(-50%);
	}
	to {
		transform: none;
	}
}

.component-property-map__marker {
	span {
		position: absolute;
		left: 0; right: 0; top: 0; bottom: 0;
		//animation: drop-in .2s ease-out;
		transition: transform .1s ease-out;
		&:hover {
			transition: transform .2s ease-out;
			transform: scale(1.05);
		}
		svg {
			display: block;
			height: 100%;
			width: 100%;
		}
		background-repeat: no-repeat;
		background-position: center center;
	}
	&.single-bostad span {		
	 	background-image: url('data:image/svg+xml;utf8,<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 81 81" enable-background="new 0 0 81 81" xml:space="preserve"><rect id="XMLID_422_" x="3" y="3" fill="none" stroke="#22334B" stroke-width="6" stroke-miterlimit="10" width="75" height="75"/></svg>');
	}
	&.cluster-bostad span {		
	 	background-image: url('data:image/svg+xml;utf8,<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 99 99" enable-background="new 0 0 99 99" xml:space="preserve"><rect id="XMLID_23_" x="3" y="21" fill="none" stroke="#22334B" stroke-width="6" stroke-miterlimit="10" width="75" height="75"/><rect id="XMLID_22_" x="21" y="3" fill="none" stroke="#22334B" stroke-width="6" stroke-miterlimit="10" width="75" height="75"/></svg>');
		background-size: auto 78%;
	}
	&.single-omsorg span {		
		background-image: url('data:image/svg+xml;utf8,<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 90 90" enable-background="new 0 0 90 90" xml:space="preserve"><circle id="XMLID_19_" fill="none" stroke="#22334B" stroke-width="6" stroke-miterlimit="10" cx="45" cy="45" r="42"/></svg>');
	}
	&.cluster-omsorg span {		
		background-image: url('data:image/svg+xml;utf8,<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 113.4 113.9" enable-background="new 0 0 113.4 113.9" xml:space="preserve"><circle id="XMLID_424_" fill="none" stroke="#22334B" stroke-width="6" stroke-miterlimit="10" cx="45" cy="68.9" r="42"/><circle id="XMLID_423_" fill="none" stroke="#22334B" stroke-width="6" stroke-miterlimit="10" cx="68.4" cy="45" r="42"/></svg>');
		background-size: auto 80%;
	}
	&.single-utveckling span {
		background-image: url('data:image/svg+xml;utf8,<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 93.7 93.7" enable-background="new 0 0 93.7 93.7" xml:space="preserve"><polygon id="XMLID_475_" fill="none" stroke="#22334B" stroke-width="6" stroke-miterlimit="10" points="4.2,89.4 26.7,5.8 87.9,67"/></svg>');
	}
	&.cluster-utveckling span {
		background-image: url('data:image/svg+xml;utf8,<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 117.6 117.6" enable-background="new 0 0 117.6 117.6" xml:space="preserve"><polygon id="XMLID_28_" fill="none" stroke="#22334B" stroke-width="6" stroke-miterlimit="10" points="4.2,113.3 26.8,29.3 88.2,90.8 "/><polygon id="XMLID_35_" fill="none" stroke="#22334B" stroke-width="6" stroke-miterlimit="10" points="27.8,89.8 50.3,5.8 111.8,67.3 "/></svg>');
		background-size: auto 80%;
	}
	
	&.cluster-bostad-utveckling,
	&.cluster-utveckling-bostad {
		span {
			background-image: url('data:image/svg+xml;utf8,<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 130.3 130.3" enable-background="new 0 0 130.3 130.3" xml:space="preserve"><polygon id="XMLID_461_" fill="none" stroke="#22334B" stroke-width="6" stroke-miterlimit="10" points="40.5,89.8 63,5.8 124.5,67.3 "/><polygon id="XMLID_416_" fill="none" stroke="#22334B" stroke-width="6" stroke-miterlimit="10" points="3,127.3 3,89.8 3,52.3 40.5,52.3 78,52.3 78,89.8 78,127.3 40.5,127.3 "/></svg>');
			background-size: auto 94%;
		}
	}
	&.cluster-omsorg-utveckling,
	&.cluster-utveckling-omsorg {
		span {
			background-image: url('data:image/svg+xml;utf8,<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 134.8 134.8" enable-background="new 0 0 134.8 134.8" xml:space="preserve"><polygon id="XMLID_457_" fill="none" stroke="#22334B" stroke-width="6" stroke-miterlimit="10" points="45,89.8 67.5,5.8 129,67.3"/><circle id="XMLID_433_" fill="none" stroke="#22334B" stroke-width="6" stroke-miterlimit="10" cx="45" cy="89.8" r="42"/></svg>');
			background-size: auto 94%;
		}
	}
	&.cluster-omsorg-bostad,
	&.cluster-bostad-omsorg {
		span {
			background-image: url('data:image/svg+xml;utf8,<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 123 123" enable-background="new 0 0 123 123" xml:space="preserve"><rect id="XMLID_476_" x="45" y="3" fill="none" stroke="#22334B" stroke-width="6" stroke-miterlimit="10" width="75" height="75"/><circle id="XMLID_473_" fill="none" stroke="#22334B" stroke-width="6" stroke-miterlimit="10" cx="45" cy="78" r="42"/></svg>');
			background-size: auto 94%;
		}
	}
	&.cluster-bostad-omsorg-utveckling,
	&.cluster-bostad-utveckling-omsorg,
	&.cluster-omsorg-bostad-utveckling,
	&.cluster-omsorg-utveckling-bostad,
	&.cluster-utveckling-omsorg-bostad,
	&.cluster-utveckling-bostad-omsorg {
		span {
			background-image: url('data:image/svg+xml;utf8,<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 141.2 129" enable-background="new 0 0 141.2 129" xml:space="preserve"><polygon id="XMLID_325_" fill="none" stroke="#22334B" stroke-width="6" stroke-miterlimit="10" points="4.2,89.8 25.8,5.8 87.3,67.3 "/><rect id="XMLID_324_" x="63.2" y="23.8" fill="none" stroke="#22334B" stroke-width="6" stroke-miterlimit="10" width="75" height="75"/><circle id="XMLID_323_" fill="none" stroke="#22334B" stroke-width="6" stroke-miterlimit="10" cx="72.9" cy="84" r="42"/></svg>');
			background-size: 98% auto;
		}
	}
}


            
          
!
            
              
class PropertyMap {	
	constructor(el) {
		this.el = el;
		this.initMap_();
		this.initMapMarkers_();
		this.addEventListeners_();
	}
	
	addEventListeners_() {
		$(document).on(PropertyMap.EVENT_MAP_TOGGLE_LAYER, (e, id) => {
			this.toggleLayers_(id);
		});
	}
	
	removeEventListeners_() {
		$(document).off(PropertyMap.EVENT_MAP_TOGGLE_LAYER);
	}
	
	toggleLayers_(id) {
		this.clusterGroup.clearLayers();
		if (isFinite(id) && id < this.layers.length) {
			this.clusterGroup.addLayer(this.layers[id]);
		}
		else {
			//if (this.clusterGroup.hasLayer(this.layers[0]))
			this.clusterGroup.addLayer(this.layers[0]);
			this.clusterGroup.addLayer(this.layers[1]);
			this.clusterGroup.addLayer(this.layers[2]);
		}
		this.fitAllInViewport();
	}

	
	createLayer_(geoData) {
		return L.geoJson(geoData, {
			pointToLayer: (geojson, latlng) => {
				let className = 'single-bostad';
				if (geojson.properties.btype === 'omsorg')
					className = 'single-omsorg';
				if (geojson.properties.btype === 'utveckling')
					className = 'single-utveckling';
				return L.marker(latlng, {
					icon: Marker.icon(className)
			 });  
			}
		});
	}
	
	static getIconSize() {
		if (window.innerWidth >= 768)
			return 130;
		return 70;
	}
	
	_onPopupOpen(e) {
		const activeMarker = e.popup._source._icon;
		$(activeMarker).addClass(CLASS_MARKER_POPUP_OPEN);
		// find the pixel location on the map where the popup anchor is
		const px = this.map.project(e.popup._latlng);
		// find the height of the popup container, divide by 2, subtract from the Y axis of marker location
		px.y -= e.popup._container.clientHeight/2;
		// pan map: https://www.mapbox.com/mapbox.js/api/v2.2.1/l-map-class/#map-panoptions
		this.map.panTo(this.map.unproject(px), {
			animate: true,
			duration: .6,
			easeLinearity: 0.5
		});
	}
	
	initMap_() {
		// Provide your access token
		L.mapbox.accessToken = 'pk.eyJ1IjoiMTRpc2xhbmRzIiwiYSI6IjFmYWIwMDU4YjkwMDMyNTQyOWQ4ZDEyYzM0M2NjYTI4In0.6mbPptnajbHi2n0hn39jQA';

		// Create a map in the div #map
		this.map = L.mapbox.map(this.el, '14islands.9770525d', {
			scrollWheelZoom: false,
			zoomControl: true,
			attributionControl: false,
			maxZoom: 18,
			minZoom: 4,
			zoomAnimationThreshold: 10,
			//dragging: false
		});
	}
	
	initMapMarkers_() {
		// https://github.com/Leaflet/Leaflet.markercluster
		this.clusterGroup = new L.MarkerClusterGroup({
			iconCreateFunction: ClusterMarker.iconFromGeoData,
			showCoverageOnHover: false,
			spiderfyOnMaxZoom: true,
			maxClusterRadius: PropertyMap.getIconSize(),
			zoomToBoundsOnClick: false,
			animateAddingMarkers: false,
			spiderfyDistanceMultiplier: 4 // distance away from the center that spiderfied markers are placed. Use if you are using big icons - default: 1
		});
		this.clusterGroup.on('clusterclick', (e) => {
			let bounds = e.layer.getBounds().pad(0.5);
			this.map.fitBounds(bounds);  
		});
		this.clusterGroup.addTo(this.map);
		
		// create marker layers inside group so we can turn on/off
		this.layers = [
			this.createLayer_(SPG.markers),
			this.createLayer_(SPG.markers2),
			this.createLayer_(SPG.markers3)
		];
		
		// show layers
		this.toggleLayers_();
	}
	
	fitAllInViewport() {
		// let's add some padding on desktop
		const padding = window.innerWidth * 0.05;
		this.map.fitBounds(this.clusterGroup.getBounds(), {
			padding: [padding, padding]
		});
	}
	
	
	destroy() {
		this.removeEventListeners_();
		super.destroy();
	}
	
	static showAll() {
		$(document).trigger(PropertyMap.EVENT_MAP_TOGGLE_LAYER);
	}
	static showLayer(id) {
		$(document).trigger(PropertyMap.EVENT_MAP_TOGGLE_LAYER, id);
	}
}
PropertyMap.EVENT_MAP_TOGGLE_LAYER = 'event-property-map-toggle-layer';


class Marker {
	static icon(className) {
		const size = PropertyMap.getIconSize() * 0.6; //single marker size ratio
		return L.divIcon({
			className: 'component-property-map__marker ' + className,
			iconSize: [size, size],
			iconAnchor: [size/2, size/2],
			popupAnchor: [0, -7],
			html: '<span></span>' // add icon in here so we can animate transform without interfering with mapbox
		});
	}
}

class ClusterMarker {
	constructor(cluster) {
		this.cluster = cluster;
		this.defaultClassName = 'component-property-map__marker';
		this.inspectData_();
	}
	inspectData_() {
		this.types = {};
		this.cluster.getAllChildMarkers().forEach( (marker) => {
			this.types[marker.feature.properties.btype] = true;
		});
		const typeClass = Object.keys(this.types).join('-');
		this.typeClassName = 'cluster-' + typeClass;
	}
	getIcon() {
		const size = PropertyMap.getIconSize();
		return L.divIcon({
			className: `${this.defaultClassName} ${this.typeClassName}`,
			iconSize: [size, size],
			iconAnchor: [size/2, size/2],
			popupAnchor: [0, 11],
			html: '<span></span>' // add icon in here so we can animate transform without interfering with mapbox
		});
	}
	static iconFromGeoData(cluster) {
		return new ClusterMarker(cluster).getIcon();
	}
}

// COMPONENT LOADER
const loader = new ComponentLoader({PropertyMap});
loader.scan();

            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console