node-red-contrib-snap4city-user
Version:
Nodes for Snap4city project, targeted to standard user (no developer)
169 lines (151 loc) • 5.95 kB
HTML
<!--/* NODE-RED-CONTRIB-SNAP4CITY-USER
Copyright (C) 2018 DISIT Lab http://www.disit.org - University of Florence
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */-->
<script type="text/javascript">
RED.nodes.registerType('address-poi-search-by-text-within-circle', {
category: 'S4CSearch',
color: '#E7E7AE',
defaults: {
name: {
value: ""
},
authentication: {
type: "snap4city-authentication",
required: false
},
latitude: {
value: 0.0,
required: false,
validate: RED.validators.number()
},
longitude: {
value: 0.0,
required: false,
validate: RED.validators.number()
},
search: {
value: "",
required: false
},
maxdists: {
value: 1,
required: false,
validate: RED.validators.number()
},
maxresults: {
value: 100,
required: false,
validate: RED.validators.number()
},
lang: {
value: "",
required: false
}
},
outputs: 2,
outputLabels: ["service uri array", "geojson result"],
inputs: 1,
icon: "white-globe.png",
label: function () {
return this.name || "address-poi-search-by-text-within-circle";
},
oneditprepare: function () {
$.ajax({
url: "s4c/js/leaflet.js",
async: false,
dataType: "script"
});
$.ajax({
url: "s4c/js/leaflet.draw.js",
async: false,
dataType: "script"
});
node = this;
map = L.map('node-input-map').setView([43.78, 11.23], 9);
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
window.node_input_map = map;
var mapLayers = {};
drawnItems = new L.FeatureGroup();
map.addLayer(drawnItems);
var editControl = new L.Control.Draw({
draw: false,
edit: {
featureGroup: drawnItems
}
});
map.addControl(editControl);
drawControl = new L.Control.Draw({
draw: {
position: 'topleft',
polyline: false,
marker: false,
circlemarker: false,
polygon: false,
rectangle: false
}
});
map.addControl(drawControl);
L.control.layers(mapLayers, {
'drawlayer': drawnItems
}, {
collapsed: true
}).addTo(map);
map.on(L.Draw.Event.CREATED, function (e) {
var fence = e.layer;
fence.nodeID = node.id;
if (drawnItems.hasLayer(fence) == false) {
drawnItems.addLayer(fence);
}
drawControl.remove();
circles = {};
drawnItems.eachLayer(function (layer) {
circles[layer.nodeID] = layer.toGeoJSON();
circles[layer.nodeID].properties.radius = Math.round(layer.getRadius()) /
1000;
});
$("#node-input-latitude").val(circles[node.id].geometry.coordinates[1]);
$("#node-input-longitude").val(circles[node.id].geometry.coordinates[0]);
$("#node-input-maxdists").val(circles[node.id].properties.radius);
});
map.on('draw:edited', function (e) {
var fences = e.layers;
fences.eachLayer(function (fence) {
fence.shape = "geofence";
if (drawnItems.hasLayer(fence) == false) {
drawnItems.addLayer(fence);
}
});
circles = {};
drawnItems.eachLayer(function (layer) {
circles[layer.nodeID] = layer.toGeoJSON();
circles[layer.nodeID].properties.radius = layer.getRadius();
});
$("#node-input-latitude").val(circles[node.id].geometry.coordinates[1]);
$("#node-input-longitude").val(circles[node.id].geometry.coordinates[0]);
$("#node-input-maxdists").val(circles[node.id].properties.radius);
});
map.on('draw:deleted', function (e) {
drawControl.addTo(map);
$("#node-input-latitude").val(0);
$("#node-input-longitude").val(0);
$("#node-input-maxdists").val(100);
});
},
oneditresize: function () {
if (window.node_input_map) {
window.node_input_map.invalidateSize(true);
}
}
});
</script>