我有一个项目,节点之间有节点,线和曲线。 点头是球体,曲线是SPlinecurve3。
鼠标悬停时,我可以更改线条,曲线或节点的颜色。 以下代码对于节点来说是完美的,但对于直线或曲线不起作用。
public class MainActivity extends FragmentActivity {
private GoogleMap googleMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SupportMapFragment fragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
googleMap = fragment.getMap();
// googleMap.setMyLocationEnabled(true);
new RetrieveTask().execute();
}
private class RetrieveTask extends AsyncTask<Void, Void, String> {
@Override
protected String doInBackground(Void... params) {
String strUrl = "http://192.168.43.229/location_marker_mysql/retrieve.php";
URL url = null;
StringBuffer sb = new StringBuffer();
try {
url = new URL(strUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.connect();
InputStream iStream = connection.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(iStream));
String line = "";
while ((line = reader.readLine()) != null) {
sb.append(line);
}
reader.close();
iStream.close();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return sb.toString();
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
new ParserTask().execute(result);
}
}
MarkerOptions markerOptions = new MarkerOptions();
String name;
LatLng latLng;
double lat;
double lng;
private class ParserTask extends AsyncTask<String, Void, List<HashMap<String, String>>> {
@Override
protected List<HashMap<String, String>> doInBackground(String... params) {
MarkerJSONParser markerParser = new MarkerJSONParser();
JSONObject json = null;
try {
json = new JSONObject(params[0]);
} catch (JSONException e) {
e.printStackTrace();
}
List<HashMap<String, String>> markersList = markerParser.parse(json);
return markersList;
}
@Override
protected void onPostExecute(List<HashMap<String, String>> result) {
for (int i = 0; i < result.size(); i++) {
HashMap<String, String> hmPlace = result.get(i);
lat = Double.parseDouble(hmPlace.get("lat"));
lng = Double.parseDouble(hmPlace.get("lng"));
name = hmPlace.get("name");
String locality = hmPlace.get("locality");
String city = hmPlace.get("city");
latLng = new LatLng(lat, lng);
markerOptions.position(latLng);
markerOptions.title(name);
markerOptions.snippet(locality + "," + city);
markerOptions.icon(BitmapDescriptorFactory.fromResource(R.drawable.school_marker));
googleMap.addMarker(markerOptions);
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(24.66372, 93.90627), 8.0f));
}
}
}
}
绘制线条的代码是
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:context=".MainActivity" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:orientation="horizontal">
<EditText
android:id="@+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="4"
android:hint="Search Here" />
<Button
android:id="@+id/search_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:onClick="onMapSearch"
android:text="Search" />
</LinearLayout>
</LinearLayout>
绘制曲线的代码是
function onMouseMove( e ) {
mouseVector.x = 2 * (e.clientX / containerWidth) - 1;
mouseVector.y = 1 - 2 * ( e.clientY / containerHeight );
var raycaster = projector.pickingRay( mouseVector.clone(), camera ),
intersects = raycaster.intersectObjects( scene.children );
if (intersects.length > 0) {
if (INTERSECTED != intersects[0].object) {
if (INTERSECTED){
material = INTERSECTED.material;
if(material.emissive){
material.emissive.setHex(INTERSECTED.currentHex);
}
else{
material.color.setHex(INTERSECTED.currentHex);
}
}
INTERSECTED = intersects[0].object;
material = INTERSECTED.material;
if(material.emissive){
INTERSECTED.currentHex = INTERSECTED.material.emissive.getHex();
material.emissive.setHex(0xff0000);
}
else{
INTERSECTED.currentHex = material.color.getHex();
material.color.setHex(0xff0000);
}
console.log(INTERSECTED.position);
}
} else {
if (INTERSECTED){
material = INTERSECTED.material;
if(material.emissive){
material.emissive.setHex(INTERSECTED.currentHex);
}
else
{
material.color.setHex(INTERSECTED.currentHex);
}
}
INTERSECTED = null;
}
}
绘制节点的代码是
function edge(x1,y1,z1,x2,y2,z2,vv){
var material = new THREE.LineBasicMaterial({
color: 0x00ff00 ,linewidth: 2
});
var geometry = new THREE.Geometry();
geometry.vertices.push(new THREE.Vector3(x1,y1,z1));
geometry.vertices.push(new THREE.Vector3(x2, y2, z2));
var line = new THREE.Line(geometry, material);
return (line);
}
我试过线条的基础材料,但它也不起作用。我相信材料的问题,我尝试了所有的可能性,但它仍然无法正常工作。请帮忙吗?