我想访问变量中定义的当前位置。之后,我想在加载页面时自动将该位置的元素着色。问题是我不知道如何访问该定义的位置,并在加载时将颜色附加到html。 我已经尝试过了,但是当我加载页面时它没有任何颜色。也许我的代码错了,任何人都可以帮忙吗?
https://jsfiddle.net/ax47kvu5/1/
var gigi = "P15";//id of g
var posisi = "C";//id of polygon
var kondisi = "amf";
if(kondisi=="amf"){
var group = $('polygon').parentNode().attr(gigi);
group.attr(posisi).css({fill: "#333333"});
$('polygon').html('XX');
}
答案 0 :(得分:1)
https://jsfiddle.net/9n9jack8/ - 在您的示例中,您没有加载jQuery,这是第一个问题。 private class LoadMarker extends AsyncTask<String, Void, Bitmap> {
@Override
protected Bitmap doInBackground(String... params) {
// Get bitmap from server
Bitmap overlay;
try {
URL url = new URL(params[0]);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
overlay = BitmapFactory.decodeStream(input);
} catch (IOException e) {
e.printStackTrace();
return null;
}
return overlay;
}
protected void onPostExecute(Bitmap bitmap) {
LatLng pLatLng = new LatLng(currentLocation.getLatitude(), currentLocation.getLongitude());
// If received bitmap successfully, draw it on our drawable
if (bitmap != null) {
View custom_layout = ((LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.view_custom_marker, null);
ImageView iv_category_logo = (ImageView) custom_layout.findViewById(R.id.profile_image);
Bitmap pinbit = Bitmap.createScaledBitmap(bitmap, 40, 60, false);
iv_category_logo.setImageBitmap(pinbit);
BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(createDrawableFromView(mContext, custom_layout));
// Add the new marker to the map
googleMap.addMarker(new MarkerOptions()
.position(pLatLng)
.title("")
.snippet("")
.icon(bitmapDescriptor));
} else {
// Add the new marker to the map
googleMap.addMarker(new MarkerOptions()
.position(pLatLng)
.title("")
.icon(BitmapDescriptorFactory.fromResource(R.mipmap.ic_marker)));
}
}
/**
* Convert a view to bitmap
*
* @param context
* @param view
* @return
*/
private Bitmap createDrawableFromView(Context context, View view) {
DisplayMetrics displayMetrics = new DisplayMetrics();
((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
view.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT));
view.measure(displayMetrics.widthPixels, displayMetrics.heightPixels);
view.layout(0, 0, displayMetrics.widthPixels, displayMetrics.heightPixels);
view.buildDrawingCache();
Bitmap bitmap = Bitmap.createBitmap(view.getMeasuredWidth(), view.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
view.draw(canvas);
return bitmap;
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Init your map here
new LoadMarker().execute();
}