Skip to content

Commit

Permalink
v0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Gianluca committed Dec 4, 2019
1 parent a132521 commit 6597337
Show file tree
Hide file tree
Showing 4 changed files with 13,620 additions and 14 deletions.
13,452 changes: 13,451 additions & 1 deletion dist/js/field.js

Large diffs are not rendered by default.

146 changes: 144 additions & 2 deletions resources/js/components/DetailField.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,152 @@
<template>
<panel-item :field="field" />

<div class="flex border-b border-40">
<div class="w-1/4 py-4">
<slot>
<h4 class="font-normal text-80">
{{ field.name }}
</h4>
</slot>
</div>
<div class="w-3/4 py-4">
<div v-bind:id="field.mapId" style="width: 100%;" :style="'height: ' + field.height">
</div>
</div>
</div>
</template>

<script>
import * as GoogleMapLoader from 'google-maps'
import * as Wkt from 'wicket'
import * as WktGmap from 'wicket/wicket-gmap3' // not remove
export default {
props: ['resource', 'resourceName', 'resourceId', 'field'],
data: () => ({
google: undefined,
gmap: undefined,
features: [],
base64img: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABEAAAAZCAYAAADXPsWXAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyNpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuNi1jMTQwIDc5LjE2MDQ1MSwgMjAxNy8wNS8wNi0wMTowODoyMSAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29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SBc8glibTYT6Am4CtONnHb8hWRuaweKEYESnV6yaxagSvocBUl/UMWoBXW7P1S41+AAQBLg7MOrTBxVgAAAABJRU5ErkJggg=="
}),
mounted() {
GoogleMapLoader.KEY = this.field.apiKey;
GoogleMapLoader.LIBRARIES = ['drawing']; // 'geometry', 'places', 'encoding'
var that = this;
GoogleMapLoader.load(function (google) {
that.google = google;
that.gmap = new google.maps.Map(document.getElementById(that.field.mapId), {
center: new google.maps.LatLng(that.field.lat, that.field.lng),
defaults: {
icon: that.base64img,
editable: true,
strokeColor: that.field.drawStrokeColor,
fillColor: that.field.drawFillColor,
fillOpacity: that.field.drawFillOpacity
},
disableDefaultUI: true,
mapTypeControl: false,
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControlOptions: {
position: google.maps.ControlPosition.TOP_LEFT,
style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
},
panControl: false,
streetViewControl: false,
zoom: that.field.zoom,
zoomControl: true,
zoomControlOptions: {
position: google.maps.ControlPosition.LEFT_TOP,
style: google.maps.ZoomControlStyle.SMALL
}
});
google.maps.event.addListener(that.gmap, 'tilesloaded', function () {
if (!this.loaded) {
this.loaded = true;
that.mapIt();
}
});
that.gmap.drawingManager = new google.maps.drawing.DrawingManager({
drawingControlOptions: {
position: google.maps.ControlPosition.TOP_CENTER,
drawingModes: []
},
markerOptions: that.gmap.defaults,
polygonOptions: that.gmap.defaults,
polylineOptions: that.gmap.defaults,
rectangleOptions: that.gmap.defaults
});
that.gmap.drawingManager.setMap(that.gmap);
});
},
methods: {
setInitialValue() {
this.value = this.field.value || ''
},
/**
* Fill the given FormData object with the field's internal value.
*/
fill(formData) {
formData.append(this.field.attribute, this.value || '')
},
/**
* Update the field's internal value.
*/
handleChange(value) {
this.value = value
},
mapIt() {
this.value = this.field.value || ''
if (!this.value || this.value === "")
return;
var wkt = new Wkt.Wkt();
try { // Catch any malformed WKT strings
wkt.read(this.value);
} catch (e1) {
try {
wkt.read(this.value.replace('\n', '').replace('\r', '').replace('\t', ''));
} catch (e2) {
if (e2.name === 'WKTError') {
console.error("Invalid WKT");
return;
}
}
}
var obj = wkt.toObject(this.gmap.defaults);
if (Wkt.isArray(obj)) { // Distinguish multigeometries (Arrays) from objects
for (i in obj) {
if (obj.hasOwnProperty(i) && !Wkt.isArray(obj[i])) {
obj[i].setMap(this.gmap);
}
}
this.features = this.features.concat(obj);
} else {
obj.setMap(this.gmap); // Add it to the map
this.features.push(obj);
}
obj.setEditable(false);
// center to polygon
var bound = new this.google.maps.LatLngBounds();
for (const pos of obj.getPath().g) {
var position = new this.google.maps.LatLng(pos.lat(), pos.lng())
bound.extend(position)
}
this.gmap.fitBounds(bound);
return obj;
},
},
}
</script>
27 changes: 16 additions & 11 deletions resources/js/components/FormField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
google: undefined,
gmap: undefined,
features: [],
base64img: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABEAAAAZCAYAAADXPsWXAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyNpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuNi1jMTQwIDc5LjE2MDQ1MSwgMjAxNy8wNS8wNi0wMTowODoyMSAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNv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S41+AAQBLg7MOrTBxVgAAAABJRU5ErkJggg=="
}),
mounted() {
Expand All @@ -41,8 +42,7 @@
that.gmap = new google.maps.Map(document.getElementById(that.field.mapId), {
center: new google.maps.LatLng(that.field.lat, that.field.lng),
defaults: {
icon: 'red_dot.png',
shadow: 'dot_shadow.png',
icon: that.base64img,
editable: true,
strokeColor: that.field.drawStrokeColor,
fillColor: that.field.drawFillColor,
Expand Down Expand Up @@ -74,12 +74,7 @@
that.gmap.drawingManager = new google.maps.drawing.DrawingManager({
drawingControlOptions: {
position: google.maps.ControlPosition.TOP_CENTER,
drawingModes: [
// google.maps.drawing.OverlayType.MARKER,
// google.maps.drawing.OverlayType.POLYLINE,
google.maps.drawing.OverlayType.POLYGON
// google.maps.drawing.OverlayType.RECTANGLE
]
drawingModes: that.field.drawingModes
},
markerOptions: that.gmap.defaults,
polygonOptions: that.gmap.defaults,
Expand Down Expand Up @@ -162,16 +157,17 @@
var obj = wkt.toObject(this.gmap.defaults);
if (!Wkt.isArray(obj) && wkt.type !== 'point') {
var that = this;
this.google.maps.event.addListener(obj.getPath(), 'insert_at', function (n) {
this.updateWktString();
that.updateWktString();
});
// Existing vertex is removed (insertion is undone)
this.google.maps.event.addListener(obj.getPath(), 'remove_at', function (n) {
this.updateWktString();
that.updateWktString();
});
// Existing vertex is moved (set elsewhere)
this.google.maps.event.addListener(obj.getPath(), 'set_at', function (n) {
this.updateWktString();
that.updateWktString();
});
} else {
if (obj.setEditable) {
Expand Down Expand Up @@ -218,6 +214,15 @@
}
}
}
// center to polygon
var bound = new this.google.maps.LatLngBounds();
for (const pos of obj.getPath().g) {
var position = new this.google.maps.LatLng(pos.lat(), pos.lng())
bound.extend(position)
}
this.gmap.fitBounds(bound);
return obj;
},
clearMap() {
Expand Down
9 changes: 9 additions & 0 deletions src/NovaGmapsWkt.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,13 @@ public function style($drawStrokeColor = '#990000', $drawFillColor = '#EEFFCC',
'drawFillOpacity' => $drawFillOpacity
]);
}

// ['marker', 'circle', 'polygon', 'polyline', 'rectangle']
public function drawingModes($drawingModes)
{
return $this->withMeta([
'drawingModes' => $drawingModes
]);
}

}

0 comments on commit 6597337

Please sign in to comment.