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

feat: add style & onEachFeature function for geojson in geolocation controller #21322

Merged
merged 1 commit into from Jun 20, 2023

Conversation

blaggacao
Copy link
Contributor

@blaggacao blaggacao commented Jun 11, 2023

This no-op function can be overriden / inherited in custom controllers
to craft richer map experiences

Motivation: https://discuss.frappe.io/t/vrp-vehicle-routing-problem-chatgpt-augmented/105143

@blaggacao blaggacao requested a review from a team as a code owner June 11, 2023 19:15
@blaggacao blaggacao requested review from phot0n and removed request for a team June 11, 2023 19:15
@blaggacao
Copy link
Contributor Author

works blissfully in tandem with #21419 :

	setup(frm) {
		df = frm.get_docfield("map");
		df["fieldtype"] = "GeolocationVRP";
		frm.layout.replace_field("map", df);
	},
	refresh(frm) {
		fld = frm.fields_dict["map"];
		fld.refresh(); // not sure why necessary, may be rather a bug in ControlGeolocation
	}

And a custom controller:

frappe.ui.form.ControlGeolocationVRP = class ControlGeolocationVRP extends (
	frappe.ui.form.ControlGeolocation
) {
	point_to_layer(geoJsonPoint, latlng) {
		// Custom rules for how geojson data is rendered on the map
		if (geoJsonPoint.properties.point_type == "circle") {
			return L.circle(latlng, { radius: geoJsonPoint.properties.radius });
		} else if (geoJsonPoint.properties.point_type == "circlemarker") {
			return L.circleMarker(latlng, {
				radius: geoJsonPoint.properties.radius,
			});
		} else {
			// return L.marker(latlng);
			const homeIcon = L.divIcon({ className: "fa fa-home --blue" });
			return L.marker(latlng, { icon: homeIcon });
		}
	}
	setStyle(geoJsonFeature) {
		if (geoJsonFeature.geometry.type === "LineString") {
			return {
				color: geoJsonFeature.properties.stroke,
				weight: geoJsonFeature.properties["stroke-width"],
			};
		}
		return {};
	}
};

This no-op function can be overriden / inherited in custom controllers
to craft richer map experiences
@codecov
Copy link

codecov bot commented Jun 18, 2023

Codecov Report

Merging #21322 (c821554) into develop (ae0edd8) will increase coverage by 0.03%.
The diff coverage is 0.00%.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #21322      +/-   ##
===========================================
+ Coverage    63.88%   63.91%   +0.03%     
===========================================
  Files          765      765              
  Lines        69364    69368       +4     
  Branches      6274     6276       +2     
===========================================
+ Hits         44314    44339      +25     
- Misses       21444    21478      +34     
+ Partials      3606     3551      -55     
Flag Coverage Δ
server-ui 32.31% <ø> (+0.02%) ⬆️
ui-tests 51.68% <0.00%> (+0.08%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

@phot0n
Copy link
Contributor

phot0n commented Jun 19, 2023

looks fine to me from a glance. ref: https://leafletjs.com/examples/geojson/

@phot0n phot0n merged commit 4da6796 into frappe:develop Jun 20, 2023
18 of 19 checks passed
@phot0n phot0n changed the title feat: add style function to geojson controller feat: add style & onEachFeature function for geojson in geolocation controller Jun 20, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 16, 2023
@blaggacao blaggacao deleted the feat-style-for-geojson branch December 16, 2023 15:57
@barredterra barredterra added the backport version-14-hotfix backport to version 14 label Feb 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
backport version-14-hotfix backport to version 14
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants